Android - 为Android设置徽章(三星)

时间:2015-12-20 13:46:18

标签: java android java-native-interface

我有来自this link

的三星徽章通知的此功能
     private static final String CONTENT_URI_S = "content://com.sec.badge/apps?notify=true";
     private static final String[] CONTENT_PROJECTION_S = new String[]{"_id","class"};


    public static void setBadgeSamsung(Context context, int count) {

        Uri mUri = Uri.parse(CONTENT_URI_S);
        ContentResolver contentResolver = context.getContentResolver();
        Cursor cursor = null;
        try {
            Log.d ("badge" , "------2------------" );
            cursor = contentResolver.query(mUri, CONTENT_PROJECTION_S, "package=?", new String[]{context.getPackageName()}, null);
            Log.d ("badge" , "------2-1111-----------" );
            if (cursor != null) {
                String entryActivityName = getLauncherClassName(context);
                boolean entryActivityExist = false;
                while (cursor.moveToNext()) {
                    Log.d ("badge" , "------2-3-----------" );
                    int id = cursor.getInt(0);
                    Log.d ("badgeID" , Integer.toString(id) );
    //                    ContentValues contentValues = getContentValues(badgeCount, false);
                        ContentValues contentValues = new ContentValues();
                        contentValues.put("badgecount", count);
                        contentResolver.update(mUri, contentValues, "_id=?", new String[]{String.valueOf(id)});
                        if (entryActivityName.equals(cursor.getString(cursor.getColumnIndex("class")))) {
                            Log.d ("badge" , "------2-3-4----------" );
                            entryActivityExist = true;
                        }
                    }

                    if (!entryActivityExist) {
                        Log.d ("badge" , "------2-3-4-5---------" );
    //                    ContentValues contentValues = getContentValues(badgeCount, true);
                                            ContentValues contentValues = new ContentValues();
                                            contentValues.put("package", context.getPackageName());
                                            contentValues.put("class", getLauncherClassName(context));
                                            contentValues.put("badgecount", count);
                        contentResolver.insert(mUri, contentValues);
                    }
            }
        } finally {
            if (cursor != null && !cursor.isClosed()) {
                Log.d ("badge" , "------2-3-4-5-6--------" );
                cursor.close();
        }
      }
   }

实际上,我对此日志感到崩溃:

D/badge   (31741): ------2------------
F/art     (31741): art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: JNI NewStringUTF called with pending exception 'java.lang.SecurityException' thrown in unknown throw location
F/art     (31741): art/runtime/check_jni.cc:65]     in call to NewStringUTF

有什么建议可以解决吗?

已编辑:

我将此添加到 AndroidManifest.xml

<!--for android badge-->
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS"/>

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

</activity>

0 个答案:

没有答案