Android 无需下载即可安装apk
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10943037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install apk without downloading
提问by Nolesh
Can I install apk
file without downloading? The apk
file is on the server. I tried the code below but it doesn't work:
我可以apk
不下载就安装文件吗?该apk
文件在服务器上。我尝试了下面的代码,但它不起作用:
public static void InstallProgram(Uri uri, Context context){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri,"application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
Where uri
is http://192.168.43.1:6789/mobile_base/test.apk
.
It returns an error:
哪里uri
是http://192.168.43.1:6789/mobile_base/test.apk
。它返回一个错误:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://192.168.43.1:6789/mobile_base/test.apk typ=application/vnd.android.package-archive flg=0x10000000 }
回答by Amit kumar
you can use this code .may be solve the problem
您可以使用此代码。可能会解决问题
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://192.168.43.1:6789/mobile_base/test.apk"));
startActivity(intent);
回答by Amit Thaper
For this your android application must have uploaded into the android market. when you upload it on the android market then use the following code to open the market with your android application.
为此,您的 android 应用程序必须已上传到 android 市场。当您将其上传到 android 市场时,请使用以下代码通过您的 android 应用程序打开市场。
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=<packagename>"));
startActivity(intent);
If you want it to download and install from your own server then use the following code
如果您希望它从您自己的服务器下载并安装,请使用以下代码
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.example.com/sample/test.apk"));
startActivity(intent);