我收到錯誤:如何從應用程序中刪除了手機收件箱中短信在Android
Permission Denial:writing`com.android.provider.telephony.smsprovider uri content://sms/472 from pid=11211, uid=10142 requires
android.permission.write_sms, or granturipermission()
請幫我解決這個問題,因爲我是新本。
我的代碼是:
public void deleteSMS()
{
Uri inboxUri = Uri.parse("content://sms/inbox");
int count = 0;
Cursor c = getContentResolver().query(inboxUri , null, null, null, null);
while (c.moveToNext()) {
try {
// Delete the SMS
String pid = c.getString(0); // Get id;
String uri = "content://sms/" + pid;
count =getContentResolver().delete(Uri.parse(uri),
null, null);
Toast.makeText(getApplicationContext(),"message deleted successfully..!"+count, 5000).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.toString(), 5000).show();
}
}}
Added Permission in manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE"/>
<receiver android:name=".receiver.SMSReceiver" android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
我添加的所有權限,但我仍然沒有得到顯示答案,同樣的錯誤......
您在哪個API級別上運行代碼 – Akshay
對於API 6及更高版本,您需要用戶在外部存儲器讀/寫,發送/接收SMS,訪問攝像機等運行時的權限。按照鏈接(http://www.theappguruz.com/blog/runtime-permissions-in-android-marshmallow)將幫助你。 – Akshay
對於Android 4.4,只有默認的應用程序可以刪除短信,如果用戶使您的應用程序爲默認,它也可以刪除短信。請參閱鏈接(http://stackoverflow.com/questions/8614211/deleting-android-sms-programatically)以獲取更多詳細信息。 – Akshay