2012-06-08 174 views
0

我可以在没有下载的情况下安装apk文件吗? 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); 
} 

哪里urihttp://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 } 

如果你有一些想法,你可以与我分享。谢谢。

+1

看到这个http://stackoverflow.com/questions/5952516/install-apk-from-网址 – vnshetty

+0

我也想安装android应用程序,而无需从我自己的服务器下载。你找到解决方案吗? – Manoj

+0

Intent intent = new Intent(Intent.ACTION_VIEW); \t \t \t \t intent.setDataAndType(Uri.fromFile(new File(downloadPath + fileName)),“application/vnd.android.package-archive”); – Johan

回答

5

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); 
+0

完美!谢谢! – TharakaNirmana

2

对于这个您的Android应用程序必须上传到Android Market的。当您在android市场上上传它时,请使用以下代码通过您的android应用程序打开市场。

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=<packagename>")); 
startActivity(intent); 

如果你想要下载和从你自己的服务器上安装,然后使用下面的代码

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.example.com/sample/test.apk")); 
    startActivity(intent); 
+2

谢谢。你忘了'intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);'但我不想下载文件。所以如果没有任何解决方案。我将在安装之前先下载它。 – Nolesh