Ran*_*del 3 android android-intent android-install-apk
我试图从资源文件夹编程安装apk但不成功,请帮助我.我正在使用以下代码.谢谢.
Intent intent = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("file:///android_asset/youtuberanjit.apk"))
.setType("application/vnd.android.package-archive");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
sky*_*eek 14
AssetManager assetManager = getAssets();
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open("myapk.apk");
out = new FileOutputStream("/sdcard/myapk.apk");
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
in.close();
in = null;
out.flush();
out.close();
out = null;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("/sdcard/myapk.apk")),
"application/vnd.android.package-archive");
startActivity(intent);
} catch(Exception e) { }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11687 次 |
| 最近记录: |