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:org.ubicompforall.BusTUC.Queries.Browser.java

public String getRequestServer(String stop, Boolean formated, Location location, int numStops, int dist,
        Context context) {/*from w  w  w  .  j  ava  2  s . c o  m*/
    String html_string = null;
    HttpGet m_get = new HttpGet();
    try {
        stop = URLEncoder.encode(stop, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // HttpPost m_post= new
    // HttpPost("http://m.atb.no/xmlhttprequest.php?service=routeplannerOracle.getOracleAnswer&question=");
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String t_id = tm.getDeviceId();
        String tmp = "TABuss";
        String p_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        m_get.setURI(new URI("http://busstjener.idi.ntnu.no/MultiBRISserver/MBServlet?dest=" + stop + "&lat="
                + location.getLatitude() + "&long=" + location.getLongitude() + "&type=json&nStops=" + numStops
                + "&maxWalkDist=" + dist + "&key=" + tmp + p_id));
        HttpResponse m_response = m_client.execute(m_get);
        // Request
        html_string = httpF.requestServer(m_response);
        // Will fail if server is busy or down
        Log.v("html_string", "Returned html: " + html_string);
        // Long newTime = System.nanoTime() - time;
        // System.out.println("TIMEEEEEEEEEEEEEEEEEEEEE: " +
        // newTime/1000000000.0);
    } catch (ClientProtocolException e) {
        Log.v("CLIENTPROTOCOL EX", "e:" + e.toString());
    } catch (IOException e) {
        Log.v("IO EX", "e:" + e.toString());

    } catch (NullPointerException e) {
        Log.v("NULL", "NullPointer");
    } catch (StringIndexOutOfBoundsException e) {
        Log.v("StringIndexOutOfBounds", "Exception");
    } catch (Exception e) {
        e.printStackTrace();
    }

    return html_string;
}

From source file:de.mangelow.throughput.NotificationService.java

@Override
public void onCreate() {
    super.onCreate();
    if (D)//from  w ww.j a  v a  2  s .c o m
        Log.d(TAG, "Service started");

    context = getApplicationContext();
    res = context.getResources();

    if (tmanager == null) {
        tmanager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        tmanager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(mBroadcastReceiver, filter);

    int[] refresh_values = res.getIntArray(R.array.refresh_values);
    long refresh = (long) refresh_values[MainActivity.loadIntPref(context, MainActivity.REFRESH,
            MainActivity.REFRESH_DEFAULT)];

    modifyNotification(R.drawable.ic_stat_zero, null, "", "", new Intent());

    if (handler == null) {
        handler = new Handler();
        handler.postDelayed(mRunnable, refresh);
    }

}

From source file:org.ubicompforall.BusTUC.Speech.HTTP.java

public CBRAnswer getCBRGuess(double lat, double lon, Context context) {
    HttpClient client = new DefaultHttpClient();
    String response = "";
    CBRAnswer answ = null;/*from ww  w  . j ava 2 s  . c om*/
    Calculate calc = null;
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String t_id = tm.getDeviceId();
        String tmp = "TABuss";
        String p_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        HttpGet httpget = new HttpGet("http://vm-6114.idi.ntnu.no:1337/SpeechServer/cbrGuess?lat=" + lat
                + "&lon=" + lon + "&devID=" + tmp + p_id);
        long first = System.nanoTime();
        response = EntityUtils.toString(client.execute(httpget).getEntity(), "UTF-8");
        calc = new Calculate();
        System.out.println("RESPONSE: " + response);
        answ = calc.createCBRAnswer(response);

    } catch (Exception e) {
        e.printStackTrace();
    }
    return answ;

}

From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ESUP_NFC_TAG_SERVER_URL = getEsupNfcTagServerUrl(getApplicationContext());
    //To keep session for desfire async requests
    CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
    LocalStorage.getInstance(getApplicationContext());
    Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(getApplicationContext()));
    setContentView(R.layout.activity_main);
    mAdapter = NfcAdapter.getDefaultAdapter(this);
    checkHardware(mAdapter);/*from   ww  w . j  a  v  a2  s .  com*/
    localStorageDBHelper = LocalStorage.getInstance(this.getApplicationContext());
    String numeroId = localStorageDBHelper.getValue("numeroId");
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String imei = telephonyManager.getDeviceId();
    url = ESUP_NFC_TAG_SERVER_URL + "/nfc-index?numeroId=" + numeroId + "&imei=" + imei + "&macAddress="
            + getMacAddr() + "&apkVersion=" + getApkVersion();
    view = (WebView) this.findViewById(R.id.webView);
    view.clearCache(true);
    view.addJavascriptInterface(new LocalStorageJavaScriptInterface(this.getApplicationContext()),
            "AndroidLocalStorage");
    view.addJavascriptInterface(new AndroidJavaScriptInterface(this.getApplicationContext()), "Android");

    view.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int progress) {
            if (progress == 100) {
                AUTH_TYPE = localStorageDBHelper.getValue("authType");
            }
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            log.info("Webview console message : " + consoleMessage.message());
            return false;
        }

    });

    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            view.reload();
            return true;
        }
    });
    view.getSettings().setAllowContentAccess(true);
    WebSettings webSettings = view.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(this.getFilesDir().getParentFile().getPath() + "/databases/");

    view.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }

    });

    view.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
        }
    });

    view.loadUrl(url);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

