三星手机怎么接口BadgeProvider以计数添加到应用程序的图标?三星手机、应用程序、图标、接口

由网友(忌医)分享简介:三星TWLauncher允许应用在应用程序图标创建徽章计数。 Samsung's TWLauncher allows apps to create badge counts on app icons. 这是完全没有证件任何地方,只有极少数的应用程序都采用这种(脸谱,eBay的命名一对夫妇)。 This is co...

三星TWLauncher允许应用在应用程序图标创建徽章计数。

Samsung's TWLauncher allows apps to create badge counts on app icons.

这是完全没有证件任何地方,只有极少数的应用程序都采用这种(脸谱,eBay的命名一对夫妇)。

This is completely undocumented ANYWHERE and only a handful of apps are using this (Facebook, eBay to name a couple).

你如何使用这个功能来计数添加到您的应用程序图标?

How do you use this functionality to add a count to your application icon?

推荐答案

首先,您需要在以下权限添加到您的Andr​​oidManifest.xml文件。

First you'll need to add the following permissions to your AndroidManifest.xml file.

<uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />

列结构如下:

(integer) _id, (text) package, (text) class, (integer) badgecount, (blob) icon, (???) extraData

为了查询所有结果从BadgeProvider请执行以下操作:

// This is the content uri for the BadgeProvider
Uri uri = Uri.parse("content://com.sec.badge/apps");

Cursor c = getContentResolver().query(uri, null, null, null, null);

// This indicates the provider doesn't exist and you probably aren't running
// on a Samsung phone running TWLauncher. This has to be outside of try/finally block
if (c == null) {
    return;
}

try {
    if (!c.moveToFirst()) {
        // No results. Nothing to query
        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();
}

为了添加徽章数到您的应用程序图标

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);

如果你想清除你的图标徽章计数

ContentValues cv = new ContentValues();
cv.put("badgecount", 0);
getContentResolver().update(Uri.parse("content://com.sec.badge/apps"), cv, "package=?", new String[] {getPackageName()});  

新 我创建了可以导入作为一个库,以协助这方面的一个开源项目。它的行货与Apache可以随意使用它,请你。

NEW I have created an open source project that you can import as a library to assist with this. It's licensed as Apache so feel free to use it as you please.

您可以从这里得到它: https://github.com/shafty023/SamsungBadger

You can get it from here: https://github.com/shafty023/SamsungBadger

阅读全文

相关推荐

最新文章