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.).
Related
I have a simple app which reads google calendar events and displays them in list. It works flawlessly on all android version - except 10. Minimalistic example of code:
Uri.Builder builder = Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, timeFrom);
ContentUris.appendId(builder, timeTo);
String projection = new String[] { Instances.EVENT_ID, Instances.TITLE };
String selection = null;
String args = null;
String sort = null;
cursor = contentResolver.query(builder.build(), projection, selection, args, sort);
As I said - works perfectly, except android 10.
On android 10 I noticed interesting anomaly - whenever I make a change in official Google Calendar app, my app does not reflect changes immediately - it takes a while.
Its completely random, sometimes changes are immediate or take seconds to show, but often its minutes and sometimes even hours - but if I go to Google Calendar app and manually press refresh there, it helps (again its random - 90% times it works, but occasionaly it doesnt)>
I am almost 100% sure Google changed something in their API on android 10 - some kind of cache - so it behaves randomly and unreliable now. All calendar widgets I tried have same problem, so probably its not the fault of an app )besides, the code was pretty much copied from official webpage).
How to solve this problem? Why on android 10 changes are not immediate? Is there a way to programatically trigger syncing/refresh of Google calendar from within my app?
I've noticed that my contentObservers for chrome history and bookmarks do not trigger anymore on android lolipop. The code works perfectly on older versions of android (regardless of the chrome version) but on Lollipop it is not working anymore.
I've filed a bug on chromium and this is confirmed by others in the comments.
https://code.google.com/p/chromium/issues/detail?q=obogzch%40gmail.com&colspec=ID%20Pri%20M%20Iteration%20ReleaseBlock%20Cr%20Status%20Owner%20Summary%20OS%20Modified&id=435541&thanks=435541&ts=1416575883
Did anybody found a solution to this?
LE:
Thanks Fuong Lee for the workaround, call this method after you add the content observer to jump start it:
private boolean checkContentProvider(Uri uri) //uri = content://com.android.chrome.browser/history
{
Cursor mCur = getContentResolver().query(uri, null, null, null, null);
return (mCur.getCount() > 0);
}
When I change new URI for chrome bookmarks from "content://com.android.chrome.browser/bookmarks" to new URI "content://com.android.chrome.browser/history", the same issue "onChange event not triggered on Lolipop version". And, I try query data to check after observer registered... it running like a magic. I don't know why it running correctly, hope it help.
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();
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)?
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);