In my application i want get phone number from sim card and show user.
I write below codes, but in emulator show me sim card number , but some devices such as Samsung not show me any sim card number.
Manifest code:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Activity code:
public class FetchSimActivity extends AppCompatActivity {
TextView fetchSimCardTxt, fetchNumCardTxt;
TelephonyManager tm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fetch_sim);
fetchSimCardTxt = findViewById(R.id.fetchSimCardTxt);
fetchNumCardTxt = findViewById(R.id.fetchNumCardTxt);
tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#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 ActivityCompat#requestPermissions for more details.
return;
}
String simID = tm.getSimSerialNumber();
if (simID != null) {
fetchSimCardTxt.setText("SIM ID : + " + simID);
}
String telNumber = tm.getLine1Number();
if (telNumber != null) {
fetchNumCardTxt.setText("SIM NUM : + " +telNumber);
}
}
}
How can i get sim card number from all devices in android?