太难了
This commit is contained in:
parent
0e2c4a39cb
commit
477f9e1b3b
@ -24,10 +24,10 @@ public class DownLoadBroadcastReceiver extends BroadcastReceiver {
|
||||
DownloadManager.Query queryById = new DownloadManager.Query();
|
||||
queryById.setFilterById(currentDownloadId);
|
||||
Cursor cursor = downloadManager.query(queryById);
|
||||
String filePath = null;
|
||||
String fileUri = null;
|
||||
if(cursor.moveToFirst()){
|
||||
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{
|
||||
downloadManager.remove(currentDownloadId);
|
||||
cursor.close();
|
||||
@ -35,16 +35,16 @@ public class DownLoadBroadcastReceiver extends BroadcastReceiver {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
if(filePath == null) return;
|
||||
File file = new File(filePath);
|
||||
if(fileUri == null) return;
|
||||
Uri fileUri1 = Uri.parse(fileUri);
|
||||
File file = new File(fileUri1.getPath());
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
Uri apkUri = FileProvider.getUriForFile(context, context.getPackageName().concat(".fileprovider"), file);
|
||||
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
install.setDataAndType(apkUri, "application/vnd.android.package-archive");
|
||||
} 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);
|
||||
context.startActivity(install);
|
||||
}
|
||||
|
@ -4,11 +4,5 @@
|
||||
<external-path
|
||||
name="external"
|
||||
path="." />
|
||||
<external-files-path
|
||||
name="external_files"
|
||||
path="." />
|
||||
<files-path
|
||||
name="files"
|
||||
path="." />
|
||||
</paths>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user