如何让来电号码以及在Android的用户进行呼叫的时间? [英] How to get Call number as well as the duration of the call made by a user in Android?

查看:126
本文介绍了如何让来电号码以及在Android的用户进行呼叫的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要尽快拿到电话号码,因为他使他的Andr​​oid手机通话,然后当通话结束,然后我需要调用的持续时间。

I need to get the call number as soon as he makes the call from his android mobile and then when the call ends then i need the duration of the call.

推荐答案

创建一个广播接收器,写在你的接收机以下的onReceive()方法
该接收机给您回电话的最后一个记录,但要延时一段时间,以便它可以返回当前记录。

Create One broadcast receiver and write following in your receiver onReceive() method this receiver return last record of your call but make some time delay so it can return current record.

Cursor c=context.getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,null, null, null,android.provider.CallLog.Calls.DATE + " DESC");
     int numberColumn = c.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
    int dateColumn = c.getColumnIndex(
    android.provider.CallLog.Calls.DATE);

    // type can be: Incoming, Outgoing or Missed
    int typeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE);
    int DurationColumn = c.getColumnIndex(android.provider.CallLog.Calls.DURATION);

写下面您的 mainfest文件

<receiver android:name="Your Receiver">
             <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
</receiver>

在onRecieve把这个

In onRecieve put this

Bundle bundle = intent.getExtras();
            Set<String> keys = bundle.keySet();
            for (String key : keys) {
                Log.i("MYAPP##", key + "="+ bundle.getString(key));
                if(bundle.getString(key).equals("IDLE"))
                {
}

}

这篇关于如何让来电号码以及在Android的用户进行呼叫的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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