简体   繁体   English

以编程方式从市场下载APK到SD卡

[英]Download apk from market to sdcard programmatically

I would like to download an .apk file on the market to the sd-card without any user interaction (I mean to do it in background, without launching a browser or the Market Application)? 我想 没有任何用户交互的情况下 将市场上的.apk文件下载到sd卡(我的意思是在后台运行,而无需启动浏览器或市场应用程序)?

Is there a special URL to use? 是否有特殊的URL使用?

Something like http://market.android.com/details?id=<your_package_name> always launch the Market Application, doesn't it? http://market.android.com/details?id=<your_package_name>类的东西总是启动市场应用程序,不是吗?

You can't do that. 你不能那样做。 You can, however, download an APK file from an outside source bu using the method suggested above. 但是,您可以使用上述建议的方法从外部来源bu下载APK文件。 This will notify the user via toast something like "Starting Download" and will not install the apk automatically. 这将通过吐司通知用户,例如“开始下载”,并且不会自动安装apk。

Have you tried HttpURLConnection ? 您尝试过HttpURLConnection吗?

    HttpURLConnection con = null;
    try
    {
        URL url = new URL(url_str);
        con = (HttpURLConnection)url.openConnection();
        InputStream input_stream = con.getInputStream();
        ...
    }
    catch (MalformedURLException e) { ErrorMSG("Bad URL"); }
    catch (IOException e) { ErrorMSG("Failed to download file from input stream"); }
    finally
    {
        if (con != null) con.disconnect();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM