SMS'imi emülatörüm içinde silmeye çalışıyorum. Ancak burada tüm örnekleri denedikten sonra, hala çalışmıyor.Programsal olarak SMS silme işlemi çalışmıyor
Hatta bir hata bile alamıyorum. Etkinliğimde, gelen SMS'e tepki veren bir BroadcastReceiver
oluşturun. İşlem bittiğinde, SMS silinmelidir. Ancak hepsini silmeye çalışsam da herhangi bir mesajı silemiyorum. Ama içeriği okuyabiliyorum.
Belki birisinin bir fikri vardır? Bu gibi benim Manifest görünüyor
@Override
public void onResume() {
super.onResume();
//registerReceiver(mMessageReceiver, new IntentFilter(Constants.BROADCAST_SMS));
// IntentFilter customIntentFiler = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
//customIntentFiler.setPriority(1000);
registerReceiver(mMessageReceiver, new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));
// registerReceiver(mMessageReceiver, customIntentFiler);
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(mMessageReceiver);
}
//This is the handler that will manage to process the broadcast intent
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Extract data included in the Intent
Bundle bundle = intent.getExtras();
if (bundle != null) {
Log.d("[" + Constants.SERVICE_SMS + "] " + "SMS received");
Object[] pdus = (Object[])bundle.get("pdus");
SmsMessage sms = SmsMessage.createFromPdu((byte[])pdus[0]);
//check if SMS content
Log.d("[" + Constants.SERVICE_SMS + "] " + "SMS data:" + sms.getMessageBody().toString());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String[] smsParts = sms.getMessageBody().toString().split(";");
//ToDo filter logic
}
}
};
private void DeleteSMS(Context context, Intent intent){
try {
// mLogger.logInfo("Deleting SMS from inbox");
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(uriSms, new String[] { "_id", "thread_id", "address", "person",
"date", "body" }, null, null, null);
Log.d(Constants.TAG, "[" + Constants.SERVICE_SMS + "] " + "Deleting SMS" + uriSms);
//getContentResolver().delete(Uri.parse("content://sms/1"), null, null);
if (c != null && c.moveToFirst()) {
do {
long id = c.getLong(0);
long threadId = c.getLong(1);
String address = c.getString(2);
String body = c.getString(5);
Log.d(Constants.TAG, "[" + Constants.SERVICE_SMS + "] " + "Deleting SMS ID"+ id);
Log.d(Constants.TAG, "[" + Constants.SERVICE_SMS + "] " + "Deleting SMS threadID" + threadId);
Log.d(Constants.TAG, "[" + Constants.SERVICE_SMS + "] " + "Deleting SMS address" + address);
Log.d(Constants.TAG, "[" + Constants.SERVICE_SMS + "] " + "Deleting SMS body" + body);
getContentResolver().delete(Uri.parse("content://sms/inbox/" + id), null, null);
//getContentResolver().delete(Uri.parse("content://sms/inbox/" + threadId), null, null);
} while (c.moveToNext());
}
} catch (Exception e) {
// mLogger.logError("Could not delete SMS from inbox: " +
// e.getMessage());
Log.d(Constants.TAG, "[" + Constants.SERVICE_SMS + "] " + "Deleting SMS failed");
}
}
başlangıç:
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
Tamam, bunu deneyin, ama üçüncü argüman nedir. Sözdizimi denetimi, bir String'e gerek duymadığı için başarısız olur. Ama bir String dizisini geçmem gerekiyor mu? Daha fazla yardım almak için Thx – JanScott
tamam, sadece "id" dizgisine "id" kimliğine sahip olmanız yeterlidir. Böylece size yeni String [] {"" + id} dizesini [] {id} yerine –