Hi Mike
Try use below method
private String getLastCallLogEntry( Context context ) {
String[] projection = new String[] {
BaseColumns._ID,
CallLog.Calls.NUMBER,
CallLog.Calls.TYPE
};
ContentResolver resolver = context.getContentResolver();
Cursor cur = resolver.query(
CallLog.Calls.CONTENT_URI,
projection,
null,
null,
CallLog.Calls.DEFAULT_SORT_ORDER );
int numberColumn = cur.getColumnIndex( CallLog.Calls.NUMBER
);
int typeColumn = cur.getColumnIndex( CallLog.Calls.TYPE );
if( !cur.moveToNext() ) {
cur.close();
return "";
}
String number = cur.getString( numberColumn );
String type = cur.getString( typeColumn );
String dir = null;
try {
int dircode = Integer.parseInt( type );
switch( dircode ) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
} catch( NumberFormatException ex ) {}
if( dir == null )
dir = "Unknown, code: "+type;
cur.close();
return number;
}
On Wed, Apr 28, 2010 at 5:26 PM, mike <[email protected]> wrote:
> i want to capture Outgoing call numner. i'm using the
> BroadCastReceiver. but every time it returns a blank String for the
> number.
> it works fine for the incoming number.
>
> this is my code
>
> public class CallListener extends BroadcastReceiver {
> private Context context;
> Intent intentttt = null;
> String phonenbr;
>
> @Override
> public void onReceive(Context context, Intent intent) {
> // TODO Auto-generated method stub
> this.context = context;
>
> TelephonyManager telManager = (TelephonyManager) context
> .getSystemService(Context.TELEPHONY_SERVICE);
> telManager.listen(new StateListener(),
> PhoneStateListener.LISTEN_CALL_STATE);
> }
>
> class StateListener extends PhoneStateListener {
> @Override
> public void onCallStateChanged(int state, String incomingNumber)
> {
> // TODO Auto-generated method stub
> // super.onCallStateChanged(state, incomingNumber);
> switch (state) {
> case TelephonyManager.CALL_STATE_RINGING:
> Intent intent = new Intent(context, AnimationView.class);
> intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
> String[] details = new String[] { "RINGING",
> incomingNumber };
> intent.putExtra("INCOMING", details);
> context.startActivity(intent);
> Log.d("DEBUG", "RINGING");
> break;
> case TelephonyManager.CALL_STATE_IDLE:
> System.exit(0);
> break;
> case TelephonyManager.CALL_STATE_OFFHOOK:
> // IntentFilter
> Log.d("NO", incomingNumber);
> Intent outIntent = new Intent(context, OutGoing.class);
>
> outIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
> outIntent.putExtra("Number", incomingNumber);
> context.startActivity(outIntent);
> break;
> }
> }
> }
>
> }
>
> and i'm using these permissions in the manifest
>
> <uses-permission android:name="android.permission.READ_PHONE_STATE"></
> uses-permission>
> <uses-permission android:name=".Provider.Permission.READ"></uses-
> permission>
> <uses-permission android:name=".Provider.Permission.WRITE"></uses-
> permission>
> <uses-permission android:name="android.permission.WRITE_CONTACTS"></
> uses-permission>
> <uses-permission android:name="android.permission.READ_CONTACTS"></
> uses-permission>
> <uses-permission android:name="android.permission.CALL_PHONE"></uses-
> permission>
> <uses-permission
> android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-
> permission>
>
> any suggestions??
>
> regards,
> Randika
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
==============================
Tel:976-70151145
Fax:976-70151146
Mobile: 976-88115679
Web: http://www.usi.mn
==============================
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en