Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于Android9.0下载完成后无法自动安装问题 #121

Open
wds1181977 opened this issue Apr 20, 2019 · 3 comments
Open

关于Android9.0下载完成后无法自动安装问题 #121

wds1181977 opened this issue Apr 20, 2019 · 3 comments

Comments

@wds1181977
Copy link

测试 三星 S8+ 华为nove3 Android 9.0机型无法 自动安装
原因是在installApp 走了异常,亲测可用 请 作者尽快修复问题
解决办法 AppUpdateUtils 增加 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

`
public static boolean installApp(Context context, File appFile) {
try {
Intent intent = getInstallAppIntent(context, appFile);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (context.getPackageManager().queryIntentActivities(intent, 0).size() > 0) {
context.startActivity(intent);

        }
        return true;
    } catch (Exception e) {
        ExceptionHandler exceptionHandler = ExceptionHandlerHelper.getInstance();
        if (exceptionHandler != null) {
            exceptionHandler.onException(e);
        }
    }
    return false;
}`
@yangwubo0800
Copy link

04-23 11:55:00.472 27013 27013 W System.err: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
04-23 11:55:00.472 27013 27013 W System.err: at android.app.ContextImpl.startActivity(ContextImpl.java:922)
04-23 11:55:00.472 27013 27013 W System.err: at android.app.ContextImpl.startActivity(ContextImpl.java:898)
04-23 11:55:00.472 27013 27013 W System.err: at android.content.ContextWrapper.startActivity(ContextWrapper.java:389)
04-23 11:55:00.472 27013 27013 W System.err: at com.vector.update_app.utils.AppUpdateUtils.installApp(AppUpdateUtils.java:74)
04-23 11:55:00.472 27013 27013 W System.err: at

我这边测试也发现这个问题,在红米安卓9.0的机器上也是不会自动安装,比较尴尬的是这部分代码即使加上去之后,也是在升级完成的Apk中生效,前一个版本的Apk无法自动安装,需要手动去找安装包,然后升级。

另外在调试过程中发现个问题,就是我这边APP的SDK版本还是25, 但是update-app模块的SDK指定的是26,在运行时DownloadService中通知适配这块,对于channel的使用需要增加版本判断处理:
mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID);
mBuilder = new NotificationCompat.Builder(this);

否则会报如下异常:
E AndroidRuntime: java.lang.NoSuchMethodError: No direct method (Landroid/content/Context;Ljava/lang/String;)V in class Landroid/support/v4/app/NotificationCompat$Builder; or its super classes (declaration of 'android.support.v4.app.NotificationCompat$Builder' appears in base.apk

@yangwubo0800
Copy link

补充说明一下,我这边出现问题的版本是3.3.1,使用最新代码编译出的aar文件来运行不会有这个问题,因为在安卓9.0上代码逻辑走的是:public static boolean installApp(Activity activity, File appFile)
而不是 public static boolean installApp(Context context, File appFile),即启动activity是从 Activity启动的,而不是从service,也就不会有 outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. 这个要求。

@jjfqqaazzx
Copy link

一楼正解,赞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants