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

Android N 插件 在获取PackageInfo.activies = null 7.0之前的版本都无此问题 #329

Open
VidicLee opened this issue Mar 24, 2017 · 3 comments

Comments

@VidicLee
Copy link

try {
PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
if(packageInfo.activities==null){
此处为空,找了很久始终没有解决方案
return null;
}
for (ActivityInfo ai : packageInfo.activities) {
if ((name+hideName).equals(ai.nonLocalizedLabel)) {
activityInfo = ai;
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}

@ghost
Copy link

ghost commented May 31, 2017

我是在PluginPackageParser里面的getPackageInfo方法里面在调用generatePackageInfo之前,加以下代码:
// Add for getPackageInfo return error result in Nougat @{
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
UserManager userManager = (UserManager) mHostContext.getSystemService(Context.USER_SERVICE);
boolean isUserUnlockingOrUnlocked = (boolean) MethodUtils.invokeMethod(userManager, "isUserUnlockingOrUnlocked", new Object[]{0});
if (isUserUnlockingOrUnlocked) {
flags |= PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
} else {
flags |= PackageManager.MATCH_DIRECT_BOOT_AWARE;
}

    }
    // @}

@ifeegoo
Copy link

ifeegoo commented Jun 30, 2017

@VidicLee 你提出的代码中

try {
PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
if(packageInfo.activities==null){
此处为空,找了很久始终没有解决方案
return null;
}

有一种情况,packageInfo.activities==null 是成立的,有少数系统级的应用(或者第三方应用)是可能会出现没有任何 Activity 的。可能你 Android 7.0 版本设备中有这种应用。

我遇到过在 Nexus 5X Android 7.1.1 版本下有一个系统级应用:
/system/priv-app/GoogleExtServices/GoogleExtServices.apk 看看配置文件:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android" xmlns:androidprv="http:https://schemas.android.com/apk/prv/res/android" coreApp="true" package="android.ext.services" platformBuildVersionCode="25" platformBuildVersionName="7.1.1">
    <application android:label="@string/app_name" defaultToDeviceProtectedStorage="true" directBootAware="true">
        <library android:name="android.ext.services"/>
        <service android:exported="true" android:label="@string/notification_ranker" android:name="android.ext.services.notification.Ranker" android:permission="android.permission.BIND_NOTIFICATION_RANKER_SERVICE">
            <intent-filter>
                <action android:name="android.service.notification.NotificationRankerService"/>
            </intent-filter>
        </service>
    </application>
</manifest>

里面是没有任何的 Activity 的,可以留意下这种情况。

@Bourneer
Copy link

Add flags of PackageManager.MATCH_DIRECT_BOOT_AWARE and PackageManager.MATCH_DIRECT_BOOT_UNAWARE while calling queryIntentActivities.
i.e.
before adding(for Android M or lower version):
final List launchers = pms.queryIntentActivities(launcherIntent,
null,
PackageManager.GET_INTENT_FILTERS,
userId).getList();

In Android N or later version:
final List launchers = pms.queryIntentActivities(launcherIntent,
null,
PackageManager.GET_INTENT_FILTERS
| PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,

userId).getList();

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