77import android .content .BroadcastReceiver ;
88import android .content .Context ;
99import android .content .Intent ;
10+ import android .graphics .Bitmap ;
1011import android .graphics .BitmapFactory ;
12+ import android .graphics .drawable .Drawable ;
1113import android .net .Uri ;
1214import android .os .Build ;
1315import android .os .Bundle ;
1719import android .support .v4 .content .FileProvider ;
1820import android .text .TextUtils ;
1921
22+ import com .taobao .luaview .util .DrawableUtil ;
23+
2024import org .json .JSONException ;
2125import org .json .JSONObject ;
2226
@@ -88,7 +92,7 @@ public void initData(Bundle bundle, String fileProviderAuthorities) {
8892 }
8993
9094
91- private void initNotification () {
95+ private void initNotification (String fileName ) {
9296 Context context = platform .getContentViewGroup ().getContext ();
9397 if (notificationManager == null ) {
9498 notificationManager = (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
@@ -104,7 +108,7 @@ private void initNotification() {
104108 .setSmallIcon (notificationIconRes )
105109 .setLargeIcon (BitmapFactory .decodeResource (context .getResources (), notificationIconRes ))
106110 .setAutoCancel (false )
107- .setContentTitle ("开始下载" )
111+ .setContentTitle ("开始下载 " + fileName )
108112 .setContentText ("准备下载" )
109113 .setProgress (100 , 0 , false );
110114 notification = builderO .build ();
@@ -136,7 +140,8 @@ public void execDownloadTask() {
136140 if (mDownloadTaskRunner == null ) {
137141 mDownloadTaskRunner = new DownloadTaskRunner (platform );
138142 }
139- final String filePath = VenvyFileUtil .getCachePath (platform .getContentViewGroup ().getContext ()) + LUA_CACHE_PATH + File .separator + Uri .parse (downloadAPI ).getLastPathSegment ();
143+ final String fileName = Uri .parse (downloadAPI ).getLastPathSegment ();
144+ final String filePath = VenvyFileUtil .getCachePath (platform .getContentViewGroup ().getContext ()) + LUA_CACHE_PATH + File .separator + fileName ;
140145 VenvyLog .d ("download to : " + filePath );
141146 DownloadTask downloadTask = new DownloadTask (platform .getContentViewGroup ().getContext (), downloadAPI , filePath , true );
142147 mDownloadTaskRunner .startTask (downloadTask , new TaskListener <DownloadTask , Boolean >() {
@@ -150,7 +155,7 @@ public void onTaskStart(DownloadTask downloadTask) {
150155 VenvyLog .d ("onTaskStart" );
151156 trackToVideoOS ("4" );
152157 uploadTrack (dsTrackLinks ); // 开始下载上报track
153- initNotification ();
158+ initNotification (fileName );
154159 }
155160
156161 @ Override
@@ -187,15 +192,20 @@ public void onTaskSuccess(DownloadTask downloadTask, Boolean aBoolean) {
187192 notifyIntent .putExtra ("filePath" , filePath );
188193 notifyIntent .putExtra ("fileProvider" , fileProviderAuthorities );
189194 PendingIntent pendingIntent = PendingIntent .getBroadcast (platform .getContentViewGroup ().getContext (), 0 , notifyIntent , PendingIntent .FLAG_UPDATE_CURRENT );
195+ Drawable icon = VenvyFileUtil .getApkIcon (platform .getContentViewGroup ().getContext (), filePath );
196+ Bitmap largeIcon = icon == null ? BitmapFactory .decodeResource (platform .getContentViewGroup ().getContext ().getResources (), notificationIconRes ) : DrawableUtil .drawableToBitmap (icon );
197+ String fileLabel = VenvyFileUtil .getApkLabel (platform .getContentViewGroup ().getContext (), filePath );
190198 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
191- notification = builderO .setContentTitle ("下载完成" )
199+ notification = builderO .setContentTitle ("下载完成 " + fileLabel )
192200 .setContentText ("点击安装" )
193201 .setAutoCancel (true )
202+ .setLargeIcon (largeIcon )
194203 .setContentIntent (pendingIntent ).build ();
195204 } else {
196- notification = builder .setContentTitle ("下载完成" )
205+ notification = builder .setContentTitle ("下载完成 " + fileLabel )
197206 .setContentText ("点击安装" )
198207 .setAutoCancel (true )
208+ .setLargeIcon (largeIcon )
199209 .setContentIntent (pendingIntent ).build ();
200210 }
201211
@@ -244,7 +254,7 @@ private void trackToVideoOS(String eventType) {
244254 }
245255 }
246256
247- private void registerAppReceiver (String filePath ) {
257+ private void registerAppReceiver (final String filePath ) {
248258 String filePackageName = VenvyFileUtil .getPackageNameByApkFile (platform .getContentViewGroup ().getContext (), filePath );
249259
250260 if (TextUtils .isEmpty (filePackageName )) return ;
@@ -259,6 +269,13 @@ public void onAppInstall(String packageName) {
259269 uploadTrack (instTrackLinks );
260270 trackToVideoOS ("7" );
261271 VenvyLog .d ("onAppInstall track: " + packageName );
272+
273+ // delete installed file
274+ File file = new File (filePath );
275+ if (file .exists ()) {
276+ file .delete ();
277+ }
278+
262279 }
263280
264281 @ Override
0 commit comments