【问题标题】:Install apk without downloading无需下载即可安装apk
【发布时间】:2012-06-12 04:04:57
【问题描述】:

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

其中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 }

【问题讨论】:

  • 我也想安装 android 应用程序而不从我自己的服务器下载。你找到解决办法了吗?
  • 意图意图=新意图(意图.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(downloadPath + fileName)), "application/vnd.android.package-archive");

标签: android streaming client-server


【解决方案1】:

为此,您的 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);

【讨论】:

  • 谢谢。你忘了intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 但我不想下载文件。所以如果没有任何解决办法。我要先下载再安装。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 2017-01-31
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    相关资源
    最近更新 更多