The mPhoneNumber variable is coming back null. I have been debugging this thing for a week and I am extremely stuck. Why does getLine1Number
return null?
try
{
TelephonyManager tMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
if (tMgr != null)
{
if (checkSelfPermission(android.Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED)
{
if (checkSelfPermission(android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)
{
// TODO: Consider calling
// Activity#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for Activity#requestPermissions for more details.
return;
}
}
String mPhoneNumber = tMgr.getLine1Number();
// Log.v("PHONE: ", mPhoneNumber);
}
else
{
//Log.v("PHONE NO: ", "NO");
}
}
catch(Exception e)
{
// TODO: Handle exception
}