Samsung sms in call log, how can I delete it? - android

With the new Android 2.2+ operating systems deployed on Samsung phones, the call log has been replaced with a special super log. The super log contains also the information about sent sms. How I can delete this type of log? Can I use a particular Uri (content://...) to delete it? I read that Samsung uses the LogsProvider.apk to manage logs, is there the open source code of it?
Thanks.
Denis.

You can try to delete the calls using this:
context.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI,
null, null);
I don't think **LogsProvider** app Samsung is open source.

Uri to be used for deleting Samsung log is "content://logs/historys".
Use this Uri to delete all the sms log of a particular number.
String smsLogUri = "content://logs/historys";
Context.getContentResolver().delete(Uri.parse(smsLogUri), " logtype = 300 and number like ?", new String[]{phoneNumber});
logtype= 300 is used to delete only sms log.
If you want to delete sms log of all numbers then use:
Context.getContentResolver().delete(Uri.parse(smsLogUri), " logtype = 300 ", null);

Related

How to Delete sent SMS with limit more than 500 android?

I followed this to Delete SMS..
So here I am using these
mContext.getContentResolver().delete(Uri.parse("content://sms/"), null, null);
I have a SMS sending app It sends more than 1k messages every hour
Now the problem is that In new/big phone its working fine, But when I installed same in a basic android phone with less internal memory / less SMS storage, I am facing NO_PDU error
So I want to delete it programmatically, but with LIMIT 500 sms or past 1 day sms or past 1 hr SMS.
mContext.getContentResolver().delete(Uri.parse("content://sms/"), null, null);
The above code will delete all the sms present in SmsProvider . To delete specific sms query SmsProvider and do your operation on selected rows.
Refer below example-
if (values.getAsInteger(Sms.TYPE) == Sms.MESSAGE_TYPE_DRAFT) {
SqliteDatabase.delete(TABLE_SMS, "thread_id=? AND type=?",
new String[] { values.getAsString(Sms.THREAD_ID),
Integer.toString(Sms.MESSAGE_TYPE_DRAFT) });
}

Delete calendar event on Android (Samsung S-Planner)

I am working with the native calendar, and I want to delete the events in native calendar. Provided that the event ID is known.
for (long eventID : eventIDList) {
// delete from native calendar
Uri deleteUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID);
int isDeleted = mContentResolver.delete(deleteUri, null, null);
Log.i("LOG", "Event deleted: " + String.valueOf(isDeleted));
}
I have checked with the log. It returns "1" which means 1 row is deleted.
It works well on normal Android Device, and the record is deleted.
But the problem appears in Samsung's Android device (S-Planner). After the delete cmd run, isDeleted returns 1. Sadly when I do a query through ContentResolver, the record supposed to be deleted still exists. (In S-Planner, the deleted won't be shown, but it is meaningless for me in this project)
Is there any workout to fix it?
** I have checked the delete cmd works fine on non-samsung devices, and isDelete returns 1 for all devices.
Thank you!!

Observing changes in Android content observer for Audio.Media.EXTERNAL_CONTENT_URI

I am developing an Android app in which I have to detect changes in Android SD card for audio files with the file name, file path and operation performed upon it. Example if I am adding a file in my SD card then I want to know
Name of the file which is added
Path of the file
Operation -- Add
Previously I Have tried file observer But for that I have to apply it on each and every directory. So I searched for some other solution and got the info about Audio.Media.EXTERNAL_CONTENT_URI. Then I created a content observer like this
UriObserver.java -- which is a content observer
class UriObserver extends ContentObserver {
public UriObserver(Handler handler) {
super(handler);
// TODO Auto-generated constructor stub
}
#Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
Log.d("INSTANT", "GETTING CHANGES");
}
}
This is the code for registration for it
UriObserver observer = new UriObserver(new Handler());
Log.d("INSTANT", "registered content observer");
this.getApplicationContext()
.getContentResolver()
.registerContentObserver(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, false,
observer);
Log.d("INSTANT", "registered content observer");
It let me know that some change has been occur in sdcard related to audio files. But it doesn't gives any sort of info about which file has been added, edited or deleted.
Then I searched for for solution and got this post
Android: How to detect a change in MediaStore when connected over MTP
In this post some code is given by Bhiefer as an answer which I think it could work, so I tried to implement that but I am not able to do so.
What can I do for this?
Update
Can I query Audio.Media.EXTERNAL_CONTENT_URI for its latest changes? This code:
mCursor = context.getContentResolver().query(
Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, "_id");
mCursor.moveToLast();
doesn't give the latest changes. Is there any other method to get the latest changes?
Let me try to unwind
ContentObserver
It doesn't give you information on what has changed
It's per design. Nothing in documentation says that it will give you this info.
FileObserver
It isn't recursive
Yes. It's know issue. What is the problem with iterating through all directories and setting observers? Per my understand by default there shouldn't be many (let say a dozen or so).
Android: How to detect a change in MediaStore when connected over MTP
The code which you found is just ContentObserver wrapped in UriObserver.
It does several things
He gets a cursor for one of content provides (in his case I believe it's images from MediaStore)
He registers an observer for this
As soon as some changes happens it forward this changes to external listener
However, this solution has two limitation:
It has inherit problem of ContentObserver that it doesn't report what happened to the data.
I believe it will report only changes to files which are registered in this MediaStore content provider. I believe system scans only special directories on SD card to check for images and so on. So, if a file will be places in some another directory, this solution won't see it.
So, What was your question about his code?
Summary
In the case, if you want to know exact type of changes for ALL files on scdard, I don't think that you can find anything better than FileObserver
Update 1
Couple more ideas, which may be not suitable for you. If you can root a device then you have the option to write filter driver for a filesystem, so your driver will be called each time when something has changed.
You can take a look at this link:
http://www.gossamer-threads.com/lists/linux/kernel/355190
Or you can reuse some existing linux changes notifications systems. As example, look at this:
http://stefan.buettcher.org/cs/fschange/. However, it could be that FileObserver is based exactly on it.
Anyway, both these approaches are low level and will require more time to figure out.
You can get the latest additions/modifications by querying on the DATE_ADDED and DATE_MODIFIED columns, but you will NOT get DELETIONS.
Here is how I do it:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
long lastDatabaseUpdateTime = preferences.getLong("lastDatabaseUpdateTime", 0);
long newDatabaseUpdateTime = (new Date()).getTime();
String[] cols = new String[] {MediaStore.Audio.Media._ID /* and other columns */};
String where = "("+MediaStore.MediaColumns.DATE_ADDED + ">" + (lastDatabaseUpdateTime/1000);
where += " or " + MediaStore.MediaColumns.DATE_MODIFIED + ">" + (lastDatabaseUpdateTime/1000);
where += ") and "+MediaStore.Audio.AudioColumns.IS_MUSIC+"==1 ";
Cursor cursor = MusicUtils.query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, cols, where, null, null);
/* Do my work on the cursor and close the cursor */
//If no exceptions, then save the new timestamp
SharedPreferences.Editor editor = preferences.edit();
editor.putLong("lastDatabaseUpdateTime", newDatabaseUpdateTime);
editor.commit();

