如何获得未接来电和放大器;短信计数 [英] How to get Missed call & SMS count

查看:130
本文介绍了如何获得未接来电和放大器;短信计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得未接来电和我的应用程序未读邮件的数量。我想打开相关应用程序时,用户在点击计数

I want to get the count of missed calls and unread messages in my application. and I'd like to open the relevant application when user click on the count.

现在最大的问题是如何让伯爵?

Now biggest problem is how to get the count?

我在网上搜索,但没有找到任何解决方案。

I searched online but couldn't find any solution.

在此先感谢。

推荐答案

<一个href="http://developer.android.com/reference/android/provider/CallLog.Calls.html">http://developer.android.com/reference/android/provider/CallLog.Calls.html

看看这个 CallLog 类。所有你需要的是查询电话为任何电话,然后提取错过了(оr做到这一点时,要查询的手机,在选择参数)。这同样适用于该消息。短信存储在内容提供商在内容://短信/

Take a look at this CallLog class. All you need is to query the phone for any calls then extract missed one (оr do this when you are querying the phone, in the selection arguments). The same applies for the messages. SMS are stored in the Content provider under "content://sms/"

然后,只需获得的行数的光标即返回由查询。 :)

Then just get the count of rows in the Cursor that is return by the query. :)

我希望这有助于。

编辑:未接来电:

 String[] projection = { CallLog.Calls.CACHED_NAME, CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.TYPE };
       String where = CallLog.Calls.TYPE+"="+CallLog.Calls.MISSED_TYPE;          
       Cursor c = this.getContentResolver().query(CallLog.Calls.CONTENT_URI, selection,where, null, null);
       c.moveToFirst();    
       Log.d("CALL", ""+c.getCount()); //do some other operation
        if(c.getCount() == SOME_VALUE_TO_START_APP_ONE)//...etc etc

在where子句设置条件,选择数据。在我们的例子中,我们需要的一切这类型等于 CallLog.Calls.MISSED_TYPE 。我们选择项目的来电和他的数名着,当然你可以指定更多信息要查询像许多类型像手机,家庭,工作。 这位前pression相当于SQL查询中,是这样的: SELECT CACHED_NAME,CACHED_NUMBER_LABEL,键入CONTENT_URI其中type = MISSED_TYPE

In the where clause you set condition for selection of data. In our case we need everything which type equals CallLog.Calls.MISSED_TYPE. We select project the Name of the caller and his number, ofcourse you can specify more information to be queried like type of number like mobile, home, work. The expression is equivalent to SQL query, something like: SELECT CACHED_NAME, CACHED_NUMBER_LABEL, TYPE FROM CONTENT_URI WHERE TYPE=MISSED_TYPE

此需要被添加到清单

 <uses-permission android:name="android.permission.READ_LOGS"></uses-permission>
 <uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>

有关查询短信的ContentProvider

Uri sms_content = Uri.parse("content://sms");
Cursor c = this.getContentResolver().query(sms_content, null,null, null, null);
c.moveToFirst();
Log.d("SMS COUNT", ""+c.getCount()); //do some other operation
//Here proceed with the what you wanted
if(c.getCount() == SOME_VALUE_TO_START_APP_ONE)//...etc etc

您可以在内容树更深,如指定的短信类型,如:内容://短信/发送内容:/ /短信/收件箱并添加投影和选择的查询的第二个参数()法像,姓名,人,信息的状态(如呼叫的例子)。

You can go deeper in the content tree like specifying the type of sms, like: content://sms/sent or content://sms/inbox and add projection and selection for the second argument of the query() method like, name, person, status of the message (like the Calls example).

这需要权限:

 <uses-permission android:name="android.permission.READ_SMS"></uses-permission>

这篇关于如何获得未接来电和放大器;短信计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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