[英]placing and running apk file inside android project
我正在構建一個依賴於另一個應用程序的android應用程序,實際上另一個應用程序是我要與該應用程序一起安裝的書寫板,我試圖將apk文件放在原始文件夾中並嘗試像這樣訪問它:
Uri app= Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.app);
可行嗎 如果是,如何安裝此應用程序?
將您的apk放置在資產文件夾中,並將myAPKFile.apk更改為您的apk文件名,然后使用此功能安裝您的apk。
所需權限:
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
private boolean InstallmyAPK(){
AssetManager assetManager = getAssets();
InputStream in = null;
OutputStream out = null;
File myAPKFile = new File(Environment.getExternalStorageDirectory().getPath()+"/myAPKFile.apk");
try {
if(!myAPKFile.exists()){
in = assetManager.open("myAPKFile.apk");
out = new FileOutputStream(myAPKFile);
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(myAPKFile),
"application/vnd.android.package-archive");
startActivity(intent);
return true;
} catch(Exception e) {return false;}
}
試試(我想這個問題已經在這里回答了: 在Android上以編程方式安裝Application )
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file:///path/to/your.apk"),
"application/vnd.android.package-archive");
startActivity(promptInstall);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.