forked from react-native-webview/react-native-webview
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue react-native-webview#3287: improve Download feature in Android
- Loading branch information
1 parent
39d4293
commit 32b82f4
Showing
5 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
android/src/main/java/com/reactnativecommunity/webview/utils/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.reactnativecommunity.webview.utils; | ||
|
||
import android.app.Notification; | ||
import android.app.NotificationChannel; | ||
import android.app.NotificationManager; | ||
import android.app.PendingIntent; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
|
||
import androidx.core.app.NotificationCompat; | ||
|
||
import com.reactnativecommunity.webview.R; | ||
|
||
public class Utils { | ||
|
||
public static String getBase64Data(String base64Data) { | ||
String[] parts = base64Data.split(","); | ||
if (parts.length > 1) { | ||
return parts[1]; | ||
} | ||
return base64Data; | ||
} | ||
|
||
public static String getMimeTypeFromBase64Data(String base64Data) { | ||
String[] parts = base64Data.split(";"); | ||
if (parts.length > 0) { | ||
String[] typePart = parts[0].split(":"); | ||
if (typePart.length > 1) { | ||
return typePart[1]; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static String getFileExtensionFromBase64Data(String base64Data) { | ||
String[] parts = base64Data.split(";"); | ||
if (parts.length > 0) { | ||
String[] extensionPart = parts[0].split("/"); | ||
if (extensionPart.length > 1) { | ||
return extensionPart[1]; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static void makeNotificationDownloadedBlobFile(Context context, Uri fileUri, String mimeType, String fileName) { | ||
Intent intent = new Intent(Intent.ACTION_VIEW); | ||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
if (mimeType != null) { | ||
intent.setDataAndType(fileUri, mimeType); | ||
} else { | ||
intent.setData(fileUri); | ||
} | ||
PendingIntent pendingIntent = PendingIntent.getActivity( | ||
context, 0, intent, | ||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); | ||
|
||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
String channel = "LunascapeChannel"; | ||
|
||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channel) | ||
.setAutoCancel(true) | ||
.setContentTitle("File downloaded") | ||
.setContentText(fileName) | ||
.setSmallIcon(R.drawable.ic_download_done_24) | ||
.setWhen(System.currentTimeMillis()) | ||
.setPriority(Notification.PRIORITY_DEFAULT) | ||
.setContentIntent(pendingIntent); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
NotificationChannel notificationChannel = new NotificationChannel(channel, channel, NotificationManager.IMPORTANCE_DEFAULT); | ||
notificationChannel.setDescription(channel); | ||
notificationChannel.enableLights(true); | ||
notificationChannel.enableVibration(true); | ||
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); | ||
notificationManager.createNotificationChannel(notificationChannel); | ||
notificationBuilder.setChannelId(channel); | ||
} | ||
|
||
notificationManager.notify(1, notificationBuilder.build()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M20.13,5.41l-1.41,-1.41l-9.19,9.19l-4.25,-4.24l-1.41,1.41l5.66,5.66z"/> | ||
<path android:fillColor="@android:color/white" android:pathData="M5,18h14v2h-14z"/> | ||
</vector> |