Added cancel action to notifications.
这个提交包含在:
		
							父节点
							
								
									7a880fdc33
								
							
						
					
					
						当前提交
						d0ca382d80
					
				| @ -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); | ||||
| @ -182,7 +184,7 @@ public class DownloaderService extends Service { | ||||
|         String title; | ||||
|         if (packageName != null) { | ||||
|             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); | ||||
|         } else { | ||||
|             title = getString(R.string.downloading); | ||||
| @ -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) | ||||
|      */ | ||||
|  | ||||
| @ -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> | ||||
		正在加载...
	
	
			
			x
			
			
		
	
		在新工单中引用
	
	屏蔽一个用户
	 Paresh Chouhan
						Paresh Chouhan