Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在android中按联系人姓名检索联系人列表_Java_Android Activity - Fatal编程技术网

Java 在android中按联系人姓名检索联系人列表

Java 在android中按联系人姓名检索联系人列表,java,android-activity,Java,Android Activity,我的应用程序需要从联系人列表中按联系人姓名检索联系人。我尝试了从网络获取的一些功能,但所有结果都失败。我在应用程序中使用广播接收器,当收到新消息时,它会触发一个函数。我正在使用广播接收器的onReceive()方法。我将把我的代码放在下面 public void onReceive(Context context, Intent intent) { ShowToaster(context,intent); } private void ShowToaster(Context context,

我的应用程序需要从联系人列表中按联系人姓名检索联系人。我尝试了从网络获取的一些功能,但所有结果都失败。我在应用程序中使用广播接收器,当收到新消息时,它会触发一个函数。我正在使用广播接收器的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
}
public void onReceive(上下文、意图){
ShowToaster(上下文、意图);
}
私有void ShowToaster(上下文、意图)
{
//从意图检索扩展数据的映射。
final Bundle=intent.getExtras();
试一试{
if(bundle!=null){
最终对象[]pdusObj=(对象[])bundle.get(“pdus”);
对于(int i=0;i