Delete calendar event on Android (Samsung S-Planner) - android

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!!

Related

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();

Android app using Google calendar - Sync issue

I am trying to create an android app that interfaces with the Google Calendar.
I have followed the tutorial using content providers from here. Parts of this code are explained here.
I am facing the below issues.
I created a new calendar TestCalendar from my online from my laptop, and marked it as Selected. When I query for my calendars from the app, I can see this new calendar, but it is shown as unselected (selected=0). Any suggestions on why this could be happening ?
From my app, I add an event to the calendar by
getContentResolver().insert(eventsUri, event);
The event is reflected in the calendar on phone, but it is not reflected in the online version. To push this new event online, I have to manually Synchronize the calendar, or turn the Auto Sync on, which I believe is not the right way in which this should be done. Any suggestions/links which could help ?
1) Can you dump your calendar and post the result?
Notice:
Android < API Lvl 14 you must set selected = 1
Android > API Lvl 14 you must set visible = 1 (selected is not longer available)
Dump:
cursor = contentResolver.query(Uri.parse(CALENDAR_URI),null, null, null,null);
while (cursor.moveToNext()) {
for (int i = 0; i < cursor.getColumnCount(); i++) {
Log.e("XXX", cursor.getColumnName(i) + ": " + cursor.getString(i));
}
}
CALENDAR_URI = content://com.android.calendar/calendars (since Froyo) or content://calendar/ (before Froyo)
2) https://stackoverflow.com/a/11652415/411951

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

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);

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.

Get the list of enabled alarm using default sdk?

I've been seeking how to simply get a list of all enabled alarm.
So far I found two things:
String nextAlarm = Settings.System.getString(getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED);
And this project but it uses:
public static final Uri CONTENT_URI =
Uri.parse("content://com.android.deskclock/alarm");
ContentResolver cr = getContentResolver();
Cursor c = null;
c = cr.query(
CONTENT_URI, ALARM_QUERY_COLUMNS,
null, null, DEFAULT_SORT_ORDER);
And as said by CommonsWare here: "This is not part of the Android SDK. It may not work on all devices. It may not work on all current Android versions. It may not work on future Android versions. It is not documented. It is not supported".
So far, the first one works but gives only one alarm when I want all of them. And the second one is just not good.
So how can I get a list of upcoming alarm ?
Thanks in advance.
So how can I get a list of upcoming alarm ?
You can't, any more than you can get the "list of upcoming alarm" from the hundreds of other alarm clock apps that users use (distributed on the Market, on devices that replace com.android.deskclock, etc.).

Categories

Resources