diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-05-13 15:23:35 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2015-05-19 15:21:00 +0200 |
commit | 390e6aa8dc1b8f9689b90b8b7899bd7141871eb0 (patch) | |
tree | 67fc5591d57a6128330a6130246284d75cbb937f /src | |
parent | 8c3aab3c422ad263a1502889fbf477cc2965679b (diff) |
untested samsung unread badge supportUnreadCountBadge
Diffstat (limited to '')
-rw-r--r-- | src/main/AndroidManifest.xml | 2 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java | 50 |
2 files changed, 45 insertions, 7 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index abe427ba..eae7a264 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -15,6 +15,8 @@ <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.NFC" /> <uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT" /> + <uses-permission android:name="com.sec.android.provider.badge.permission.READ"/> + <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/> <application android:allowBackup="true" diff --git a/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java b/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java index 3e194c05..55f10bed 100644 --- a/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java @@ -1,8 +1,10 @@ package eu.siacs.conversations.utils; +import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.content.Intent; +import android.database.Cursor; import android.net.Uri; import android.util.Log; @@ -20,7 +22,8 @@ public class UnreadCountBadgeHelper { final String packageName = context.getPackageName(); final String activity = context.getPackageManager().getLaunchIntentForPackage(packageName).getComponent().getClassName(); updateTeslaUnreadApi(context, packageName, activity, count); - updateApexNotificationApi(context, packageName, activity, count); + //updateApexNotificationApi(context, packageName, activity, count); + updateSamsungApi(context, packageName, activity, count); } } @@ -34,12 +37,12 @@ public class UnreadCountBadgeHelper { final int count) { try { ContentValues contentValues = new ContentValues(); - contentValues.put("tag",packageName+"/"+activity); - contentValues.put("count",count); + contentValues.put("tag", packageName + "/" + activity); + contentValues.put("count", count); context.getContentResolver().insert( Uri.parse("content://com.teslacoilsw.notifier/unread_count"), contentValues - ); + ); } catch (IllegalArgumentException e) { return; } catch (Exception e) { @@ -55,10 +58,43 @@ public class UnreadCountBadgeHelper { final String activity, final int count) { Intent intent = new Intent("com.anddoes.launcher.COUNTER_CHANGED"); - intent.putExtra("package",packageName); + intent.putExtra("package", packageName); //intent.putExtra("class",packageName+"."+activity); - intent.putExtra("class",activity); - intent.putExtra("count",count); + intent.putExtra("class", activity); + intent.putExtra("count", count); context.sendBroadcast(intent); } + + private static void updateSamsungApi(final Context context, + final String packageName, + final String activity, + final int count) { + Uri mUri = Uri.parse("content://com.sec.badge/apps?notify=true"); + ContentResolver contentResolver = context.getContentResolver(); + Cursor cursor = null; + ContentValues contentValues = new ContentValues(); + contentValues.put("badgecount", count); + try { + cursor = contentResolver.query(mUri,new String[]{"_id","class"}, "package=?", new String[]{packageName}, null); + if (cursor != null) { + boolean entryActivityExist = false; + while (cursor.moveToNext()) { + int id = cursor.getInt(0); + contentResolver.update(mUri, contentValues, "_id=?", new String[]{String.valueOf(id)}); + if (activity.equals(cursor.getString(cursor.getColumnIndex("class")))) { + entryActivityExist = true; + } + } + if (!entryActivityExist) { + contentValues.put("package", packageName); + contentValues.put("class", activity); + contentResolver.insert(mUri, contentValues); + } + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + } } |