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:com.example.hbranciforte.trafficclient.History.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);
    DefaultHttpClient httpclient = new DefaultHttpClient();
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String token = telephonyManager.getDeviceId().toString();
    //HttpPost httppostreq = new HttpPost("http://10.0.2.2:3000/parkings??notification_token=".concat(token));
    ListView listView = (ListView) findViewById(R.id.historyable);

    try {/*from   w  w w.  ja  v a 2 s .  co m*/
        HttpClient client = new DefaultHttpClient();
        String getURL = "http://45.55.79.197/parkings?notification_token=".concat(token);
        //String getURL = "http://10.0.2.2:3000/parkings?notification_token=".concat(token);
        HttpGet get = new HttpGet(getURL);
        HttpResponse responseGet = client.execute(get);
        HttpEntity resEntityGet = responseGet.getEntity();
        if (resEntityGet != null) {
            String response = EntityUtils.toString(resEntityGet);
            data = new JSONArray(response);

            String[] values = new String[data.length()];
            for (int i = 0; i < this.data.length(); i++) {
                JSONObject parking = new JSONObject(data.get(i).toString());
                JSONObject zone = new JSONObject(parking.getString("zone"));
                JSONObject car = new JSONObject(parking.getString("car"));
                String temp = "Patente: ".concat(car.getString("license_plate")).concat("\n");
                temp = temp.concat("Zona: ").concat(zone.getString("name")).concat("-")
                        .concat(Integer.toString(zone.getInt("number")).concat("\n"));
                temp = temp.concat("Estado: ").concat(parking.getString("status")).concat("\n");
                values[i] = temp.concat("Valido hasta: ").concat(parking.getString("formated_expires_at"));

            }
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                    android.R.id.text1, values);
            listView.setAdapter(adapter);
        }
    } catch (Exception e) {
        Log.e("Error Parsing:", e.getMessage());
    }

}

From source file:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}

From source file:Main.java

public boolean isNetworkRoaming(Context mCm) {
    ConnectivityManager connectivity = (ConnectivityManager) mCm.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return false;
    }/* w  w  w.  j a v  a2  s .  c  om*/
    NetworkInfo info = connectivity.getActiveNetworkInfo();
    boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
    TelephonyManager mTm = (TelephonyManager) mCm.getSystemService(Context.TELEPHONY_SERVICE);
    boolean isRoaming = isMobile && mTm.isNetworkRoaming();
    return isRoaming;
}

From source file:Main.java

/**
 * Uses the telephony manager to understand if the client is running on a
 * simulator or a real device. On the simulator the device id is a 15 chars
 * long 0 sequence (os < 2.1)./*from w  ww.j av  a2 s .c o m*/
 * @param context the application Context
 * @return true if the device id is a 0s sequence, false otherwise.
 */
public static boolean isSimulator(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = tm.getDeviceId();
    return "000000000000000".equals(deviceId);
}

From source file:com.neuron.fantecremote.PhoneIntentReciever.java

@Override
public void onReceive(Context context, Intent intent) {
    MyPhoneStateListener phoneListener = new MyPhoneStateListener(
            context.getSharedPreferences("fantecremote", 0));
    TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}

From source file:fr.inria.ucn.listeners.MyPhoneStateListener.java

/**
 * // w w w .  j  a v a  2 s .  c  o m
 * @param c
 */
public void enable(Context c) {
    TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
        tm.listen(this,
                PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
        this.c = c;
    } // else no telephony
}

From source file:com.nextgis.maplib.util.NetworkUtil.java

public NetworkUtil(Context context) {
    mConnectionManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
}

From source file:de.inhji.cordova.plugin.Telephony.java

public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    context = this.cordova.getActivity().getApplicationContext();
    tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    listener = new MyPhoneStateListener();
    tm.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

    Log.i(TAG, "Starting PhoneStateListener..");
}

From source file:local.plugin.phonecheck.PhoneCheck.java

private String check() {
    String response;/*  ww  w .  ja va  2  s  .  c  om*/
    try {
        if (((TelephonyManager) this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE))
                .getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
            response = "IMPOSSIBLE";
        } else {
            response = "CANCALL";
        }
    } catch (Exception e) {
        response = "UNKNOWN";
    }

    return response;
}

From source file:com.smithleedon.device.MyPhoneNumber.java

private void initTelephonyReceiver() {
    mGap = this.cordova;
    TelephonyManager mTelephonyMgr = (TelephonyManager) mGap.getActivity()
            .getSystemService(Context.TELEPHONY_SERVICE);
    strPhoneNumber = mTelephonyMgr.getLine1Number();
    strPhoneNumber = strPhoneNumber.replace("-", "").replace("+82", "0");
}