ACTION_INSTALL_PACKAGE [英] ACTION_INSTALL_PACKAGE

查看:749
本文介绍了ACTION_INSTALL_PACKAGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用正在尝试安装APK.

My app is trying to install an APK.

Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
installIntent.setData(Uri.fromFile(new File(pathToApk)));
installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
((Activity)context).startActivityForResult(installIntent, Constants.APP_INSTALL_REQUEST);

在我的活动中

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
        case Constants.APP_INSTALL_REQUEST:
            if(resultCode == RESULT_OK){
                Log.e(TAG, "Package Installation Success");
            }else if(resultCode == RESULT_FIRST_USER){
                Log.e(TAG, "Package Installation Cancelled by USER");
            }else{
                Log.e(TAG, "Something went wrong - INSTALLATION FAILED");
            }

当启动startActivityResult时,我的活动立即获得结果代码0,该结果代码与RESULT_CANCELLED对应,而系统安装UI仍在等待用户权限.

When my startActivityResult is fired my activity instantly gets the result code 0 which corresponds to RESULT_CANCELLED while the System Install UI is still waiting for the user permission.

我实际上要了解安装是否成功并基于该更新的UI进行活动.

My activity to actually get to know whether the installation was successful or not and based on that update its UI.

任何帮助将不胜感激.

推荐答案

找到了罪魁祸首.

* installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); *

尽管该系统使我的活动的现有实例恢复了活力,但它位于 新任务堆栈 中.因此,系统会在启动新任务之前取消activityForResult.

Though the system brings the existing instance of my activity back to life it is in the new TASK stack. So the system cancels the activityForResult before it starts the new TASK.

谢谢

这篇关于ACTION_INSTALL_PACKAGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