1. 程式人生 > >關於android手機桌面應用圖示的角標通知

關於android手機桌面應用圖示的角標通知

vivo桌面角標通知

網上有相關的程式碼實現方式,但是經過vivo官方文件沒有找到對應方法,於是找到客服給我的回覆是未開放此功能,具功能只對指定應用開放,下面是客服的回覆截圖

小米桌面角標通知:

文件裡面有實現該功能的原始碼。但是比較坑的是要將設計角標的應用的通知設為重要通知才能生效。

try {
    Field field = notification.getClass().getDeclaredField("extraNotification");
    Object extraNotification = field.get(notification);
    Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
    method.invoke(extraNotification, number);
} catch (Exception e) {
    e.printStackTrace();
}

魅族手機不支援桌面角標功能

華為手機桌面角標通知

華為很輕鬆能實現,沒有手動關閉通知許可權的情況下可以直接實現(在系統設定-》通知管理裡面有個圖示角標開關,可以進行關閉)

try {
    if (number < 0) {
        number = 0;
    }
    Bundle bundle = new Bundle();
    bundle.putString("package", context.getPackageName());
    String launchClassName = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()).getComponent().getClassName();
    bundle.putString("class", launchClassName);
    bundle.putInt("badgenumber", number);
    context.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher.settings/badge/"), "change_badge", null, bundle);
} catch (Exception e) {
    e.printStackTrace();
}

條件有限,其它手機的實測的同學們可以在評論裡面進行補充