Example usage for android.content Context TELEPHONY_SERVICE

List of usage examples for android.content Context TELEPHONY_SERVICE

Introduction

In this page you can find the example usage for android.content Context TELEPHONY_SERVICE.

Prototype

String TELEPHONY_SERVICE

To view the source code for android.content Context TELEPHONY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device.

Usage

From source file:at.alladin.rmbt.android.util.InformationCollector.java

/**
 * Lazily initializes the network managers.
 * /*www .  j a  va  2  s. co  m*/
 * As a side effect, assigns connectivityManager and telephonyManager.
 */
private synchronized void initNetwork() {
    if (connManager == null) {
        final ConnectivityManager tryConnectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        final TelephonyManager tryTelephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);

        final WifiManager tryWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

        // Assign to member vars only after all the get calls succeeded,

        connManager = tryConnectivityManager;
        telManager = tryTelephonyManager;
        wifiManager = tryWifiManager;

        if (Build.VERSION.SDK_INT >= 18) {
            telManagerSupport = new TelephonyManagerV18(telManager);
        } else {
            telManagerSupport = new TelephonyManagerPreV18(telManager);
        }

        // Some interesting info to look at in the logs
        //final NetworkInfo[] infos = connManager.getAllNetworkInfo();
        //for (final NetworkInfo networkInfo : infos)
        //    Log.i(DEBUG_TAG, "Network: " + networkInfo);
    }
    assert connManager != null;
    assert telManager != null;
    assert wifiManager != null;
}

From source file:RhodesService.java

