android應用icon右上方未讀訊息數字提示

來源:互聯網
上載者:User

標籤:

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 belowcv.put("class", "com.example.badge.activity.Test");cv.put("badgecount", 1); // integer count you want to display// Execute insertgetContentResolver().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

android應用icon右上方未讀訊息數字提示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.