0

I'm trying to add support for TeslaUnread in my application. It puts a numerical badge on an app icon when using the paid version of Nova Launcher. The documentation is here: http://novalauncher.com/teslaunread-api/. Here is the code I use to send count updates to 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();
    }

The content values are correctly updated and TeslaUnread is installed. My app is selected under the "Common" section of TeslaUnread. This code is contained within a method in MainActivity.

Jake Moritz
  • 843
  • 2
  • 9
  • 21

1 Answers1

0

I could not get the API working natively. I ended up using the ShortcutBadger library to handle app icon badges.

Jake Moritz
  • 843
  • 2
  • 9
  • 21