Java Examples for android.Manifest.permission.READ_PHONE_STATE
The following java examples will help you to understand the usage of android.Manifest.permission.READ_PHONE_STATE. These source code samples are taken from different open source projects.
Example 1
Project: Klyph-master File: Android.java View source code |
public static String getDeviceUDID(Context ctx) {
final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice, tmSerial, androidId;
PackageManager pm = ctx.getPackageManager();
int hasPerm = pm.checkPermission(android.Manifest.permission.READ_PHONE_STATE, ctx.getPackageName());
if (hasPerm == PackageManager.PERMISSION_GRANTED) {
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
} else {
tmDevice = Settings.Secure.ANDROID_ID;
tmSerial = android.os.Build.SERIAL;
}
androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
String deviceId = deviceUuid.toString();
return deviceId;
}
Example 2
Project: digits-android-master File: SimManagerTest.java View source code |
@Test
public void testGetPhoneNumber_noPermission() throws Exception {
when(context.checkCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE)).thenReturn(PackageManager.PERMISSION_DENIED);
simManager = SimManager.createSimManager(context);
when(telephonyManager.getLine1Number()).thenReturn(TestConstants.PHONE);
assertEquals("", simManager.getRawPhoneNumber());
}
Example 3
Project: ikvStockChart-master File: AppRuntimeInitializer.java View source code |
private void initIMEI() {
final String TAG = "AppRuntime";
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(AppRuntime.sContext, android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
TelephonyManager tm = (TelephonyManager) AppRuntime.sContext.getSystemService(Context.TELEPHONY_SERVICE);
DeviceRuntime.IMEI = tm.getDeviceId();
DeviceRuntime.DEVICE_ID = Settings.Secure.getString(AppRuntime.sContext.getContentResolver(), Settings.Secure.ANDROID_ID);
}
Log.e(TAG, "### initIMEI: IMEI = " + DeviceRuntime.IMEI + ", DEVICE_ID = " + DeviceRuntime.DEVICE_ID);
}
Example 4
Project: prey-android-client-master File: PreyPhone.java View source code |
public int getSimState() {
TelephonyManager tManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
int simState = -1;
try {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ctx.checkSelfPermission(android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
simState = tManager.getSimState();
}
} else {
simState = tManager.getSimState();
}
} catch (Exception e) {
PreyLogger.e("Error getSimSerialNumber:" + e.getMessage(), e);
}
return simState;
}
Example 5
Project: android_packages_apps_GmsCore-master File: SelfCheckFragment.java View source code |
@Override
protected void prepareSelfCheckList(List<SelfCheckGroup> checks) {
checks.add(new RomSpoofSignatureChecks());
checks.add(new InstalledPackagesChecks());
if (SDK_INT > LOLLIPOP_MR1) {
checks.add(new PermissionCheckGroup(ACCESS_COARSE_LOCATION, WRITE_EXTERNAL_STORAGE, GET_ACCOUNTS, READ_PHONE_STATE));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checks.add(new SystemChecks());
}
checks.add(new NlpOsCompatChecks());
checks.add(new NlpStatusChecks());
}
Example 6
Project: android_frameworks_base-master File: TelecomManager.java View source code |
/** * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific * account returned depends on the following priorities: * <ul> * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will * be returned. * </li> * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it * will be returned. * </li> * </ul> * <p> * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}. * * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} * * @param uriScheme The URI scheme. * @return The {@link PhoneAccountHandle} corresponding to the account to be used. */ @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) { try { if (isServiceConnected()) { return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme, mContext.getOpPackageName()); } } catch (RemoteException e) { Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e); } return null; }
Example 7
Project: AndroidSamples-master File: RuntimePermissionActivity.java View source code |
public void onPermission(View v) {
switch(v.getId()) {
case R.id.calendar:
//日历
requestRuntimePermission(READ_CALENDAR, this);
break;
case R.id.camera:
//照相机
requestRuntimePermission(CAMERA, this);
break;
case R.id.contacts:
//通讯录
requestRuntimePermission(READ_CONTACTS, this);
break;
case R.id.location:
//定位
requestRuntimePermission(ACCESS_FINE_LOCATION, this);
break;
case R.id.microPhone:
//录音
requestRuntimePermission(RECORD_AUDIO, this);
break;
case R.id.readPhone:
//读取手机状态
requestRuntimePermission(READ_PHONE_STATE, this);
break;
case R.id.sensors:
//传感器
requestRuntimePermission(BODY_SENSORS, this);
break;
case R.id.sms:
//短信
requestRuntimePermission(SEND_SMS, this);
break;
case R.id.storage:
//文件管理
requestRuntimePermission(READ_EXTERNAL_STORAGE, this);
break;
case R.id.contactsLocation:
requestContactsLocation();
break;
case R.id.easyPermissions:
methodRequiresTwoPermission();
break;
}
}
Example 8
Project: mobile-sdk-android-master File: DJISampleApplication.java View source code |
@Override
public void onCreate() {
super.onCreate();
/*
* handles SDK Registration using the API_KEY
*/
int permissionCheck = ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE);
if (permissionCheck == 0 || Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
DJISDKManager.getInstance().registerApp(this, mDJISDKManagerCallback);
}
instance = this;
}
Example 9
Project: GPS2SMS-master File: GpsHelper.java View source code |
@TargetApi(23)
public static boolean canAccessLocation(BaseActivity a) {
// All needed permissions
return (hasPermission(android.Manifest.permission.ACCESS_FINE_LOCATION, a) && hasPermission(android.Manifest.permission.SEND_SMS, a) && hasPermission(android.Manifest.permission.RECEIVE_SMS, a) && hasPermission(android.Manifest.permission.READ_SMS, a) && hasPermission(android.Manifest.permission.READ_CONTACTS, a) && hasPermission(android.Manifest.permission.READ_PHONE_STATE, a));
}
Example 10
Project: yako-master File: MainActivity.java View source code |
// Associate the device with a user public void registerPushNotification() { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { // READ_PHONE_STATE permission has not been granted. ActivityCompat.requestPermissions(MainActivity.this, new String[] { android.Manifest.permission.READ_PHONE_STATE }, 1); } else { // READ_PHONE_STATE permission is already been granted. final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE); final String tmDevice, tmSerial, androidId; tmDevice = "" + tm.getDeviceId(); tmSerial = "" + tm.getSimSerialNumber(); androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); final UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); final String deviceId = deviceUuid.toString(); ParseInstallation installation = ParseInstallation.getCurrentInstallation(); installation.put("user", mCurrentUser); installation.put("uniqueId", deviceId); installation.saveInBackground(); } }
Example 11
Project: android-imf-ext-master File: TelephonyRegistry.java View source code |
private void broadcastCallStateChanged(int state, String incomingNumber) {
long ident = Binder.clearCallingIdentity();
try {
if (state == TelephonyManager.CALL_STATE_IDLE) {
mBatteryStats.notePhoneOff();
} else {
mBatteryStats.notePhoneOn();
}
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
Intent intent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
intent.putExtra(Phone.STATE_KEY, DefaultPhoneNotifier.convertCallState(state).toString());
if (!TextUtils.isEmpty(incomingNumber)) {
intent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, incomingNumber);
}
mContext.sendBroadcast(intent, android.Manifest.permission.READ_PHONE_STATE);
}