gpt4 book ai didi

java - 以编程方式删除所有电话通话记录

转载 作者:行者123 更新时间:2023-12-04 23:58:50 29 4
gpt4 key购买 nike

我正在尝试创建一种方法,通过单击即可删除所有通话记录。这是我的代码:

    private void deletePhoneCallLogs() {
Cursor cursor = getContext().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(CallLog.Calls._ID));
Uri deleteUri = ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, id);
getContext().getContentResolver().delete(deleteUri, null, null);
}
cursor.close();
}

我的权限 list :

<uses-permission android:name="android.permission.WRITE_CALL_LOG"></uses-permission>
<uses-permission android:name="android.permission.READ_CALL_LOG"></uses-permission>

我有一个我不明白的错误,就是这个:

    java.lang.UnsupportedOperationException: Cannot delete that URL: content://call_log/calls/922
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.delete(ContentProviderNative.java:553)
at android.content.ContentResolver.delete(ContentResolver.java:1956)
at com.example.testbackup.ui.dataset1.Dataset1Fragment.deletePhoneCallLogs(Dataset1Fragment.java:425)
at com.example.testbackup.ui.dataset1.Dataset1Fragment.access$800(Dataset1Fragment.java:55)
at com.example.testbackup.ui.dataset1.Dataset1Fragment$2.onClick(Dataset1Fragment.java:150)
at android.view.View.performClick(View.java:7870)
at android.widget.TextView.performClick(TextView.java:14970)
at android.view.View.performClickInternal(View.java:7839)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29363)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7948)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

有没有人有解决办法?

最佳答案

好吧,我终于找到了删除所有电话的方法,这篇文章对我有帮助:Delete all Missed Calls log entries显然,我被迫为调用指定一种类型,以便将其删除

我的代码:

    private void deletePhoneCallLogs() {
Cursor cursor = getContext().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(CallLog.Calls._ID));
Uri deleteUri = ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, id);
Log.d("PhoneCall","My delete PhoneCall"+deleteUri);
getContext().getContentResolver().delete(CallLog.Calls.CONTENT_URI , "type="+CallLog.Calls.TYPE , null); }
cursor.close();
}

我在许多设备以及 Android 8 和 10 上进行了测试。

关于java - 以编程方式删除所有电话通话记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69991213/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com