Merge branch 'notifications' into 'master'
Added cancel action to notifications.  See merge request !267
This commit is contained in:
commit
27d1187216
@ -168,6 +168,8 @@ public class DownloaderService extends Service {
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(createAppDetailsIntent(this, 0, 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)
|
||||
.setContentText(urlString)
|
||||
.setProgress(100, 0, true);
|
||||
@ -211,6 +213,17 @@ public class DownloaderService extends Service {
|
||||
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
|
||||
public int onStartCommand(Intent intent, int flags, int 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.
|
||||
* This is useful for checking whether to re-register {@link android.content.BroadcastReceiver}s
|
||||
* in {@link android.app.Activity#onResume()}.
|
||||
*
|
||||
* @see DownloaderService#isQueued(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