为应用选择默认启动器,但未在Android 7中显示

问题描述 投票:1回答:1

我有一个可以作为启动器运行的应用程序,在Android 4中运行良好,但是在Android 7和8中,没有出现选择启动器对话框

enter image description here

// 
// Decompiled by Procyon v0.5.36
// 

package com.r7developers.unityplugin;

import android.os.Build;
import android.annotation.TargetApi;
import android.os.Process;
import android.app.AppOpsManager;
import android.content.Intent;
import com.rvalerio.fgchecker.AppChecker;
import android.content.Context;

public class Plugin
{
    static Context mContext;
    static String mBundleIdentifier;
    static AppChecker mAppChecker;

    public static void init(final Context context, final String bundleIdentifier) {
        Plugin.mContext = context;
        Plugin.mBundleIdentifier = bundleIdentifier;
    }

    public static void start() {
        Plugin.mAppChecker = new AppChecker();
        Plugin.mAppChecker.other((AppChecker.Listener)new AppChecker.Listener() {
            public void onForeground(final String packageName) {
                if (packageName != null && !packageName.contains(Plugin.mBundleIdentifier)) {
                    final Intent startHomescreen = new Intent("android.intent.action.MAIN");
                    startHomescreen.addCategory("android.intent.category.HOME");
                    startHomescreen.setFlags(268435456);
                    Plugin.mContext.startActivity(startHomescreen);

                }
            }
        }).timeout(1000).start(Plugin.mContext);
    }

    public static void stop() {
        Plugin.mAppChecker.stop();
    }

    public static void requestUsageStatsPermission() {
        if (needsUsageStatsPermission() && !hasUsageStatsPermission()) {
            Plugin.mContext.startActivity(new Intent("android.settings.USAGE_ACCESS_SETTINGS"));
        }
    }

    @TargetApi(19)
    public static boolean hasUsageStatsPermission() {
        final AppOpsManager appOps = (AppOpsManager)Plugin.mContext.getSystemService("appops");
        final int mode = appOps.checkOpNoThrow("android:get_usage_stats", Process.myUid(), Plugin.mContext.getPackageName());
        final boolean granted = mode == 0;
        return granted;
    }

    public static boolean needsUsageStatsPermission() {
        return Build.VERSION.SDK_INT >= 21;
    }

    public static void openSettings() {
        final Intent intent = new Intent("android.settings.SETTINGS");
        intent.addFlags(268435456);
        Plugin.mContext.startActivity(intent);
    }
}

此代码从unity项目的jar插件中反编译

我有什么想念的吗?

android unity3d android-launcher
1个回答
0
投票

您的问题必须由清单中的某些缺少的行引起。Android的发展非常迅速,由于权限系统的更改,最初为旧版本制作的某些应用程序可能不再起作用。这也必须适用于Android Manifest。幸运的是,您可以在较旧的设备上运行它,但是处理较新的设备似乎有问题。

您是否尝试过重新编译较小版本的代码并在多个版本上进行测试?

仅查看一些示例启动器(但未使用Unity Engine即可完成,可以帮助您了解是否错过了某些东西。

这里是我在GitHub上找到的Android Launcher(第一个)的链接:KISS/app/src/main/AndroidManifest.xml

[尝试添加您缺少的行,尤其是意图过滤器,该过滤器可帮助Android知道应用程序在菜单(如启动器选择器)中显示时应注意的内容。

我不是专家,但是我知道使用Android会很痛苦。

© www.soinside.com 2019 - 2024. All rights reserved.