如何与Samsung手机上的BadgeProvider交互以将计数添加到应用程序图标? [英] How to interface with the BadgeProvider on Samsung phones to add a count to the app icon?

查看:259
本文介绍了如何与Samsung手机上的BadgeProvider交互以将计数添加到应用程序图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是完全没有记载的!在任何地方都没有提到它,只有少数应用程序正在使用它(例如Facebook,eBay).

您如何使用此功能为应用程序图标添加计数?

这是非常特定于三星设备的.我一般不是在问Android.我只是在询问对三星的Touchwhiz接口进行认证的方法,该界面目前允许认证. Android没有.

解决方案

首先,您需要为AndroidManifest.xml文件添加以下权限.

<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许可,因此可以随意使用它.

您可以从这里获取它: https://github.com/shafty023/SamsungBadger

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

This is completely undocumented! There is no mention of it anywhere, and only a handful of apps are using it (e.g. Facebook, eBay).

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

This is very specific to Samsung devices. I am not asking about Android in general. I'm only asking about badging Samsung's Touchwhiz interface which currently allows badging. Android does not.

解决方案

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" />

The column structure is as follows:

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

In order to query ALL results from the BadgeProvider do the following:

// 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();
}

In order to add a badge count to your application icon

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

If you want to clear the badge count on your icon

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

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.

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

这篇关于如何与Samsung手机上的BadgeProvider交互以将计数添加到应用程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