get mobile number from android version 6.0 using TelephonyManager , it works with lowest versions -


i want mobile number device using telephonymanager in android studio , able in version 4.0 app gets crash when test version 6.0

you should check if user has granted permission of telephonymanager version 6.0. can check details link

the following code checks if app has permission read user's contacts, , requests permission if necessary:

// here, thisactivity current activity if (contextcompat.checkselfpermission(thisactivity,             manifest.permission.read_contacts)     != packagemanager.permission_granted) {  // should show explanation? if (activitycompat.shouldshowrequestpermissionrationale(thisactivity,         manifest.permission.read_contacts)) {      // show expanation user *asynchronously* -- don't block     // thread waiting user's response! after user     // sees explanation, try again request permission.  } else {      // no explanation needed, can request permission.      activitycompat.requestpermissions(thisactivity,             new string[]{manifest.permission.read_contacts},             my_permissions_request_read_contacts);      // my_permissions_request_read_contacts     // app-defined int constant. callback method gets     // result of request. } 

}


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -