How to get Missed call & SMS count

I want to get the number of missed calls and unread messages in my application. and I would like to open the corresponding application when the user clicks on the account.

Now the biggest problem is how to get the bill?

I searched on the Internet but could not find a solution.

Thanks in advance.

+5
source share
2 answers

http://developer.android.com/reference/android/provider/CallLog.Calls.html

CallLog. , , - , ( , , ). . SMS "content://sms/"

, .:)

, .

: :

 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. " " , , , , , , , . SQL, : 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>

SMS 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

, , sms, : content://sms/sent content://sms/inbox, query() , , , (, Calls).

:

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

, @Prasad

→ getContentResolver() - undefined new Runnable() {}

getContentResolver() , , BroadcastReceiver onReceive(),

    @Override
    public void onReceive(Context context, Intent intent) {

    context.getContentResolver()
}

Activity,

getApplicationContext().getContentResolver()

[Ctrl + Shift + O (O )]

Eclipse

, - , , .

0

All Articles