|
|
@@ -95,7 +95,7 @@ public class UpdateManager { |
|
|
|
break; |
|
|
|
//下载完成,进行安装 |
|
|
|
case DOWN_OVER: |
|
|
|
theClass.installApk(); |
|
|
|
theClass.installApkNew(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -301,14 +301,42 @@ public class UpdateManager { |
|
|
|
* @param url |
|
|
|
*/ |
|
|
|
private void installApk(){ |
|
|
|
File apkfile = new File(savePath+saveFileName); |
|
|
|
if (!apkfile.exists()) { |
|
|
|
return; |
|
|
|
try { |
|
|
|
File apkfile = new File(savePath + saveFileName); |
|
|
|
if (!apkfile.exists()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
Intent i = new Intent(Intent.ACTION_VIEW); |
|
|
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
//com.example.silentinstallation.fileprovider |
|
|
|
Uri uri = Uri.parse("file://" + apkfile.toString()); |
|
|
|
i.setDataAndType(uri, "application/vnd.android.package-archive"); |
|
|
|
mContext.startActivity(i); |
|
|
|
} catch(Exception e){ |
|
|
|
T.show(mContext,"错误信息,正在安装..."+e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void installApkNew(){ |
|
|
|
try { |
|
|
|
|
|
|
|
File apkfile = new File(savePath + saveFileName); |
|
|
|
Intent intent = new Intent(); |
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
intent.setAction(Intent.ACTION_VIEW); |
|
|
|
Uri uri = null; |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
|
|
|
//fileprovider为上述manifest中provider所配置相同 |
|
|
|
uri = FileProvider.getUriForFile(mContext, mContext.getPackageName() + ".fileprovider", apkfile); |
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
|
|
|
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
|
|
|
} else { |
|
|
|
uri = Uri.fromFile(apkfile); |
|
|
|
} |
|
|
|
intent.setDataAndType(uri, "application/vnd.android.package-archive"); |
|
|
|
mContext.startActivity(intent); |
|
|
|
} catch(Exception e){ |
|
|
|
T.show(mContext,"错误信息,正在安装..."+e.getMessage()); |
|
|
|
} |
|
|
|
Intent i = new Intent(Intent.ACTION_VIEW); |
|
|
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
Uri uri = Uri.parse("file://" + apkfile.toString()); |
|
|
|
i.setDataAndType(uri, "application/vnd.android.package-archive"); |
|
|
|
mContext.startActivity(i); |
|
|
|
} |
|
|
|
} |