i have developped an android application, but i need to get the phone number
of the phone owner
. I have seen many questions here in stackoverflow and many answers but none works for me.
I work with Android 2.2:
I have tested this code, but nothing happened:
TelephonyManager phoneManager = (TelephonyManager)
getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = phoneManager.getLine1Number();
I added the permission in my manifest file READ_PHONE_STATE
, in my setting i can't see the phone number :/
I have seen those answers link and this ,and this is my problem
I know that i can get an unique id using getDeviceId()
but i'd get the number phone if it's possible ..
Can you give more information?
Any idea to get the phone number??
EDIT : In my country, we can see our number with USSD command ,the result is in dialogBox, can i read the datas in the USSD response?
I have tested this code, but nothing to get:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String encodedHash = Uri.encode("#");
String ussd = "*141*1" + encodedHash;
startActivityForResult(new Intent("android.intent.action.CALL",
Uri.parse("tel:" + ussd)), 1);
}
});
.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(getApplicationContext(),
"USSD: " + requestCode + " " + resultCode + " ", 1).show();
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
// String result=data.getStringExtra("result");
String dd = data.toString();
Toast.makeText(getApplicationContext(), dd, 1).show();
}
}
I also tested some examples but the result is :
Android doesn't support USSD service
Help plz?