華為手機用戶占有率已經很大,有必要為華為手機支持角標提醒。 首先,要參考官網文檔。 實現 1. 申請許可權,這裡有點多,還包含了其他手機的。官方文檔的許可權是不夠的。 2. 官方代碼。需要註意包名和類名必須正確,否則無反應 自由打賞 ...
華為手機用戶占有率已經很大,有必要為華為手機支持角標提醒。
首先,要參考官網文檔。
實現
1. 申請許可權,這裡有點多,還包含了其他手機的。官方文檔的許可權是不夠的。
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE"/> <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/> <uses-permission android:name="com.android.launcher2.permission.READ_SETTINGS"/> <uses-permission android:name="com.android.launcher2.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS"/> <uses-permission android:name="com.android.launcher3.permission.WRITE_SETTINGS"/> <uses-permission android:name="org.adw.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="org.adw.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="com.htc.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.qihoo360.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="com.qihoo360.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.lge.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="com.lge.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="net.qihoo.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="net.qihoo.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="org.adwfreak.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="org.adwfreak.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="org.adw.launcher_donut.permission.READ_SETTINGS"/> <uses-permission android:name="org.adw.launcher_donut.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.huawei.launcher3.permission.READ_SETTINGS"/> <uses-permission android:name="com.huawei.launcher3.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.fede.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="com.fede.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.sec.android.app.twlauncher.settings.READ_SETTINGS"/> <uses-permission android:name="com.sec.android.app.twlauncher.settings.WRITE_SETTINGS"/> <uses-permission android:name="com.anddoes.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="com.anddoes.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.tencent.qqlauncher.permission.READ_SETTINGS"/> <uses-permission android:name="com.tencent.qqlauncher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.huawei.launcher2.permission.READ_SETTINGS"/> <uses-permission android:name="com.huawei.launcher2.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.android.mylauncher.permission.READ_SETTINGS"/> <uses-permission android:name="com.android.mylauncher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.ebproductions.android.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="com.ebproductions.android.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.lenovo.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="com.lenovo.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS"/> <uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS"/> <uses-permission android:name="telecom.mdesk.permission.READ_SETTINGS"/> <uses-permission android:name="telecom.mdesk.permission.WRITE_SETTINGS"/> <uses-permission android:name="dianxin.permission.ACCESS_LAUNCHER_DATA"/>
2. 官方代碼。需要註意包名和類名必須正確,否則無反應
public void SetBadge(int num){ try{ String pName= getPackageName(); Toast.makeText(MainActivity.this, pName, Toast.LENGTH_LONG).show(); Bundle bunlde =new Bundle(); bunlde.putString("package", "com.test.badge.example"); // 包名 bunlde.putString("class", "com.test.badge.example.MainActivity"); //類名 bunlde.putInt("badgenumber",num); Bundle res= this.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher.settings/badge/"), "change_badge", null, bunlde); }catch(Exception e){ Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } }
自由打賞