簡體   English   中英

Android 主屏幕應用程序圖標與不需要的迷你圖標徽章

[英]Android Home Screen App Icon With Unwanted Mini-Icon Badge

在添加了使用我的應用程序的快捷方式圖標填充設備主屏幕的代碼后,該圖標顯示為別名圖標,我嘗試在主頁上安裝主圖標以及某種迷你版圖標我圖標右下角的徽章。 有誰知道如何防止顯示此徽章?

在此處輸入圖像描述

EyeSee 圖標是我的應用程序的圖標。 請注意,我上面的另一個應用程序的圖標有一個與主圖標不同的迷你徽章。 我很想知道如何創建這個備用徽章圖標,但我會非常感激只是暫時擺脫迷你別名圖標。

這是我在為主要活動運行 OnCreate 時創建快捷方式的代碼。

private void createOrUpdateShortcut()
{
    SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean isAppInstalled = appPreferences.getBoolean("isAppInstalled", false);

    if(!isAppInstalled) 
    {
        Context appContext = getApplicationContext();

        Intent homeScreenShortCut= new Intent(appContext, MainActivity.class);
        homeScreenShortCut.setAction(Intent.ACTION_MAIN);
        homeScreenShortCut.putExtra("duplicate", false);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) 
        {
            homeScreenShortCut.setPackage(appContext.getPackageName());
            homeScreenShortCut.setClass(appContext, MainActivity.class);
            homeScreenShortCut.setClassName(appContext.getPackageName(), String.valueOf(MainActivity.class));

            ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
            assert shortcutManager != null;
            if (shortcutManager.isRequestPinShortcutSupported()) 
            {
                ShortcutInfo pinShortcutInfo =
                        new ShortcutInfo.Builder(this, "browser-shortcut-")
                                .setShortLabel(appContext.getResources().getString(R.string.app_name))
                                .setLongLabel(appContext.getResources().getString(R.string.app_name))
                                .setIcon(Icon.createWithResource(this,R.drawable.ic_launcher))
                                .setIntent(homeScreenShortCut)
                                .build();

                shortcutManager.requestPinShortcut(pinShortcutInfo, null);
                System.out.println("added_to_homescreen");
            } else {
                System.out.println("failed_to_add");
            }
        } else {
            if(shortcutReinstall) 
            {
                Intent removeIntent = new Intent();
                removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, homeScreenShortCut);
                String prevAppName = appPreferences.getString("appName", getString(R.string.app_name));
                removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, prevAppName);
                removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
                getApplicationContext().sendBroadcast(removeIntent);
            }

            Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, homeScreenShortCut);
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
            addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            getApplicationContext().sendBroadcast(addIntent);
        }

        //Make preference true
        SharedPreferences.Editor editor = appPreferences.edit();
        editor.putBoolean("isAppInstalled", true);
        editor.putString("phoneLanguage", currentLanguage);
        editor.putString("appName", getString(R.string.app_name));
        editor.commit();
    }
}

有誰知道如何防止顯示此徽章?

一般來說,這不是一個選擇。 固定快捷方式的標准操作系統提供的呈現包括您所說的徽章,並且沒有選擇退出該徽章的方法。 據推測,這是為了幫助避免應用程序通過這些快捷方式偽裝成其他應用程序。

請注意,我上面的另一個應用程序的圖標有一個與主圖標不同的迷你徽章

我假設您指的是“Patio Motion ...”。 較大的圖標是快捷方式的圖標。 右下角較小的圖標(“徽章”)是應用程序的圖標(即顯示在設置和其他地方的圖標)。

在您的情況下,您似乎已將快捷方式圖標設置為與啟動器圖標相同,這就是您具有這種重復效果的原因。 為快捷方式使用不同的圖標,最好是代表該快捷方式正在執行的操作的圖標。

就目前而言,您的快捷方式似乎只是啟動您的應用程序,這不是快捷方式的用途。 大多數用戶可以在他們的主屏幕上放置一個啟動器圖標,而無需您的應用發布快捷方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM