List of usage examples for android.telephony TelephonyManager getCallState
public @CallState int getCallState()
From source file:Main.java
public static int getCallState(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.getCallState(); }
From source file:Main.java
public static boolean isInSystemCall(Context context) { TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telManager == null) return false; return (telManager.getCallState() != TelephonyManager.CALL_STATE_IDLE); }
From source file:edu.polyu.screamalert.SoundProcessing.java
private static void callPhone() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Exchanger.thisContext); String phoneNumber = prefs.getString("phoneNumber", null); Boolean enableCall = prefs.getBoolean("enableCall", false); if (phoneNumber != null && enableCall) { if (phoneNumber.trim().length() > 0) { // Avoid empty string or white spaces in the preference field TelephonyManager phoneMgr = (TelephonyManager) thisContext .getSystemService(Context.TELEPHONY_SERVICE); if (phoneMgr.getCallState() == TelephonyManager.CALL_STATE_IDLE && phoneMgr.getSimState() != TelephonyManager.SIM_STATE_ABSENT) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); callIntent.setData(Uri.parse("tel:" + phoneNumber)); Exchanger.thisContext.startActivity(callIntent); }/* ww w .j a v a 2s . com*/ } } }
From source file:com.meiste.tempalarm.gcm.GcmIntentService.java
@Override protected void onHandleIntent(final Intent intent) { final Bundle extras = intent.getExtras(); final GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); final String messageType = gcm.getMessageType(intent); if (extras != null && !extras.isEmpty() && extras.containsKey(MSG_KEY) && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { final String type = extras.getString(MSG_KEY); final String state = extras.getString(STATE_KEY, "UNKNOWN"); Timber.d("Received %s message with state %s", type, state); // Only show notification if user wants results notifications final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final boolean ok2notify = prefs.getBoolean(AppConstants.PREF_NOTIFICATIONS, true); SyncAdapter.requestSync(this, ok2notify); if (ok2notify) { cancelNotification();/* w ww .j a v a 2 s . com*/ final Intent killIntent = new Intent(AppConstants.INTENT_ACTION_KILL_ALARM); LocalBroadcastManager.getInstance(this).sendBroadcastSync(killIntent); final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); final boolean inCall = tm.getCallState() != TelephonyManager.CALL_STATE_IDLE; switch (type) { case MSG_KEY_ALARM: handleAlarm(state, inCall); break; case MSG_KEY_SENSOR: handleSensor(state, inCall); break; default: Timber.i("Message type unknown. Ignoring."); break; } } } GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.polyvi.xface.extension.telephony.XTelephonyExt.java
private void incomingCallResponse(Intent intent) { TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Service.TELEPHONY_SERVICE); XEvent evt = XEvent.createEvent(XEventType.CALL_RECEIVED, tm.getCallState()); ((XFaceMainActivity) mContext).getEventCenter().sendEventAsync(evt); }
From source file:com.polyvi.xface.extension.XTelephonyExt.java
private void incomingCallResponse(Intent intent) { Context ctx = getContext();//from www .ja v a2 s. c om TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Service.TELEPHONY_SERVICE); XEvent evt = XEvent.createEvent(XEventType.CALL_RECEIVED, tm.getCallState()); XSystemEventCenter.getInstance().sendEventAsync(evt); }
From source file:fr.inria.ucn.collectors.NetworkStateCollector.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private JSONObject getMobile(TelephonyManager tm) throws JSONException { JSONObject mob = new JSONObject(); mob.put("call_state", tm.getCallState()); mob.put("data_activity", tm.getDataActivity()); mob.put("network_type", tm.getNetworkType()); mob.put("network_type_str", Helpers.getTelephonyNetworkType(tm.getNetworkType())); mob.put("phone_type", tm.getPhoneType()); mob.put("phone_type_str", Helpers.getTelephonyPhoneType(tm.getPhoneType())); mob.put("sim_state", tm.getSimState()); mob.put("network_country", tm.getNetworkCountryIso()); mob.put("network_operator", tm.getNetworkOperator()); mob.put("network_operator_name", tm.getNetworkOperatorName()); // current cell location CellLocation cl = tm.getCellLocation(); if (cl != null) { JSONObject loc = new JSONObject(); if (cl instanceof GsmCellLocation) { JSONObject cell = new JSONObject(); cell.put("cid", ((GsmCellLocation) cl).getCid()); cell.put("lac", ((GsmCellLocation) cl).getLac()); cell.put("psc", ((GsmCellLocation) cl).getPsc()); loc.put("gsm", cell); } else if (cl instanceof CdmaCellLocation) { JSONObject cell = new JSONObject(); cell.put("bs_id", ((CdmaCellLocation) cl).getBaseStationId()); cell.put("bs_lat", ((CdmaCellLocation) cl).getBaseStationLatitude()); cell.put("bs_lon", ((CdmaCellLocation) cl).getBaseStationLongitude()); cell.put("net_id", ((CdmaCellLocation) cl).getNetworkId()); cell.put("sys_id", ((CdmaCellLocation) cl).getSystemId()); loc.put("cdma", cell); }/*from www . ja va 2 s . c om*/ mob.put("cell_location", loc); } // Cell neighbors List<NeighboringCellInfo> ncl = tm.getNeighboringCellInfo(); if (ncl != null) { JSONArray cells = new JSONArray(); for (NeighboringCellInfo nc : ncl) { JSONObject jnc = new JSONObject(); jnc.put("cid", nc.getCid()); jnc.put("lac", nc.getLac()); jnc.put("network_type", nc.getNetworkType()); jnc.put("network_type_str", Helpers.getTelephonyNetworkType(nc.getNetworkType())); jnc.put("psc", nc.getPsc()); jnc.put("rssi", nc.getRssi()); cells.put(jnc); } mob.put("neigh_cells", cells); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { // only works for API level >=17 List<CellInfo> aci = (List<CellInfo>) tm.getAllCellInfo(); if (aci != null) { JSONArray cells = new JSONArray(); for (CellInfo ci : aci) { JSONObject jci = new JSONObject(); if (ci instanceof CellInfoGsm) { CellInfoGsm cigsm = (CellInfoGsm) ci; jci.put("is_registered", cigsm.isRegistered()); jci.put("type", "gsm"); jci.put("cid", cigsm.getCellIdentity().getCid()); jci.put("lac", cigsm.getCellIdentity().getLac()); jci.put("mcc", cigsm.getCellIdentity().getMcc()); jci.put("mnc", cigsm.getCellIdentity().getMnc()); jci.put("psc", cigsm.getCellIdentity().getPsc()); jci.put("asu_level", cigsm.getCellSignalStrength().getAsuLevel()); jci.put("level", cigsm.getCellSignalStrength().getLevel()); jci.put("dbm", cigsm.getCellSignalStrength().getDbm()); } else if (ci instanceof CellInfoCdma) { CellInfoCdma cicdma = (CellInfoCdma) ci; jci.put("is_registered", cicdma.isRegistered()); jci.put("type", "cdma"); jci.put("bs_id", cicdma.getCellIdentity().getBasestationId()); jci.put("bs_lat", cicdma.getCellIdentity().getLatitude()); jci.put("bs_lon", cicdma.getCellIdentity().getLongitude()); jci.put("net_id", cicdma.getCellIdentity().getNetworkId()); jci.put("sys_id", cicdma.getCellIdentity().getSystemId()); jci.put("asu_level", cicdma.getCellSignalStrength().getAsuLevel()); jci.put("dbm", cicdma.getCellSignalStrength().getDbm()); jci.put("level", cicdma.getCellSignalStrength().getLevel()); jci.put("cdma_dbm", cicdma.getCellSignalStrength().getCdmaDbm()); jci.put("cdma_ecio", cicdma.getCellSignalStrength().getCdmaEcio()); jci.put("cdma_level", cicdma.getCellSignalStrength().getCdmaLevel()); jci.put("evdo_dbm", cicdma.getCellSignalStrength().getEvdoDbm()); jci.put("evdo_ecio", cicdma.getCellSignalStrength().getEvdoEcio()); jci.put("evdo_level", cicdma.getCellSignalStrength().getEvdoLevel()); jci.put("evdo_snr", cicdma.getCellSignalStrength().getEvdoSnr()); } else if (ci instanceof CellInfoWcdma) { CellInfoWcdma ciwcdma = (CellInfoWcdma) ci; jci.put("is_registered", ciwcdma.isRegistered()); jci.put("type", "wcdma"); jci.put("cid", ciwcdma.getCellIdentity().getCid()); jci.put("lac", ciwcdma.getCellIdentity().getLac()); jci.put("mcc", ciwcdma.getCellIdentity().getMcc()); jci.put("mnc", ciwcdma.getCellIdentity().getMnc()); jci.put("psc", ciwcdma.getCellIdentity().getPsc()); jci.put("asu_level", ciwcdma.getCellSignalStrength().getAsuLevel()); jci.put("dbm", ciwcdma.getCellSignalStrength().getDbm()); jci.put("level", ciwcdma.getCellSignalStrength().getLevel()); } else if (ci instanceof CellInfoLte) { CellInfoLte cilte = (CellInfoLte) ci; jci.put("is_registered", cilte.isRegistered()); jci.put("type", "lte"); jci.put("ci", cilte.getCellIdentity().getCi()); jci.put("mcc", cilte.getCellIdentity().getMcc()); jci.put("mnc", cilte.getCellIdentity().getMnc()); jci.put("pci", cilte.getCellIdentity().getPci()); jci.put("tac", cilte.getCellIdentity().getTac()); jci.put("asu_level", cilte.getCellSignalStrength().getAsuLevel()); jci.put("dbm", cilte.getCellSignalStrength().getDbm()); jci.put("level", cilte.getCellSignalStrength().getLevel()); jci.put("timing_adv", cilte.getCellSignalStrength().getTimingAdvance()); } cells.put(jci); } mob.put("all_cells", cells); } } return mob; }
From source file:com.nbplus.vbroadlauncher.BroadcastPushReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent == null) { return;/*from w w w .j a va 2s . com*/ } Intent pi; String action = intent.getAction(); if (PushConstants.ACTION_PUSH_STATUS_CHANGED.equals(action)) { LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } else if (PushConstants.ACTION_PUSH_MESSAGE_RECEIVED.equals(action)) { Log.d(TAG, "Receive.. broadcast ACTION_PUSH_MESSAGE_RECEIVED from push service. re-direct to activity!!!"); //TODO: iot ?. // int i = 0; // if (i == 0) { // return; // } PushMessageData data = null; try { data = (PushMessageData) intent.getParcelableExtra(PushConstants.EXTRA_PUSH_MESSAGE_DATA); if (data == null || StringUtils.isEmptyString(data.getPayload())) { Log.d(TAG, "empty push message string !!"); return; } } catch (Exception e) { e.printStackTrace(); return; } PushPayloadData payloadData = null; try { Gson gson = new GsonBuilder().create(); payloadData = gson.fromJson(data.getPayload(), new TypeToken<PushPayloadData>() { }.getType()); } catch (Exception e) { e.printStackTrace(); } if (payloadData == null) { Log.d(TAG, "empty push message data !!"); return; } String type = payloadData.getServiceType(); Log.d(TAG, "HANDLER_MESSAGE_PUSH_MESAGE_RECEIVED received type = " + type + ", messageId = " + payloadData.getMessageId()); payloadData.setAlertMessage(data.getAlert()); switch (type) { // case Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST: case Constants.PUSH_PAYLOAD_TYPE_NORMAL_BROADCAST: case Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST: TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); int callState = telephonyManager.getCallState(); boolean isOutdoor = LauncherSettings.getInstance(context).isOutdoorMode(); playNotificationAlarm(context, R.string.notification_broadcast_push); if (isOutdoor || callState == TelephonyManager.CALL_STATE_OFFHOOK) { // ? ? ?. Log.d(TAG, "Broadcast notification.. isOutdoor mode... "); pi = new Intent(); pi.setAction(action); pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, intent.getIntExtra( PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED)); pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData); LocalBroadcastManager.getInstance(context).sendBroadcast(pi); return; } if (Constants.OPEN_BETA_PHONE) { String activePackageName = PackageUtils.getActivePackage(context); if (activePackageName != null && !StringUtils.isEmptyString(activePackageName)) { if (Constants.VBROAD_SEND_APP_PACKAGE.equals(activePackageName)) { Log.d(TAG, Constants.VBROAD_SEND_APP_PACKAGE + " is top running application...."); pi = new Intent(); pi.setAction(action); pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, intent.getIntExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED)); pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData); LocalBroadcastManager.getInstance(context).sendBroadcast(pi); return; } } } // ?? ?. ? Domain url ?? . if (PackageUtils.isActivePackage(context, Constants.GOOGLE_CHROME_PACKAGE_NAME)) { Log.d(TAG, "chrome browser is active...."); // get the last visited URL from the Browser.BOOKMARKS_URI database String url = ""; Uri chromeUri = Uri.parse("content://com.android.chrome.browser/bookmarks"); Cursor cur = context.getContentResolver().query(chromeUri/*Browser.BOOKMARKS_URI*/, new String[] { Browser.BookmarkColumns.URL }, null, null, Browser.BookmarkColumns.DATE + " DESC"); if (cur != null && cur.getCount() > 0) { cur.moveToFirst(); url = cur.getString(cur.getColumnIndex(Browser.BookmarkColumns.URL)); cur.close(); } else { if (cur != null) { cur.close(); } } Log.d(TAG, "Last activated url = " + url); if (!StringUtils.isEmptyString(url) && (url.startsWith(Constants.VBROAD_HTTP_DOMAIN) || url.startsWith(Constants.VBROAD_HTTPS_DOMAIN))) { Log.w(TAG, ">> Village broadcast is running... do not show!!!!"); pi = new Intent(); pi.setAction(action); pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, intent.getIntExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED)); pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData); LocalBroadcastManager.getInstance(context).sendBroadcast(pi); return; } } // android version check. if (Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST.equals(type) || Constants.PUSH_PAYLOAD_TYPE_NORMAL_BROADCAST.equals(type)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Log.d(TAG, ">> This device version code = " + Build.VERSION.SDK_INT + ", not supported version !!"); Toast.makeText(context, R.string.notification_broadcast_not_support, Toast.LENGTH_SHORT); pi = new Intent(); pi.setAction(action); pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, intent.getIntExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED)); pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData); LocalBroadcastManager.getInstance(context).sendBroadcast(pi); break; } } /*boolean useServiceChatHead = false; if (useServiceChatHead) { i = new Intent(context, RealtimeBroadcastProxyActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setAction(action); i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData); context.startActivity(i); } else*/ String playingType = LauncherSettings.getInstance(context).getCurrentPlayingBroadcastType(); if (StringUtils.isEmptyString(playingType) || !Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST.equals(playingType)) { // ??? ... ? . ??? pi = new Intent(context, RealtimeBroadcastActivity.class); pi.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); pi.setAction(action); pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData); pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, System.currentTimeMillis()); Log.d(TAG, "1. sendBroadcast() >> ACTION_PUSH_MESSAGE_RECEIVED : idx = " + pi.getLongExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, -1)); // ? ms ? ?? ? ? ? ???? // broadcast ? . // ?? ?? ??. //LocalBroadcastManager.getInstance(context).sendBroadcast(pi); try { //Thread.sleep(30); context.startActivity(pi); } catch (Exception e) { e.printStackTrace(); } } else { // ?? ? ??... ? ?.. ? . if (Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST.equals(playingType) && Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST.equals(type)) { pi = new Intent(context, RealtimeBroadcastActivity.class); pi.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); pi.setAction(action); pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData); pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, System.currentTimeMillis()); Log.d(TAG, "2. sendBroadcast() >> ACTION_PUSH_MESSAGE_RECEIVED : idx = " + pi.getLongExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, -1)); // ? ms ? ?? ? ? ? ???? // broadcast ? . // ?? ?? ??. //LocalBroadcastManager.getInstance(context).sendBroadcast(pi); try { //Thread.sleep(30); context.startActivity(pi); } catch (Exception e) { e.printStackTrace(); } } else { // ? ? ? ??. Log.d(TAG, "? ? ? ??."); Toast.makeText(context, payloadData.getAlertMessage(), Toast.LENGTH_SHORT).show(); } } break; // case Constants.PUSH_PAYLOAD_TYPE_EMERGENCY_CALL: break; // case Constants.PUSH_PAYLOAD_TYPE_INHABITANTS_POLL: // ? case Constants.PUSH_PAYLOAD_TYPE_COOPERATIVE_BUYING: int strId = Constants.PUSH_PAYLOAD_TYPE_INHABITANTS_POLL.equals(payloadData.getServiceType()) ? R.string.notification_inhabitant_push : R.string.notification_cooperative_buying_push; playNotificationAlarm(context, strId); pi = new Intent(); pi.setAction(action); pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, intent.getIntExtra( PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED)); pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData); Log.d(TAG, "3. sendBroadcast() >> ACTION_PUSH_MESSAGE_RECEIVED : idx = " + 0); LocalBroadcastManager.getInstance(context).sendBroadcast(pi); break; // IOT DEVICE ( ) case Constants.PUSH_PAYLOAD_TYPE_IOT_DEVICE_CONTROL: Log.d(TAG, "startService >> ACTION_SEND_IOT_COMMAND"); IoTInterface.getInstance().controlDevice(payloadData.getIotControlDeviceId(), payloadData.getMessage()); break; // PUSH_PAYLOAD_TYPE_PUSH_NOTIFICATION case Constants.PUSH_PAYLOAD_TYPE_PUSH_NOTIFICATION: // ?... // pi = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(payloadData.getMessage())); // showNotification(context, Constants.SYSTEM_ADMIN_NOTIFICATION_ID, PackageUtils.getApplicationName(context), payloadData.getAlertMessage(), null, pi); // bigText showNotification(context, Constants.SYSTEM_ADMIN_NOTIFICATION_ID, PackageUtils.getApplicationName(context), payloadData.getAlertMessage(), PackageUtils.getApplicationName(context), payloadData.getMessage(), null, null, null); break; // IOT DEVICE ( ) case Constants.PUSH_PAYLOAD_TYPE_FIND_PASSWORD: pi = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(payloadData.getMessage())); showNotification(context, Constants.PW_FIND_NOTIFICATION_ID, PackageUtils.getApplicationName(context), payloadData.getAlertMessage(), null, pi); break; default: Log.d(TAG, "Unknown push payload type !!!"); break; } } }
From source file:com.mindprotectionkit.freephone.RedPhoneService.java
private boolean isBusy() { TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); return ((currentCallManager != null && state != RedPhone.STATE_IDLE) || telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE); }
From source file:com.googlecode.mindbell.accessors.ContextAccessor.java
public boolean isPhoneOffHook() { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE; }