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