安装apk而不下载

时间:2012-06-08 04:22:48

标签: android streaming client-server

我可以在不下载的情况下安装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 }

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

2 个答案:

答案 0 :(得分:5)

  

您可以使用此代码。可以解决问题

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://192.168.43.1:6789/mobile_base/test.apk"));
startActivity(intent);

答案 1 :(得分:2)

为此你的Android应用程序必须已上传到Android市场。当你在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);
相关问题