From source file:com.phonegap.Device.java

public String getSubscriberId() {
    TelephonyManager operator = (TelephonyManager) this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return operator.getSubscriberId();
}

From source file:count.ly.messaging.DeviceInfo.java

/**
 * Returns the display name of the current network operator from the
 * TelephonyManager from the specified context.
 * @param context context to use to retrieve the TelephonyManager from
 * @return the display name of the current network operator, or the empty
 *         string if it cannot be accessed or determined
 *//*from   w  w  w .  java  2s  .  co  m*/
static String getCarrier(final Context context) {
    String carrier = "";
    final TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (manager != null) {
        carrier = manager.getNetworkOperatorName();
    }
    if (carrier == null || carrier.length() == 0) {
        carrier = "";
        if (Countly.sharedInstance().isLoggingEnabled()) {
            Log.i(Countly.TAG, "No carrier found");
        }
    }
    return carrier;
}

From source file:com.almende.demo.conferenceApp.ConferenceAgent.java

/**
 * Inits the./*from   w w w  .j  a  v a2s.c o  m*/
 * 
 * @param ctx
 *            the ctx
 */
public void init(Context ctx) {
    ConferenceAgent.ctx = ctx;
    final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    final AgentConfig config = new AgentConfig();
    config.setId(tm.getDeviceId());

    final FileStateConfig stateConfig = new FileStateConfig();
    stateConfig.setJson(true);
    stateConfig.setPath(ctx.getFilesDir().getAbsolutePath() + "/agentStates/");
    stateConfig.setId("conferenceAgent");

    config.setState(stateConfig);

    SimpleSchedulerConfig schedulerConfig = new SimpleSchedulerConfig();
    config.setScheduler(schedulerConfig);

    loadConfig(config);

    if (!getState().containsKey(CONTACTKEY.getKey())) {
        getState().put(CONTACTKEY.getKey(), new HashMap<String, Info>());
    }
    DetectionUtil.getInstance().startScan();
    getScheduler().schedule(this.getRpc().buildMsg("refresh", null, null), DateTime.now().plus(60000));

    reconnect();
}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

/**
*Returns the IMEI Number//w  w  w  .ja v  a  2 s.  com
*/
public String getDeviceId() {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    try {
        deviceId = tm.getDeviceId();
        if (deviceId == null || deviceId.length() == 0)
            deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return deviceId;
}

From source file:org.wso2.iot.agent.services.NetworkInfoService.java

@Override
public void onCreate() {
    thisInstance = this;
    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "Creating service");
    }/*from  w w w  .  j  a v a  2  s  . c  o m*/
    mapper = new ObjectMapper();
    info = getNetworkInfo();
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(deviceNetworkStatusListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (Constants.WIFI_SCANNING_ENABLED) {
        // Register broadcast receiver
        // Broadcast receiver will automatically call when number of wifi connections changed
        registerReceiver(wifiScanReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        // start scanning wifi
        startWifiScan();
    }
}

From source file:com.apptentive.android.sdk.storage.DeviceManager.java

private static Device generateNewDevice(Context context) {
    Device device = new Device();

    // First, get all the information we can load from static resources.
    device.setOsName("Android");
    device.setOsVersion(Build.VERSION.RELEASE);
    device.setOsBuild(Build.VERSION.INCREMENTAL);
    device.setOsApiLevel(String.valueOf(Build.VERSION.SDK_INT));
    device.setManufacturer(Build.MANUFACTURER);
    device.setModel(Build.MODEL);/*from   w  ww  . j a v a  2s. c  o m*/
    device.setBoard(Build.BOARD);
    device.setProduct(Build.PRODUCT);
    device.setBrand(Build.BRAND);
    device.setCpu(Build.CPU_ABI);
    device.setDevice(Build.DEVICE);
    device.setUuid(GlobalInfo.androidId);
    device.setBuildType(Build.TYPE);
    device.setBuildId(Build.ID);

    // Second, set the stuff that requires querying system services.
    TelephonyManager tm = ((TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)));
    device.setCarrier(tm.getSimOperatorName());
    device.setCurrentCarrier(tm.getNetworkOperatorName());
    device.setNetworkType(Constants.networkTypeAsString(tm.getNetworkType()));

    // Finally, use reflection to try loading from APIs that are not available on all Android versions.
    device.setBootloaderVersion(Reflection.getBootloaderVersion());
    device.setRadioVersion(Reflection.getRadioVersion());

    device.setLocaleCountryCode(Locale.getDefault().getCountry());
    device.setLocaleLanguageCode(Locale.getDefault().getLanguage());
    device.setLocaleRaw(Locale.getDefault().toString());
    device.setUtcOffset(String.valueOf((TimeZone.getDefault().getRawOffset() / 1000)));
    return device;
}