如何获得在Android手机的报警数? [英] How to get the number of alarms in Android phone?

查看:157
本文介绍了如何获得在Android手机的报警数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用下面的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.

这篇关于如何获得在Android手机的报警数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