List of usage examples for android.telephony TelephonyManager getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
public static void setDataEnabled(Context context, boolean enabled) { try {//from w w w .ja v a 2s .c o m TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Method setMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("setDataEnabled", boolean.class); if (null != setMobileDataEnabledMethod) { setMobileDataEnabledMethod.invoke(tm, enabled); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean getDataEnabled(Context context) { try {//from www .j a v a2s . co m TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Method getMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("getDataEnabled"); if (null != getMobileDataEnabledMethod) { return (boolean) getMobileDataEnabledMethod.invoke(tm); } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
protected static Object getITelephony(final Context context) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException, IllegalAccessException { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final Method getITelephony = tm.getClass().getDeclaredMethod("getITelephony"); if (!getITelephony.isAccessible()) { getITelephony.setAccessible(true); }/*from ww w . java 2s. c o m*/ return getITelephony.invoke(tm); }
From source file:Main.java
/** * Requires {@link android.Manifest.permission#READ_PHONE_STATE} permission. * * @param context/*from www . j a v a 2s.com*/ * @return */ public static boolean isMobileDataEnabled(Context context) { boolean mobileDataEnabled = false; // Assume disabled if (Build.VERSION.SDK_INT >= 21) { try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class<?> tmClass = Class.forName(tm.getClass().getName()); Method method = tmClass.getDeclaredMethod("getDataEnabled"); method.setAccessible(true); mobileDataEnabled = (Boolean) method.invoke(tm); } catch (ClassNotFoundException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } } else { try { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); Class<?> cmClass = Class.forName(cm.getClass().getName()); Method method = cmClass.getDeclaredMethod("getMobileDataEnabled"); method.setAccessible(true); mobileDataEnabled = (Boolean) method.invoke(cm); } catch (ClassNotFoundException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } } return mobileDataEnabled; }
From source file:hmatalonga.greenhub.models.SimCard.java
/** * Retrieves sim operator name using an undocumented telephony manager call. * WARNING: Uses reflection, data might not always be available. * * @param context/*w w w. j a v a2 s . c om*/ * @param subId * @return */ private static String getSimOperatorNameForSubscription(final Context context, int subId) { TelephonyManager stub = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); try { Class<?> telephonyManager = Class.forName(stub.getClass().getName()); Method getName = telephonyManager.getMethod("getSimOperatorNameForSubscription", int.class); getName.setAccessible(true); return ((String) getName.invoke(context, subId)); } catch (Exception e) { if (Config.DEBUG && e != null && e.getLocalizedMessage() != null) { LOGD(TAG, "Failed getting sim operator with subid: " + e.getLocalizedMessage()); } } return null; }
From source file:com.ripperdesignandmultimedia.phoneblockplugin.PhoneBlockerPlugin.java
public void onReceive() { try {//from w w w . j a va2 s . c om TelephonyManager localTelephonyManager; Method localMethod = Class.forName(localTelephonyManager.getClass().getName()) .getDeclaredMethod("getITelephony", new Class[0]); localMethod.setAccessible(true); this.telephonyService = ((ITelephony) localMethod.invoke(localTelephonyManager, new Object[0])); this.telephonyService.endCall(); return; } catch (Exception e) { Log.e(LOG_TAG, "Couldn't Block Call: " + e.getMessage(), e); } }
From source file:at.bitfire.nophonespam.CallReceiver.java
protected void rejectCall(@NonNull Context context, Number number) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class c = null;// w w w . java 2 s .c om try { c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony telephony = (ITelephony) m.invoke(tm); telephony.endCall(); } catch (Exception e) { e.printStackTrace(); } Settings settings = new Settings(context); if (settings.showNotifications()) { Notification notify = new NotificationCompat.Builder(context).setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(context.getString(R.string.receiver_notify_call_rejected)) .setContentText(number != null ? (number.name != null ? number.name : number.number) : context.getString(R.string.receiver_notify_private_number)) .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_CALL) .setShowWhen(true).setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, BlacklistActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)) .addPerson("tel:" + number).setGroup("rejected").build(); String tag = number != null ? number.number : "private"; NotificationManagerCompat.from(context).notify(tag, NOTIFY_REJECTED, notify); } }
From source file:org.easyaccess.phonedialer.CallingScreen.java
private void answerCall() { try {//from w w w .j av a 2 s. c o m TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Class clazz = Class.forName(telephonyManager.getClass().getName()); Method method = clazz.getDeclaredMethod("getITelephony"); method.setAccessible(true); ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager); telephonyService.answerRingingCall(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.easyaccess.phonedialer.CallingScreen.java
private void rejectCall() { try {/* w w w .j a va 2 s .co m*/ TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Class clazz = Class.forName(telephonyManager.getClass().getName()); Method method = clazz.getDeclaredMethod("getITelephony"); method.setAccessible(true); ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager); telephonyService.endCall(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.easyaccess.phonedialer.CallingScreen.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // long press of power button will end the call if (KeyEvent.KEYCODE_POWER == event.getKeyCode()) { TelephonyManager telephony = (TelephonyManager) getApplicationContext() .getSystemService(Context.TELEPHONY_SERVICE); try {//w w w.j a va2s. co m Class<?> c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony telephonyService = (ITelephony) m.invoke(telephony); telephonyService.endCall(); } catch (Exception e) { e.printStackTrace(); } return true; } else if (keyCode == KeyEvent.KEYCODE_BACK) { // do nothing return true; } return super.onKeyDown(keyCode, event); }