TeslaUnread 未收到计数并将徽章放在应用程序图标上

TeslaUnread not receiving count and putting badge on app icon

我正在尝试在我的应用程序中添加对 TeslaUnread 的支持。使用 Nova Launcher 的付费版本时,它会在应用程序图标上放置一个数字徽章。文档在这里:http://novalauncher.com/teslaunread-api/。这是我用来向 TeslaUnread 发送计数更新的代码:

    try {
        RealmResults<BacklogItem> realmResults = App.getInstance().getRealm().where(BacklogItem.class).findAll();

        if (realmResults == null || realmResults.isValid()){
            ContentValues cv = new ContentValues();
            cv.put("tag", getComponentName().getPackageName() + "/" + getComponentName().getClassName());
            cv.put("count", realmResults.size());
            getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);
        }
    } catch (IllegalArgumentException ex) {
        /* Fine, TeslaUnread is not installed. */
    } catch (Exception ex) {
        /* Some other error, possibly because the format
        of the ContentValues are incorrect.
        Log but do not crash over this. */

        ex.printStackTrace();
    }

内容值已正确更新并安装了 TeslaUnread。我的应用程序是在 TeslaUnread 的 "Common" 部分下选择的。此代码包含在 MainActivity.

中的方法中

我无法让 API 在本机工作。我最终使用了 ShortcutBadger 处理应用程序图标徽章的库。