华为手机设置桌面图标角标提醒的实现
程序员文章站
2022-04-19 18:46:13
华为手机用户占有率已经很大,有必要为华为手机支持角标提醒。 首先,要参考官网文档。 实现 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(); } }
*打赏