如何获得在Android手机的报警数?如何获得、手机、Android

2023-09-05 04:52:22 作者:有多难就有多勇敢う

我尝试使用下面的code拿到手机上当前设置的报警数量。

 开放的URI = Uri.parse(内容://com.android.deskclock/AlarmClock);
光标C = getApplicationContext()getContentResolver()查询(URI,NULL,NULL,NULL,NULL);
 

但我得到一个 NullPointerException异常当我尝试使用,以获取数

  INT NUM = c.getCount();
的System.out.println(没有报警:+ c.getCount());
 

请让我知道我做错了什么?在getCount将(发生的除外)本身,所以我不能够显示的报警数量。

编辑:我也得到这个消息对我的LogCat中:

  ActivityThread(13290):未能找到com.android.deskclock供应商信息
 
给家里购装智能锁前,这些方面的知识你不可不了解

解决方案

乌里你要找的是内容://融为一体。 android.deskclock /报警,但您无法访问应用程序的的ContentProvider ,因为它不出口。你只是抛出一个 SecurityException异常

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.