I mean you definitely need to know the country code somehow. you might be able to get it from the phone (read this answer for instance) in case it is absent.
then once you have it you simply write
phone="+"+foundCountryCode+phone;
but before you do that you need to check if the phone nr. doesnt already have a country code as some of the users contacts might be from other countries (we live in a globalized world) so simply check if the phone String begins with "+" or "00" and only perform the adjustment above in case it does not.
I did the following
public static String depuratePhone(String rawPhone){
String phone=rawPhone.replace(" ","").replace("+","00").replace("-","");
String depPhone=null;
if (phone.length()>2){
if (phone.substring(0,2).contentEquals("00")){
depPhone=phone;
}else{
depPhone="00"+your_current_country_code+phone;
}
}
return depPhone;
}
in order to get your own phones country code amazingly it seems you always have to create your own database of country codes as all you can get from the phone are 2 letter string codes for your country. I am also amazed that there is not a way to get this directly from the phone. Amazing, I wonder what the justification for this is.
the freaking TelephonyManager even lets you get your own phone number if you grant it a ton of permissions but not a simple country code.