太难了

This commit is contained in:
Jerry Yan 2020-02-28 00:20:04 +08:00
parent 0e2c4a39cb
commit 477f9e1b3b
2 changed files with 6 additions and 12 deletions

View File

@ -24,10 +24,10 @@ public class DownLoadBroadcastReceiver extends BroadcastReceiver {
DownloadManager.Query queryById = new DownloadManager.Query(); DownloadManager.Query queryById = new DownloadManager.Query();
queryById.setFilterById(currentDownloadId); queryById.setFilterById(currentDownloadId);
Cursor cursor = downloadManager.query(queryById); Cursor cursor = downloadManager.query(queryById);
String filePath = null; String fileUri = null;
if(cursor.moveToFirst()){ if(cursor.moveToFirst()){
if(cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL){ if(cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL){
filePath = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); fileUri = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
}else{ }else{
downloadManager.remove(currentDownloadId); downloadManager.remove(currentDownloadId);
cursor.close(); cursor.close();
@ -35,16 +35,16 @@ public class DownLoadBroadcastReceiver extends BroadcastReceiver {
} }
cursor.close(); cursor.close();
} }
if(filePath == null) return; if(fileUri == null) return;
File file = new File(filePath); Uri fileUri1 = Uri.parse(fileUri);
File file = new File(fileUri1.getPath());
if (Build.VERSION.SDK_INT >= 24) { if (Build.VERSION.SDK_INT >= 24) {
Uri apkUri = FileProvider.getUriForFile(context, context.getPackageName().concat(".fileprovider"), file); Uri apkUri = FileProvider.getUriForFile(context, context.getPackageName().concat(".fileprovider"), file);
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
install.setDataAndType(apkUri, "application/vnd.android.package-archive"); install.setDataAndType(apkUri, "application/vnd.android.package-archive");
} else { } else {
install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); install.setDataAndType(Uri.parse(fileUri), "application/vnd.android.package-archive");
} }
install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(install); context.startActivity(install);
} }

View File

@ -4,11 +4,5 @@
<external-path <external-path
name="external" name="external"
path="." /> path="." />
<external-files-path
name="external_files"
path="." />
<files-path
name="files"
path="." />
</paths> </paths>
</resources> </resources>