Added cancel action to notifications.
This commit is contained in:
parent
7a880fdc33
commit
d0ca382d80
@ -168,6 +168,8 @@ public class DownloaderService extends Service {
|
|||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setContentIntent(createAppDetailsIntent(this, 0, packageName))
|
.setContentIntent(createAppDetailsIntent(this, 0, packageName))
|
||||||
.setContentTitle(getNotificationTitle(packageName))
|
.setContentTitle(getNotificationTitle(packageName))
|
||||||
|
.addAction(R.drawable.ic_cancel_black_24dp, getString(R.string.cancel),
|
||||||
|
createCancelDownloadIntent(this, 0, urlString))
|
||||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||||
.setContentText(urlString)
|
.setContentText(urlString)
|
||||||
.setProgress(100, 0, true);
|
.setProgress(100, 0, true);
|
||||||
@ -182,7 +184,7 @@ public class DownloaderService extends Service {
|
|||||||
String title;
|
String title;
|
||||||
if (packageName != null) {
|
if (packageName != null) {
|
||||||
App app = AppProvider.Helper.findByPackageName(
|
App app = AppProvider.Helper.findByPackageName(
|
||||||
getContentResolver(), packageName, new String[] {AppProvider.DataColumns.NAME});
|
getContentResolver(), packageName, new String[]{AppProvider.DataColumns.NAME});
|
||||||
title = getString(R.string.downloading_apk, app.name);
|
title = getString(R.string.downloading_apk, app.name);
|
||||||
} else {
|
} else {
|
||||||
title = getString(R.string.downloading);
|
title = getString(R.string.downloading);
|
||||||
@ -211,6 +213,17 @@ public class DownloaderService extends Service {
|
|||||||
return stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_UPDATE_CURRENT);
|
return stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PendingIntent createCancelDownloadIntent(@NonNull Context context, int
|
||||||
|
requestCode, @NonNull String urlString) {
|
||||||
|
Intent cancelIntent = new Intent(context.getApplicationContext(), DownloaderService.class)
|
||||||
|
.setData(Uri.parse(urlString))
|
||||||
|
.setAction(ACTION_CANCEL);
|
||||||
|
return PendingIntent.getService(context.getApplicationContext(),
|
||||||
|
requestCode,
|
||||||
|
cancelIntent,
|
||||||
|
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
onStart(intent, startId);
|
onStart(intent, startId);
|
||||||
@ -361,6 +374,7 @@ public class DownloaderService extends Service {
|
|||||||
* Check if a URL is waiting in the queue for downloading or if actively being downloaded.
|
* Check if a URL is waiting in the queue for downloading or if actively being downloaded.
|
||||||
* This is useful for checking whether to re-register {@link android.content.BroadcastReceiver}s
|
* This is useful for checking whether to re-register {@link android.content.BroadcastReceiver}s
|
||||||
* in {@link android.app.Activity#onResume()}.
|
* in {@link android.app.Activity#onResume()}.
|
||||||
|
*
|
||||||
* @see DownloaderService#isQueued(String)
|
* @see DownloaderService#isQueued(String)
|
||||||
* @see DownloaderService#isActive(String)
|
* @see DownloaderService#isActive(String)
|
||||||
*/
|
*/
|
||||||
|
9
app/src/main/res/drawable/ic_cancel_black_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_cancel_black_24dp.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/>
|
||||||
|
</vector>
|
Loading…
x
Reference in New Issue
Block a user