Вопрос

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
Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top