Can't remove SMS logs from call log on Samsung devices

谁都会走 提交于 2019-12-12 15:41:26

问题


I'm trying to remove all SMS messages from the device via my app, but for some reason SMS logs still appear on the call log on some of the Samsung devices.

I've tried a more "radical" approach, and deleted the following URI's using the ContentResolver:

  • content://call_log/calls
  • content://sms
  • content://sms/inbox
  • content://sms/sent
  • content://mms/inbox
  • content://mms
  • content://mms-sms
  • content://mms/address
  • content://mms/part
  • content://mms/sent
  • content://mms/outbox

Delete was done with the following simple code:

ContentResolver cr = mContext.getContentResolver() ;
cr.delete(uri, null, null) ;

The result was that all text messages are deleted from the device, call log is clear from calls, BUT still contains SMS logs (for SMS messages that does not exist).

All the tables which are mentioned above are indeed empty at the end of the process, but I can't find the relevant source which the call log fetches it's SMS data from.

I've found the following posts on the subject, but still with no working solution:

  • SMS are duplicated as Calls(Samsung galaxy S II)
  • Samsung device returns text messages when querying for call-log

I'll state in advance that I know about the "logtype" column at CallLog.Calls.CONTENT_URI.. Not relevant due to the fact that this table is now empty, and data is not coming from there.


回答1:


The result was that all text messages are deleted from the device, call log is clear from calls, BUT still contains SMS logs (for SMS messages that does not exist).

what exactly your indication for "still contains SMS logs"? what contains SMS logs?
I'll assume you refer to Samsung Phone calls app. if so - unfortunately, as @CommonsWare said, this phone calls app not necessarily displaying correct state of the database behind the relevant ContentProvider.

it might be that this app caching (persistent / not persistent) data, and not refreshes it when the "real data" (from content provider database) change.. who knows... maybe only if it process will restart, and it cache would clear - it would refresh itself...




回答2:


Found the answer -

In order to get access to Samsung call logs we need to add a couple of Permissions to the manifest:

<uses-permission android:name="com.sec.android.provider.logsprovider.permission.READ_LOGS" />
<uses-permission android:name="com.sec.android.provider.logsprovider.permission.WRITE_LOGS" />

Now, all we have to do is to use the content resolver to delete log types 400, 410, 700, 200, 300, 600 and 500 from content://logs/historys as follows:

    mContext = getActivity(); // Assuming that you are doing this from within a Fragment

    try
    {
        mContext.getContentResolver().delete(Uri.parse("content://logs/historys"), "logtype='400'", null);
        mContext.getContentResolver().delete(Uri.parse("content://logs/historys"), "logtype='410'", null);
        mContext.getContentResolver().delete(Uri.parse("content://logs/historys"), "logtype='700'", null);
        mContext.getContentResolver().delete(Uri.parse("content://logs/historys"), "logtype='200'", null);
        mContext.getContentResolver().delete(Uri.parse("content://logs/historys"), "logtype='300'", null);
        mContext.getContentResolver().delete(Uri.parse("content://logs/historys"), "logtype='600'", null);
        mContext.getContentResolver().delete(Uri.parse("content://logs/historys"), "logtype='500'", null);
    }
    catch(Exception exception)
    {
        exception.printStackTrace();
    }

Worked like a charm for me.




回答3:


Samsung uses a separate storage for Messages log. Nevertheless, they have created a special ContentProvider to access them. Source I have not found, but found URI: content://logs/historys.

Example of removing log for specified number:

try{
    context.getContentResolver().delete(Uri.parse("content://logs/historys"), CallLog.Calls.NUMBER + " like '%" + number + "'", null);
} catch (IllegalArgumentException e){
    //that mean this not samsung device
}


来源:https://stackoverflow.com/questions/15246478/cant-remove-sms-logs-from-call-log-on-samsung-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!