"SQLiteException: no such column: mimetype" when using ContactsContract in Android

I want to delete an entry from Android's internal database table ContactsContract, i.e. an event such as a birthday should be removed from the contact's entry.
The following code works pretty well, but some users (ca. 1%) have this crashing with an SQLException. So is there anything wrong in my code or is it just that their device doesn't support Android's ContactsContract correctly?
try {
ArrayList<Long> rawContactIDs = getRawContactID(o.getID());
int rawContactCount = rawContactIDs.size();
for (int r = 0; r < rawContactCount; r++) {
long rawContactID = rawContactIDs.get(r);
String where = ContactsContract.Data.MIMETYPE+" = ? AND "+ContactsContract.Data.RAW_CONTACT_ID+" = ? AND "+ContactsContract.CommonDataKinds.Event.TYPE+" = ?";
String[] selection = new String[] { ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE, String.valueOf(MY_RAW_CONTACT_ID), String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY) };
getContentResolver().delete(ContactsContract.Data.CONTENT_URI, where, selection);
}
}
catch (Exception e) {}
The exception that is thrown is:
android.database.sqlite.SQLiteException: no such column: mimetype: , while
compiling: DELETE FROM data WHERE mimetype = ? AND raw_contact_id = ? AND
data2 = ?
at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158)
at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
at
android.content.ContentProviderProxy.delete(ContentProviderNative.java:472)
at android.content.ContentResolver.delete(ContentResolver.java:700)
at ... MY_ACTIVITY ...
It is possible for device manufacturers to change the implementation of a ContentProvider that ships with the AOSP. In theory, those changes would be caught by the Compatibility Test Suite (CTS), so that only devices that don't break the API will run your app when shipped through the Play Store.
That being said...
The CTS is far from complete
The CTS does not protect you if you intentionally distribute your app beyond the Play Store, and somebody with an incompatible device runs your app
The CTS does not protect you if you unintentionally distribute your app beyond the Play Store (i.e., your app's been pirated), and somebody with an incompatible device runs your app
Various device manufacturers pirate the Play Store app itself
So, when you see problems that would appear to originate from within an OS-supplied ContentProvider, but those problems are infrequent and/or are on unrecognized devices, don't panic. You still might choose to somehow fail gracefully in this case (by wrapping the failing calls in your own exception handler), but it's unlikely that your code is really the source of the difficulty.
The ContactsContract API has been available since level 5. Is it possible the users reporting this issue are < level 5 (Donut, Cupcake)?

Sqlite query not working when running on android device

I am using few update queries to update my tables(Sqlite). They are working very well on my emulator. But, when I installed on my phone, they dont return sucess. At the same time,it does not throw any errors also.
This is my code:
ContentValues msg_values = new ContentValues();
msg_values.put("folder_id", 1);
int i=getContentResolver().update(MBContants.CONTENT_URI_SMS, msg_values,
"address=" + msg.getAddress(), null);
if(i>0)
System.out.println("done..!");
else
Log.i("--------------------------------------------","not done");
Where, I've created my db and the URI to my table is MBContants.CONTENT_URI_SMS, where MBContants class holds all the URI's.
Please help solve this issue.
Thanks,
Viashnavi
Try debugging your app from the phone. Don't forget to turn debugging on in the phone's settings. Set a breackpoint at the start of this logic and step through to see what happens. I'm sure the answer will be pretty obvious once you do that.

Categories

Resources