1.此功能是指应用图标展示的数字,例如未读短信,邮件,类似iOS应用icon
原生Android系统并不支持此功能
定制的Samsung,sony支持此功能,有各自对应不同的实现方式,以三星为例
1.在AndroidManifest.xml中加上两个权限: <uses-permission android:name="com.sec.android.provider.badge.permission.READ" /> <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" /> 2.查看你的APP是否已经注册在BadgeProvider中: Uri uri = Uri.parse("content://com.sec.badge/apps"); Cursor c = getContentResolver().query(uri, null, null, null, null); if (c == null) { return; } try { if (!c.moveToFirst()) { return; } c.moveToPosition(-1); while (c.moveToNext()) { String pkg = c.getString(1); String clazz = c.getString(2); int badgeCount = c.getInt(3); Log.d("BadgeTest", "package: " + pkg + ", class: " + clazz + ", count: " + String.valueOf(cnt)); } } finally { c.close(); } 3.如果没有注册就注册上去: ContentValues cv = new ContentValues(); cv.put("package", getPackageName()); // Name of your activity declared in the manifest as android.intent.action.MAIN. // Must be fully qualified name as shown below cv.put("class", "com.example.badge.activity.Test"); cv.put("badgecount", 1); // integer count you want to display // Execute insert getContentResolver().insert(Uri.parse("content://com.sec.badge/apps"), cv); 4.如果已经注册了就用下面方法更新角标: ContentValues cv = new ContentValues(); cv.put("badgecount", 0); getContentResolver().update(Uri.parse("content://com.sec.badge/apps"), cv, "package=?", new String[] {getPackageName()}); 附:BadgeProvider https://github.com/shafty023/SamsungBadger
参考http://blog.csdn.net/qq549631030/article/details/38512207
2.对于应用view级别的数字提醒展示可以使用开源控件
https://github.com/jgilfelt/android-viewbadger
时间: 2024-10-28 03:35:29