How to get the number of alarms in Android phone?

不想你离开。 提交于 2019-12-18 09:40:58

问题


I am trying to use the following code to get the number of alarms currently set on the phone.

Uri uri = Uri.parse("content://com.android.deskclock/AlarmClock");
Cursor c = getApplicationContext().getContentResolver().query(uri, null, null, null,null);

But I get a NullPointerException when I try to fetch the number using

int num = c.getCount();
System.out.println("No of alarms : "+c.getCount());

Please let me know what I am doing wrong ? The exception occurs in getCount() itself so I am not able to display the number of alarms.

EDIT: I also get this message on my LogCat :

ActivityThread(13290): Failed to find provider info for com.android.deskclock

回答1:


The Uri you're looking for is content://com.android.deskclock/alarms, but you can't access the app's ContentProvider because it isn't exported. You'll just throw a SecurityException.



来源:https://stackoverflow.com/questions/22523404/how-to-get-the-number-of-alarms-in-android-phone

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