/**
  * Delete messages with a given {@link Uri}.
  *
  * @param context {@link Context}
  * @param uri {@link Uri}
  * @param title title of Dialog
  * @param message message of the Dialog
  * @param activity {@link Activity} to finish when deleting.
  */
 static void deleteMessages(
     final Context context,
     final Uri uri,
     final int title,
     final int message,
     final Activity activity) {
   Log.i(TAG, "deleteMessages(..," + uri + " ,..)");
   final Builder builder = new Builder(context);
   builder.setTitle(title);
   builder.setMessage(message);
   builder.setNegativeButton(android.R.string.no, null);
   builder.setPositiveButton(
       android.R.string.yes,
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(final DialogInterface dialog, final int which) {
           final int ret = context.getContentResolver().delete(uri, null, null);
           Log.d(TAG, "deleted: " + ret);
           if (activity != null && !activity.isFinishing()) {
             activity.finish();
           }
           if (ret > 0) {
             Conversation.flushCache();
             Message.flushCache();
             SmsReceiver.updateNewMessageNotification(context, null);
           }
         }
       });
   builder.show();
 }
Example #2
0
  /** {@inheritDoc} */
  @Override
  public void onCreate() {
    super.onCreate();
    Log.init("SMSdroid");
    Log.i(TAG, "init SMSdroid v" + this.getString(R.string.app_version));

    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
    int state = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (p.getBoolean(PreferencesActivity.PREFS_ACTIVATE_SENDER, true)) {
      try {
        Cursor c =
            this.getContentResolver()
                .query(SenderActivity.URI_SENT, PROJECTION, null, null, "_id LIMIT 1");
        if (c == null) {
          Log.i(TAG, "disable .Sender: curor=null");
        } else if (SmsManager.getDefault() == null) {
          Log.i(TAG, "disable .Sender: SmsManager=null");
        } else {
          state = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
          Log.d(TAG, "enable .Sender");
        }
        if (c != null && !c.isClosed()) {
          c.close();
        }
      } catch (IllegalArgumentException e) {
        Log.e(TAG, "disable .Sender: " + e.getMessage(), e);
      } catch (SQLiteException e) {
        Log.e(TAG, "disable .Sender: " + e.getMessage(), e);
      }
    } else {
      Log.i(TAG, "disable .Sender");
    }
    this.getPackageManager()
        .setComponentEnabledSetting(
            new ComponentName(this, SenderActivity.class), state, PackageManager.DONT_KILL_APP);
  }