通过android中的联系人名称检索联系人列表

时间:2015-08-11 07:52:20

标签: java android-activity

我的应用程序需要通过联系人列表中的联系人姓名检索联系人。我尝试从网络中获取一些功能,但所有结果都失败了。我在我的应用程序中使用广播接收器,当新消息收到时触发功能。我正在使用广播接收器的onReceive()方法。我将把我的代码放在下面,

public void onReceive(Context context, Intent intent) {
ShowToaster(context,intent);

}

private void ShowToaster(Context context,Intent intent)
{
    // Retrieves a map of extended data from the intent.
            final Bundle bundle = intent.getExtras();

            try {

                if (bundle != null) {

                    final Object[] pdusObj = (Object[]) bundle.get("pdus");

                    for (int i = 0; i < pdusObj.length; i++) {

                        SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                        String phoneNumber = currentMessage.getDisplayOriginatingAddress();

                        String senderNum = phoneNumber;
                        String message = currentMessage.getDisplayMessageBody();

                        Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);

                        int duration = Toast.LENGTH_LONG;
                        Toast toast = Toast.makeText(context, "senderNum: "+ senderNum + ", message: " + message, duration);
                        toast.show();

                    } // end for loop
                  } // bundle is null

            } catch (Exception e) {
                Log.e("SmsReceiver", "Exception smsReceiver" +e);

            }
            ReadPhoneContacts(context,"Dad");

}

public void ReadPhoneContacts(Context cntx,String name) 
{
    //need to retrieve contact by contact name
}

0 个答案:

没有答案