Android 如何将通讯录中储存的号码与来电号码进行匹配

Android 如何将通讯录中储存的号码与来电号码进行匹配,android,Android,嗨,朋友们,我正在尝试做一个项目,在这个项目中,我将呼入号码与储存在不同手机中的不同格式的号码进行匹配。 我能够匹配“+919045308261”和“+919045308261”,但我希望匹配必须也适用于其他格式。我必须做什么才能使其也适用于其他格式??。。 我使用的代码是 package com.example.matchnumbers; import android.os.Bundle; import android.app.Activity; import android.view.Me

嗨,朋友们,我正在尝试做一个项目,在这个项目中,我将呼入号码与储存在不同手机中的不同格式的号码进行匹配。 我能够匹配“+919045308261”和“+919045308261”,但我希望匹配必须也适用于其他格式。我必须做什么才能使其也适用于其他格式??。。 我使用的代码是

package com.example.matchnumbers;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends Activity {

    String incomingcall = "+919045308261";
    String str = "+91 90 45 308261";
    String st1 = "0 90 45 308261";
    String str2 = "90 45 308261";
    String str3="9045308261";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        str = str.replaceAll("\\s+","");
        if(incomingcall.equals(str)){
            Toast.makeText(getApplicationContext(), "Hit occurs", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
希望这对您有所帮助:

好友您可以使用
ContentProvider
(用于比较电话号码和联系人)

上述代码将与联系人列表中的电话号码匹配,如果联系人中存储了电话号码,则会返回联系人姓名

或者如果您有两个字符串,并且希望比较它们:

String phone1;   
String phone2; 

 if (PhoneNumberUtils.compare(phone1, phone2)) {
      // code if both are same
   }

使用…@GopalRao你好,你在很长一段时间后认识的,你好吗???n谢谢你的回答,你总是很帮我。看起来你很忙。好的,每当你有空的时候,请看一下这个东西。。。。布尔a=PhoneNumberRutils.compare(数字,phoneNumber);if(a){String contname=phoneCursor.getString(phoneCursor.getColumnIndex(DISPLAY_NAME));if(!contname.equals(null)){Toast.makeText(getApplicationContext(),contname,Toast.LENGTH_SHORT).show();tts.speak(contname+“calling”,TextToSpeech.QUEUE_FLUSH,null);}我正在将contactname发送给AT,但问题是它没有说出contactname
String phone1;   
String phone2; 

 if (PhoneNumberUtils.compare(phone1, phone2)) {
      // code if both are same
   }