【问题标题】:Custom android app installation自定义安卓应用安装
【发布时间】:2011-10-23 15:38:23
【问题描述】:

在测试阶段,我需要能够在不通过 android 商店的情况下发送更新。我发现了一些关于此的帖子,但似乎没有一个对我有用。文件本身可以正常下载,但对于这两种选择,我都会收到以下错误:

08-09 16:31:20.411: 错误/AndroidRuntime(906): android.content.ActivityNotFoundException: 找不到处理 Intent { act=android.intent.action.VIEW dat=http://localhost:4567 的活动typ=application/vnd.android.package-archive }

有什么想法吗?

安卓

// first way
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://localhost:4567"));

// second way
// Intent intent = new Intent(Intent.ACTION_VIEW);
// intent.setDataAndType(Uri.parse("http://localhost:4567"), 
//                      "application/vnd.android.package-archive");
startActivity(intent); 

辛纳特拉

require 'sinatra'

get "/" do
  content_type "application/vnd.android.package-archive"
  attachment('agatha_v4.0.apk')
  file = File.open("agatha.apk", "rb")
  response.write(file.read)
end

【问题讨论】:

    标签: android


    【解决方案1】:
    Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(new File
                        (Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive");
                context.startActivity(intent); 
    

    【讨论】:

    • /download/app.apk 当然是你下载它时保存的地方
    • 同意。 Android 仅支持file:///content:// 方案安装APK。
    • 所以答案是您下载文件,然后安装它。当我这样做并尝试安装文件时,我收到一条错误消息“解析包时出现问题”,即使我已经通过在将下载的文件复制到设备后成功安装来检查下载的文件是否有问题.
    • IIRC 我遇到了类似的问题,最终发现是主机没有配置 application/vnd.android.package-archive。我对确切原因可能是错误的,但我记得那个错误并且我们已经解决了它。我发布的代码是安装下载的APK的实时代码
    【解决方案2】:

    这是在 Android 方面对我有用的方法。正如 Pyrodante 所提到的,您必须先下载该文件。我发现的另一个问题是文件必须设置为 MODE_WORLD_READBALE (MODE_PRIVATE) 对我来说失败了。

    final String APP_FILE_NAME = "agatha.apk";
    HttpClient http = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://10.10.100.113:4567");
    
    try {
        HttpResponse response = http.execute(request);
        InputStream fileStream = response.getEntity().getContent();
            FileOutputStream output = openFileOutput(APP_FILE_NAME, MODE_WORLD_READABLE);
    
        byte[] buffer = new byte[1024];
        int len = 0;
        while ((len = fileStream.read(buffer)) > 0) {
            output.write(buffer, 0, len);
        }
        fileStream.close();
        output.close();
    
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(getFileStreamPath(APP_FILE_NAME)), 
                           "application/vnd.android.package-archive");
        startActivity(intent); 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      相关资源
      最近更新 更多