public static Object getProperty(String name) {
    try {/*  w w w .  j  a v a  2 s .  co  m*/
        if (name.equalsIgnoreCase("platform"))
            return "ANDROID";
        else if (name.equalsIgnoreCase("locale"))
            return getCurrentLocale();
        else if (name.equalsIgnoreCase("country"))
            return getCurrentCountry();
        else if (name.equalsIgnoreCase("screen_width"))
            return Integer.valueOf(getScreenWidth());
        else if (name.equalsIgnoreCase("screen_height"))
            return Integer.valueOf(getScreenHeight());
        else if (name.equalsIgnoreCase("screen_orientation")) {
            int orientation = getScreenOrientation();
            if ((orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
                    || (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE))
                return "landscape";
            else
                return "portrait";
        } else if (name.equalsIgnoreCase("has_network"))
            return Boolean.valueOf(hasNetwork());
        else if (name.equalsIgnoreCase("has_wifi_network"))
            return Boolean.valueOf(hasWiFiNetwork());
        else if (name.equalsIgnoreCase("has_cell_network"))
            return Boolean.valueOf(hasCellNetwork());
        else if (name.equalsIgnoreCase("ppi_x"))
            return Float.valueOf(getScreenPpiX());
        else if (name.equalsIgnoreCase("ppi_y"))
            return Float.valueOf(getScreenPpiY());
        else if (name.equalsIgnoreCase("phone_number")) {
            Context context = ContextFactory.getContext();
            String number = "";
            if (context != null) {
                TelephonyManager manager = (TelephonyManager) context
                        .getSystemService(Context.TELEPHONY_SERVICE);
                number = manager.getLine1Number();
                Logger.I(TAG, "Phone number: " + number + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
            }
            return number;
        } else if (name.equalsIgnoreCase("device_owner_name")) {
            return AndroidFunctionalityManager.getAndroidFunctionality()
                    .AccessOwnerInfo_getUsername(getContext());
        } else if (name.equalsIgnoreCase("device_owner_email")) {
            return AndroidFunctionalityManager.getAndroidFunctionality().AccessOwnerInfo_getEmail(getContext());
        } else if (name.equalsIgnoreCase("device_name")) {
            return Build.MANUFACTURER + " " + Build.DEVICE;
        } else if (name.equalsIgnoreCase("is_emulator")) {
            String strDevice = Build.DEVICE;
            return Boolean.valueOf(strDevice != null && strDevice.equalsIgnoreCase("generic"));
        } else if (name.equalsIgnoreCase("os_version")) {
            return Build.VERSION.RELEASE;
        } else if (name.equalsIgnoreCase("has_calendar")) {
            return Boolean.valueOf(EventStore.hasCalendar());
        } else if (name.equalsIgnoreCase("phone_id")) {
            RhodesService service = RhodesService.getInstance();
            if (service != null) {
                PhoneId phoneId = service.getPhoneId();
                return phoneId.toString();
            } else {
                return "";
            }
        } else if (name.equalsIgnoreCase("webview_framework")) {
            return RhodesActivity.safeGetInstance().getMainView().getWebView(-1).getEngineId();
        } else if (name.equalsIgnoreCase("is_motorola_device")) {
            return isMotorolaDevice();
        } else if (name.equalsIgnoreCase("oem_info")) {
            return Build.PRODUCT;
        } else if (name.equalsIgnoreCase("uuid")) {
            return fetchUUID();
        } else if (name.equalsIgnoreCase("has_camera")) {
            return Boolean.TRUE;
        } else {
            return RhoExtManager.getImplementationInstance().getProperty(name);
        }
    } catch (Exception e) {
        Logger.E(TAG, "Can't get property \"" + name + "\": " + e);
    }

    return null;
}

From source file:com.prey.net.PreyWebServices.java

public PreyHttpResponse registerNewDeviceRemote(Context ctx, String mail, String notificationId,
        String deviceType) throws PreyException {
    PreyConfig preyConfig = PreyConfig.getPreyConfig(ctx);

    String model = Build.MODEL;//from   www .  j  a  v a2  s. c o  m
    String vendor = "Google";
    if (!PreyConfig.getPreyConfig(ctx).isCupcakeOrAbove())
        vendor = AboveCupcakeSupport.getDeviceVendor();

    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("device[notification_id]", notificationId);
    parameters.put("device[remote_email]", mail);
    parameters.put("device[title]", vendor + " " + model);
    parameters.put("device[device_type]", deviceType);
    parameters.put("device[os]", "Android");
    parameters.put("device[os_version]", Build.VERSION.RELEASE);
    parameters.put("device[referer_device_id]", "");
    parameters.put("device[plan]", "free");
    parameters.put("device[activation_phrase]", preyConfig.getSmsToRun());
    parameters.put("device[deactivation_phrase]", preyConfig.getSmsToStop());
    parameters.put("device[model_name]", model);
    parameters.put("device[vendor_name]", vendor);

    parameters = increaseData(ctx, parameters);
    TelephonyManager mTelephonyMgr = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = mTelephonyMgr.getDeviceId();
    parameters.put("device[physical_address]", imei);

    PreyHttpResponse response = null;
    try {
        String url = "https://panel.preyapp.com/api/v2/remote.json";
        response = PreyRestHttpClient.getInstance(ctx).post(url, parameters);
    } catch (IOException e) {
        throw new PreyException(ctx.getText(R.string.error_communication_exception).toString(), e);
    }

    return response;
}

From source file:org.linphone.LinphoneService.java

void addCallListner() {

    mIncomingCallReceiver = new IncomingCallReceiver();

    IntentFilter mIntentFilter = new IntentFilter();
    // /*w  ww  .  j  a  va 2s .c o m*/
    mIntentFilter.addAction("android.intent.action.PHONE_STATE");
    mIntentFilter.setPriority(1000);
    // 
    //      mIntentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
    // BroadcastReceiver
    registerReceiver(mIncomingCallReceiver, mIntentFilter);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    // endcall
    TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    try {
        Method getITelephonyMethod = TelephonyManager.class.getDeclaredMethod("getITelephony", (Class[]) null);
        getITelephonyMethod.setAccessible(true);
        //       mITelephony = (ITelephony)
        getITelephonyMethod.invoke(mTelephonyManager, (Object[]) null);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.hfoss.posit.android.sync.Communicator.java

public static boolean recordSync(Context context, String authKey) {
    // Record the synchronization in the server's sync_history table

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String server = prefs.getString(SERVER_PREF, "");
    int projectId = prefs.getInt(context.getString(R.string.projectPref), 0);

    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = telephonyManager.getDeviceId();

    String url = server + "/api/recordSync?authKey=" + authKey + "&imei=" + imei + "&projectId=" + projectId;
    Log.i(TAG, "recordSync URL=" + url);
    String responseString = "";

    try {/*from  w w w .j  a v a2  s. c  o m*/
        responseString = doHTTPGET(url);
    } catch (Exception e) {
        Log.i(TAG, e.getMessage());
        e.printStackTrace();
        return false;
    }
    Log.i(TAG, "HTTPGet recordSync response = " + responseString);
    return true;
}

From source file:org.hfoss.posit.android.sync.Communicator.java

public static boolean sendFind(Find find, Context context, String authToken) {
    String url = "";
    boolean success = false;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String server = prefs.getString(SERVER_PREF, "");

    if (find.getAction().equals(FindHistory.ACTION_CREATE))
        url = server + "/api/createFind?authKey=" + authToken;
    else if (find.getAction().equals(FindHistory.ACTION_UPDATE))
        url = server + "/api/updateFind?authKey=" + authToken;
    else {/*from  w  ww  .j a  va  2 s. co  m*/
        Log.e(TAG, "Find object does not contain an appropriate action: " + find);
        return false;
    }

    Log.i(TAG, "SendFind=" + find);

    List<NameValuePair> pairs = getNameValuePairs(find);

    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = telephonyManager.getDeviceId();

    BasicNameValuePair pair = new BasicNameValuePair("imei", imei);
    pairs.add(pair);
    Log.i(TAG, "pairs: " + pairs);
    String responseString = null;

    // Send the find
    try {
        responseString = doHTTPPost(url, pairs);
        DbHelper.getDbManager(context).updateStatus(find, Constants.TRANSACTING);
        DbHelper.getDbManager(context).updateSyncOperation(find, Constants.POSTING);
    } catch (Exception e) {
        Log.i(TAG, e.getMessage());
        Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
        DbHelper.getDbManager(context).updateStatus(find, Constants.FAILED);
        success = false;
    }

    Log.i(TAG, "sendFind.ResponseString: " + responseString);

    // If the update failed return false
    if (responseString.indexOf("True") == -1) {
        Log.i(TAG, "sendFind result doesn't contain 'True'");
        DbHelper.getDbManager(context).updateStatus(find, Constants.FAILED);
        success = false;
    } else {
        DbHelper.getDbManager(context).updateStatus(find, Constants.SUCCEEDED);
        Log.i(TAG, "sendFind() synced find id: " + find.getId());
        success = true;
    }

    if (!success) {
        //don't bother sending the images if we can't save the find
        return false;
    }

    //Check if the image is out of sync and needs to be sent
    if (Camera.isPhotoSynced(find, context) == false) {
        //We have an image to send!
        //Get the image string
        String fullPicStr = Camera.getPhotoAsString(find.getGuid(), context);
        //Get the thumbnail version of it too
        String thumbPicStr = Camera.getPhotoThumbAsString(find.getGuid(), context);
        //fill in the data needed to send to the photo table
        HashMap<String, String> sendMap = new HashMap<String, String>();
        sendMap.put(COLUMN_IMEI, imei);
        sendMap.put(COLUMN_GUID, find.getGuid());
        sendMap.put(COLUMN_IDENTIFIER, Integer.toString(find.getId()));
        sendMap.put(COLUMN_PROJECT_ID, Integer.toString(find.getProject_id()));
        //          sendMap.put("COLUMN_TIMESTAMP",find.getTime()); //uses current timestamp if not set
        //          sendMap.put("mine_type",imageData.getAsString(PositDbHelper.PHOTOS_MIME_TYPE));      
        sendMap.put(COLUMN_MIME_TYPE, "image/jpeg");
        sendMap.put(COLUMN_DATA_FULL, fullPicStr);
        sendMap.put(COLUMN_DATA_THUMBNAIL, thumbPicStr);

        //ready to send the image to the server
        sendMedia(sendMap, context);
    }

    DbHelper.releaseDbManager();
    return success;
}

From source file:net.kidlogger.kidlogger.KLService.java

public void runRoamingEvent() {
    new Thread(new Runnable() {
        public void run() {
            TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            try {
                String country = tm.getNetworkCountryIso();
                String operator = tm.getNetworkOperatorName();
                sync.writeLog(".htm", Templates.getRoamingInfo(country.toUpperCase(Locale.US), operator));
            } catch (Exception e) {
                app.logError(CN + "runRoamingEvent", e.toString());
            }//from w w  w .j  a v a2s .co m
        }
    }).start();
}

From source file:edu.polyu.screamalert.SoundProcessing.java

private static void sendSMS() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Exchanger.thisContext);
    Boolean enableSMS = prefs.getBoolean("enableSMS", false);
    String phoneNumber = prefs.getString("phoneNumber", null);
    TelephonyManager phoneMgr = (TelephonyManager) thisContext.getSystemService(Context.TELEPHONY_SERVICE);
    if (enableSMS == true && phoneNumber != null && phoneNumber.trim().length() > 0
            && phoneMgr.getSimState() != TelephonyManager.SIM_STATE_ABSENT) {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNumber, null, "Scream detected. Longitude: " + gps.getLongitude()
                + "; Latitude: " + gps.getLatitude() + ". Please try to contact the mobile user", null, null);
    }// www . j av  a  2  s  . c om
}

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);
            }//w ww.ja  v a 2  s.  c o  m
        }
    }
}