tags:

views:

140

answers:

2

This not work:

try {
    Context mmsContext = context.createPackageContext("com.android.mms", Context.CONTEXT_IGNORE_SECURITY);
    mmsContext.grantUriPermission(context.getPackageName(), 
    Uri.parse("file:///data/data/com.android.mms/shared_prefs/com.android.mms_preferences.xml"), 
    Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mmsContext);
    Editor editor = settings.edit();
    editor.putBoolean("pref_key_enable_notifications", false);
    editor.commit();
} catch (NameNotFoundException e1) {
    e1.printStackTrace();
}

Error: "Attempt to read preferences file /data/data/com.android.mms/shared_prefs/com.android.mms_preferences.xml without permission" Help, please!

A: 

You cannot disable SMS notifications programmatically. Please allow the user to decide whether or not SMS notifications should be enabled and allow them to control it through the appropriate settings screen.

CommonsWare
People at Ericsson say "The SMS Intent android.provider.Telephony.SMS_RECEIVED was an unordered broadcast until version 1.6, thus making it impossible for an application to stop the SMS from ending up in the inbox", but what about Android 1.6+ ?
Guido
A: 

Hi Mark,

By "you cannot", do you mean you should not, or there is no clean way of doing it/there's no API for that? Or do you really mean there is no way?

In most cases, I fully agree with you that the user should be able to control it through the appropriate settings screen. However, unfortunately, there are cases where there is no settings screen to toggle message notifications. An example I know of is the Samsung Behold II (which replaces the default messaging app, and removes the option to set/unset message notifications). I'm trying to develop a way around this, as there have been several requests by Behold II owners who've installed alternative MMS/SMS apps, and do not want the double notification. I've tried to access the preference activity directly using the following code, but it forced closed

    final Intent messagesettings = new Intent();
    messagesettings.setClassName("com.android.mms", "com.android.mms.ui.MessagingPreferenceActivity");
    ...
        public void onClick(View view){
            startActivity(messagesettings);
        }

Any ideas?

fjmustak