在下载新版本android

时间:2015-08-21 17:22:03

标签: android

我想以编程方式更新我的应用程序。在我运行我的应用程序之后,在下载期间"使用"完成操作出现对话框。我不知道是什么原因。我的代码如下:

private BroadcastReceiver downloadReceiver = new BroadcastReceiver() {

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public void onReceive(Context context, Intent intent) {

        // check if the broadcast message is for our Enqueued download
        long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
        if (downloadReference == referenceId) {

            try{
            Log.v(LOG_TAG, "Downloading of the new app version complete");
            // start the installation of the latest version
            Intent installIntent = new Intent(Intent.ACTION_VIEW);


             intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive");


            installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(installIntent);
            }
            catch(Exception ex)
            {
            String mess=    ex.getMessage();
            String a=mess;
            }

        }
    }
};

1 个答案:

答案 0 :(得分:0)

您似乎没有任何意图过滤器,请使用标记

添加它们

<intent-filter>