Java Code Examples for android.telephony.TelephonyManager

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android-tether, under directory /src/og/android/tether/.

Source file: TetherApplication.java

  24 
vote

public boolean isPhone(){
  TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
switch (tm.getPhoneType()) {
case TelephonyManager.PHONE_TYPE_NONE:
    return false;
case TelephonyManager.PHONE_TYPE_GSM:
case TelephonyManager.PHONE_TYPE_CDMA:
default :
  return true;
}
}
 

Example 2

From project lastfm-android, under directory /app/src/fm/last/android/widget/.

Source file: AdArea.java

  24 
vote

public static boolean adsEnabled(Context context){
  Session session=LastFMApplication.getInstance().session;
  if (session == null || session.getSubscriber().equals("1")) {
    return false;
  }
  TelephonyManager tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  if (!tm.getNetworkCountryIso().equals("us")) {
    return false;
  }
  return getAdInfo();
}
 

Example 3

From project BazaarUtils, under directory /src/com/congenialmobile/adad/.

Source file: AdsManager.java

  23 
vote

/** 
 * Prepare the data that should be sent to the server. The returned string
 * @return The string ready to be appended to the URL for passing data by GET method.
 */
private String prepareData(){
  TelephonyManager tm=(TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
  String s=null;
  s="deviceid=" + mUUID;
  s+="&androidid=" + Secure.getString(mContext.getContentResolver(),Secure.ANDROID_ID);
  s+="&token=" + mToken;
  s+="&brand=" + URLEncoder.encode(Build.BRAND);
  s+="&model=" + URLEncoder.encode(Build.MODEL);
  s+="&width=" + mWidth;
  s+="&height=" + mHeight;
  s+="&density=" + mDensity;
  s+="&car=" + URLEncoder.encode(tm.getNetworkOperator());
  s+="&data=";
  if (tm.getDataState() == TelephonyManager.DATA_CONNECTED) {
    s+="1";
  }
 else {
    s+="0";
  }
  s+="&lang=" + Locale.getDefault().getLanguage();
  return s;
}
 

Example 4

From project creamed_glacier_app_settings, under directory /src/com/android/settings/.

Source file: DataUsageSummary.java

  23 
vote

/** 
 * Test if device has a mobile 4G data radio.
 */
private static boolean hasMobile4gRadio(Context context){
  if (!NetworkPolicyEditor.ENABLE_SPLIT_POLICIES) {
    return false;
  }
  if (TEST_RADIOS) {
    return SystemProperties.get(TEST_RADIOS_PROP).contains("4g");
  }
  final ConnectivityManager conn=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  final TelephonyManager telephony=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  final boolean hasWimax=conn.isNetworkSupported(TYPE_WIMAX);
  final boolean hasLte=telephony.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE;
  return hasWimax || hasLte;
}
 

Example 5

From project android-joedayz, under directory /Proyectos/TaxiLab6/src/pe/joedayz/samples/.

Source file: GridReserva.java

  22 
vote

private void call(String telefono){
  try {
    Intent callIntent=new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + telefono));
    startActivity(callIntent);
    TelephonyManager tManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    listener=new ListenToPhoneState();
    tManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);
  }
 catch (  ActivityNotFoundException activityException) {
    Log.e("telephony-example","Call failed",activityException);
  }
}
 

Example 6

From project androidquery, under directory /demo/src/com/androidquery/test/.

Source file: TestUtility.java

  22 
vote

public static String getDeviceId(Context context){
  if (deviceId == null) {
    TelephonyManager tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    String tmDevice, tmSerial, tmPhone, androidId;
    tmDevice="" + tm.getDeviceId();
    tmSerial="" + tm.getSimSerialNumber();
    androidId="" + android.provider.Settings.Secure.getString(context.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);
    UUID deviceUuid=new UUID(androidId.hashCode(),((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
    deviceId=deviceUuid.toString();
    System.err.println(deviceId);
  }
  return deviceId;
}
 

Example 7

From project beintoo-android-sdk, under directory /BeintooSDK/src/com/beintoo/beintoosdkutility/.

Source file: DeviceId.java

  22 
vote

public static String getImei(Context context){
  String imei=null;
  try {
    PackageManager pm=context.getPackageManager();
    if (PackageManager.PERMISSION_GRANTED == pm.checkPermission(Manifest.permission.READ_PHONE_STATE,context.getPackageName())) {
      final TelephonyManager tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
      imei=tm.getDeviceId();
    }
  }
 catch (  Exception e) {
    return null;
  }
  return imei;
}
 

Example 8

From project CHMI, under directory /src/org/kaldax/app/chmi/.

Source file: CHMI.java

  22 
vote

private boolean anyNetworkActive(){
  TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  WifiManager wm=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  WifiInfo wi=wm.getConnectionInfo();
  return !((wi == null || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.IDLE) && tm.getDataState() != TelephonyManager.DATA_CONNECTED);
}
 

Example 9

From project Common-Sense-Net-2, under directory /RealFarm/src/com/commonsensenet/realfarm/.

Source file: RealFarmApp.java

  22 
vote

/** 
 * Gets the DeviceId from the Telephony Manager. If the value is not available a default value is set.
 * @return the current DeviceId
 */
public String getDeviceId(){
  if (mDeviceId == null || mDeviceId.equals("")) {
    TelephonyManager telephonyManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    mDeviceId=telephonyManager.getDeviceId();
    if (mDeviceId == null || mDeviceId.equals("")) {
      mDeviceId=RealFarmDatabase.DEFAULT_DEVICE_ID;
    }
  }
  return mDeviceId;
}
 

Example 10

From project FlipDroid, under directory /app/src/com/goal98/flipdroid2/model/taobao/.

Source file: TaobaoArticleSource.java

  22 
vote

public TaobaoArticleSource(String query,Context context){
  TelephonyManager telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  String imei=telephonyManager.getDeviceId();
  String imsi=telephonyManager.getSubscriberId();
  OpenServiceClient.init(Taobao.TAOBAOURI,Taobao.APPKEY,Taobao.APPSERECT,context,Taobao.TTID,imei,imsi);
  this.query=query;
}
 

Example 11

From project framework_base_policy, under directory /src/com/android/internal/policy/impl/.

Source file: GlobalActions.java

  22 
vote

/** 
 * @param context everything needs a context :(
 */
public GlobalActions(Context context){
  mContext=context;
  mAudioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  IntentFilter filter=new IntentFilter();
  filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
  filter.addAction(Intent.ACTION_SCREEN_OFF);
  filter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
  context.registerReceiver(mBroadcastReceiver,filter);
  TelephonyManager telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  telephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_SERVICE_STATE);
}
 

Example 12

From project HapiPodcastJ, under directory /src/info/xuluan/podcast/service/.

Source file: PlayerService.java

  22 
vote

@Override public void onCreate(){
  super.onCreate();
  mPlayer=new MyPlayer();
  mPlayer.setHandler(handler);
  mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  TelephonyManager tmgr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  tmgr.listen(mPhoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
  log.debug("onCreate()");
}
 

Example 13

From project Ohmage_Phone, under directory /src/org/ccnx/android/ccnlib/.

Source file: CCNxConfiguration.java

  22 
vote

public static String getPhoneNumber(Context ctx){
  try {
    TelephonyManager tm=(TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
    String s=tm.getLine1Number();
    if (null != s && s.length() > 0)     return s;
  }
 catch (  Exception e) {
    Log.e(TAG,"TelephoneManager error",e);
    e.printStackTrace();
  }
  return null;
}
 

Example 14

From project onebusaway-android, under directory /src/com/joulespersecond/seattlebusbot/.

Source file: Application.java

  22 
vote

private String getAppUid(){
  try {
    final TelephonyManager telephony=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    final String id=telephony.getDeviceId();
    MessageDigest digest=MessageDigest.getInstance("MD5");
    digest.update(id.getBytes());
    return getHex(digest.digest());
  }
 catch (  Exception e) {
    return UUID.randomUUID().toString();
  }
}
 

Example 15

From project packages_apps_Phone_1, under directory /src/com/android/phone/.

Source file: OtaUtils.java

  22 
vote

private static int getLteOnCdmaMode(Context context){
  final TelephonyManager telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  if (telephonyManager == null || telephonyManager.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_UNKNOWN) {
    return SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,Phone.LTE_ON_CDMA_UNKNOWN);
  }
  return telephonyManager.getLteOnCdmaMode();
}
 

Example 16

From project phonelocator-android, under directory /phonelocator/src/com/birkettenterprise/phonelocator/settings/.

Source file: EnvironmentalSettingsSetter.java

  22 
vote

public static void updateEnvironmentalSettingsIfRequired(SharedPreferences sharedPreferences,Context context){
  TelephonyManager telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  setIMEIIfRequired(sharedPreferences,telephonyManager);
  setIMSIIfRequiredAndDetectSIMCardChanged(sharedPreferences,telephonyManager);
  try {
    EnvironmentalSettingsSetter.setVersionIfRequired(sharedPreferences,context.getPackageManager().getPackageInfo(context.getPackageName(),0));
  }
 catch (  NameNotFoundException e1) {
  }
}
 

Example 17

From project platform_frameworks_policies_base, under directory /phone/com/android/internal/policy/impl/.

Source file: GlobalActions.java

  22 
vote

/** 
 * @param context everything needs a context :(
 */
public GlobalActions(Context context){
  mContext=context;
  mAudioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  IntentFilter filter=new IntentFilter();
  filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
  filter.addAction(Intent.ACTION_SCREEN_OFF);
  filter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
  context.registerReceiver(mBroadcastReceiver,filter);
  TelephonyManager telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  telephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_SERVICE_STATE);
}
 

Example 18

From project platform_packages_apps_contacts, under directory /src/com/android/contacts/.

Source file: CallDetailActivity.java

  22 
vote

@Override public boolean onKeyDown(int keyCode,KeyEvent event){
switch (keyCode) {
case KeyEvent.KEYCODE_CALL:
{
      TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
      if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
        startActivity(ContactsUtils.getCallIntent(Uri.fromParts(Constants.SCHEME_TEL,mNumber,null)));
        return true;
      }
    }
}
return super.onKeyDown(keyCode,event);
}
 

Example 19

From project platform_packages_apps_phone, under directory /src/com/android/phone/.

Source file: OtaUtils.java

  22 
vote

private static int getLteOnCdmaMode(Context context){
  final TelephonyManager telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  if (telephonyManager == null || telephonyManager.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
    return SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,PhoneConstants.LTE_ON_CDMA_UNKNOWN);
  }
  return telephonyManager.getLteOnCdmaMode();
}
 

Example 20

From project platform_packages_apps_settings, under directory /src/com/android/settings/.

Source file: DataUsageSummary.java

  22 
vote

@Deprecated private boolean isMobilePolicySplit(){
  final Context context=getActivity();
  if (hasReadyMobileRadio(context)) {
    final TelephonyManager tele=TelephonyManager.from(context);
    return mPolicyEditor.isMobilePolicySplit(getActiveSubscriberId(context));
  }
 else {
    return false;
  }
}
 

Example 21

From project platform_packages_providers_contactsprovider, under directory /src/com/android/providers/contacts/.

Source file: GlobalSearchSupport.java

  22 
vote

@SuppressWarnings("all") public GlobalSearchSupport(ContactsProvider2 contactsProvider){
  mContactsProvider=contactsProvider;
  TelephonyManager telman=(TelephonyManager)mContactsProvider.getContext().getSystemService(Context.TELEPHONY_SERVICE);
  if (Organization.COMPANY != Data.DATA1 || Phone.NUMBER != Data.DATA1 || Email.DATA != Data.DATA1) {
    throw new AssertionError("Some of ContactsContract.CommonDataKinds class primary" + " data is not in DATA1 column");
  }
}
 

Example 22

From project radio-reddit-for-Android, under directory /radioreddit/src/com/radioreddit/android/.

Source file: MusicService.java

  22 
vote

@Override public void onDestroy(){
  if (DEBUG) {
    Log.d(TAG,"++OnDestroy++");
  }
  stop();
  unregisterPlaystateListener(mWidgetPlaystateListener);
  unregisterReceiver(mCommandReceiver);
  final TelephonyManager telemgr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  telemgr.listen(mPhoneStateListener,PhoneStateListener.LISTEN_NONE);
}
 

Example 23

From project simplefacebook, under directory /src/com/androidquery/simplefeed/util/.

Source file: PrefUtility.java

  22 
vote

public static String getDeviceId(){
  if (deviceId == null) {
    Context context=MainApplication.getContext();
    TelephonyManager tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    String tmDevice, tmSerial, tmPhone, androidId;
    tmDevice="" + tm.getDeviceId();
    tmSerial="" + tm.getSimSerialNumber();
    androidId="" + android.provider.Settings.Secure.getString(context.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);
    UUID deviceUuid=new UUID(androidId.hashCode(),((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
    deviceId=deviceUuid.toString();
  }
  System.err.println("device:" + deviceId);
  return deviceId;
}
 

Example 24

From project subsonic, under directory /subsonic-android/src/github/daneren2005/dsub/service/.

Source file: DownloadServiceLifecycleSupport.java

  22 
vote

public void onDestroy(){
  executorService.shutdown();
  serializeDownloadQueue();
  downloadService.clear(false);
  downloadService.unregisterReceiver(ejectEventReceiver);
  downloadService.unregisterReceiver(headsetEventReceiver);
  downloadService.unregisterReceiver(intentReceiver);
  TelephonyManager telephonyManager=(TelephonyManager)downloadService.getSystemService(Context.TELEPHONY_SERVICE);
  telephonyManager.listen(phoneStateListener,PhoneStateListener.LISTEN_NONE);
}
 

Example 25

From project Subsonic-Android, under directory /src/net/sourceforge/subsonic/androidapp/service/.

Source file: DownloadServiceLifecycleSupport.java

  22 
vote

public void onDestroy(){
  executorService.shutdown();
  serializeDownloadQueue();
  downloadService.clear(false);
  downloadService.unregisterReceiver(ejectEventReceiver);
  downloadService.unregisterReceiver(headsetEventReceiver);
  downloadService.unregisterReceiver(intentReceiver);
  TelephonyManager telephonyManager=(TelephonyManager)downloadService.getSystemService(Context.TELEPHONY_SERVICE);
  telephonyManager.listen(phoneStateListener,PhoneStateListener.LISTEN_NONE);
}
 

Example 26

From project subsonic_1, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/.

Source file: DownloadServiceLifecycleSupport.java

  22 
vote

public void onDestroy(){
  executorService.shutdown();
  serializeDownloadQueue();
  downloadService.clear(false);
  downloadService.unregisterReceiver(ejectEventReceiver);
  downloadService.unregisterReceiver(headsetEventReceiver);
  downloadService.unregisterReceiver(intentReceiver);
  TelephonyManager telephonyManager=(TelephonyManager)downloadService.getSystemService(Context.TELEPHONY_SERVICE);
  telephonyManager.listen(phoneStateListener,PhoneStateListener.LISTEN_NONE);
}
 

Example 27

From project subsonic_2, under directory /subsonic-android/src/net/sourceforge/subsonic/androidapp/service/.

Source file: DownloadServiceLifecycleSupport.java

  22 
vote

public void onDestroy(){
  executorService.shutdown();
  serializeDownloadQueue();
  downloadService.clear(false);
  downloadService.unregisterReceiver(ejectEventReceiver);
  downloadService.unregisterReceiver(headsetEventReceiver);
  downloadService.unregisterReceiver(intentReceiver);
  TelephonyManager telephonyManager=(TelephonyManager)downloadService.getSystemService(Context.TELEPHONY_SERVICE);
  telephonyManager.listen(phoneStateListener,PhoneStateListener.LISTEN_NONE);
}
 

Example 28

From project TeclaAccess, under directory /source/src/ca/idi/tekla/sep/.

Source file: SwitchEventProvider.java

  22 
vote

@Override public void onReceive(Context context,Intent intent){
  if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
    if (TeclaApp.DEBUG)     Log.d(TeclaApp.TAG,CLASS_TAG + "Phone state changed");
    mPhoneRinging=false;
    TelephonyManager tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm.getCallState() == TelephonyManager.CALL_STATE_RINGING) {
      if (TeclaApp.DEBUG)       Log.d(TeclaApp.TAG,CLASS_TAG + "Phone ringing");
      mPhoneRinging=true;
    }
  }
}
 

Example 29

From project ub0rlib, under directory /src/de/ub0r/android/lib/.

Source file: DonationHelper.java

  22 
vote

/** 
 * Get MD5 hash of the IMEI (device id).
 * @param context {@link Context}
 * @return MD5 hash of IMEI
 */
public static String getImeiHash(final Context context){
  if (imeiHash == null) {
    TelephonyManager mTelephonyMgr=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    final String did=mTelephonyMgr.getDeviceId();
    if (did != null) {
      imeiHash=Utils.md5(did);
    }
 else {
      imeiHash=Utils.md5(Build.BOARD + Build.BRAND + Build.PRODUCT+ Build.DEVICE);
    }
  }
  return imeiHash;
}
 

Example 30

From project vanilla, under directory /src/org/kreed/vanilla/.

Source file: MediaButtonReceiver.java

  22 
vote

/** 
 * Return whether the phone is currently in a call.
 * @param context A context to use.
 */
private static boolean isInCall(Context context){
  if (sInCall == -1) {
    TelephonyManager manager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    sInCall=(byte)(manager.getCallState() == TelephonyManager.CALL_STATE_IDLE ? 0 : 1);
  }
  return sInCall == 1;
}
 

Example 31

From project zaduiReader, under directory /src/cn/zadui/reader/service/.

Source file: UsageCollector.java

  22 
vote

public static String getDeviceId(Context ctx){
  final TelephonyManager tm=(TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
  String tmDevice, tmSerial, tmPhone, androidId;
  tmDevice="" + tm.getDeviceId();
  tmSerial="" + tm.getSimSerialNumber();
  androidId="" + android.provider.Settings.Secure.getString(ctx.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);
  UUID deviceUuid=new UUID(androidId.hashCode(),((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
  return deviceUuid.toString();
}
 

Example 32

From project android_packages_apps_phone, under directory /src/com/android/phone/.

Source file: CallNotifier.java

  21 
vote

public CallNotifier(PhoneApp app,Phone phone,Ringer ringer,BluetoothHandsfree btMgr,CallLogAsync callLog){
  mSettings=CallFeaturesSetting.getInstance(app);
  mApplication=app;
  mCM=app.mCM;
  mCallLog=callLog;
  mAudioManager=(AudioManager)mApplication.getSystemService(Context.AUDIO_SERVICE);
  mPowerManager=(PowerManager)mApplication.getSystemService(Context.POWER_SERVICE);
  registerForNotifications();
  try {
    mSignalInfoToneGenerator=new ToneGenerator(AudioManager.STREAM_VOICE_CALL,TONE_RELATIVE_VOLUME_SIGNALINFO);
  }
 catch (  RuntimeException e) {
    Log.w(LOG_TAG,"CallNotifier: Exception caught while creating " + "mSignalInfoToneGenerator: " + e);
    mSignalInfoToneGenerator=null;
  }
  mRinger=ringer;
  mBluetoothHandsfree=btMgr;
  TelephonyManager telephonyManager=(TelephonyManager)app.getSystemService(Context.TELEPHONY_SERVICE);
  telephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR);
}
 

Example 33

From project android_packages_apps_TouchWiz30Launcher, under directory /src/com/sec/android/app/twlauncher/.

Source file: BootupListener.java

  21 
vote

public void onReceive(Context context,Intent intent){
  Log.v("bootupListener",(new StringBuilder()).append("IMSI ").append(SystemProperties.get("ril.IMSI")).append(" intent ").append(intent.getAction()).toString());
  if (("AMN".equals(salesCode) || "ORA".equals(salesCode) || "FTM".equals(salesCode)|| "XEC".equals(salesCode)) && !SystemProperties.get("ril.IMSI").equals("999999999999999") && "android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
    TelephonyManager telephonymanager=(TelephonyManager)context.getSystemService("phone");
    if (telephonymanager.getSimState() != 1) {
      SharedPreferences sharedpreferences=context.getSharedPreferences("pref_first_Time_boot",0);
      android.content.SharedPreferences.Editor editor=sharedpreferences.edit();
      String s=getIccidPreference(sharedpreferences);
      String s1;
      boolean flag;
      if (s == null)       Log.d("bootupListener","========= iccidPref is null =============");
 else       Log.d("bootupListener",(new StringBuilder()).append("========= iccidPref ============= ").append(s).toString());
      s1=getIccid(telephonymanager);
      if (s1 == null)       Log.d("bootupListener","========= iccid is null =============");
 else       Log.d("bootupListener",(new StringBuilder()).append("========= iccid ============= ").append(s1).toString());
      if (s == null || s1 != null && !s.equals(s1)) {
        Log.d("bootupListener","========= New SIM =============");
        flag=true;
      }
 else {
        flag=false;
      }
      if (flag && s1 != null) {
        editor.putString("sim_iccid",s1);
        Log.d("bootupListener","========= New SIM ICCID added to preferences =============");
        editor.commit();
        Intent intent1=new Intent(context,com / sec / android/ app/ twlauncher/ FlatRateAlertActivity);
        intent1.setFlags(0x10000000);
        context.startActivity(intent1);
      }
    }
  }
}
 

Example 34

From project callmeter, under directory /src/de/ub0r/android/callmeter/data/.

Source file: LogRunnerService.java

  21 
vote

/** 
 * Acquire  {@link WakeLock} and init service.
 * @param a action
 * @return {@link WakeLock}
 */
private WakeLock acquire(final String a){
  final PowerManager pm=(PowerManager)this.getSystemService(Context.POWER_SERVICE);
  final PowerManager.WakeLock wakelock=pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,TAG);
  wakelock.acquire();
  Log.i(TAG,"got wakelock");
  if (a != null && (a.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED) || a.equals(ACTION_SMS))) {
    Log.i(TAG,"sleep for " + WAIT_FOR_LOGS + "ms");
    try {
      Thread.sleep(WAIT_FOR_LOGS);
    }
 catch (    InterruptedException e) {
      Log.e(TAG,"interrupted while waiting for logs",e);
    }
  }
  TelephonyManager tm=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
  roaming=tm.isNetworkRoaming();
  Log.d(TAG,"roaming: " + roaming);
  mynumber=tm.getLine1Number();
  Log.d(TAG,"my number: " + mynumber);
  return wakelock;
}
 

Example 35

From project DeskSMS, under directory /DeskSMS/src/com/koushikdutta/desktopsms/.

Source file: Helper.java

  21 
vote

@SuppressLint("NewApi") static public String getSafeDeviceId(Context context){
  TelephonyManager tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  String deviceId=tm.getDeviceId();
  if (deviceId == null) {
    String wifiInterface=SystemProperties.get("wifi.interface");
    try {
      if (Build.VERSION.SDK_INT < 9)       throw new Exception();
      String wifiMac=new String(NetworkInterface.getByName(wifiInterface).getHardwareAddress());
      deviceId=wifiMac;
    }
 catch (    Exception e) {
      deviceId="000000000000";
    }
  }
  deviceId+=context.getPackageName();
  String ret=digest(deviceId);
  return ret;
}
 

Example 36

From project dmix, under directory /MPDroid/src/com/namelessdev/mpdroid/.

Source file: StreamingService.java

  21 
vote

public void onCreate(){
  super.onCreate();
  isServiceRunning=true;
  mediaPlayer=new MediaPlayer();
  audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  buffering=true;
  oldStatus="";
  isPlaying=true;
  isPaused=false;
  needStoppedNotification=false;
  lastStartID=0;
  mediaPlayer.setOnBufferingUpdateListener(this);
  mediaPlayer.setOnCompletionListener(this);
  mediaPlayer.setOnPreparedListener(this);
  mediaPlayer.setOnErrorListener(this);
  mediaPlayer.setOnInfoListener(this);
  remoteControlResponder=new ComponentName(getPackageName(),RemoteControlReceiver.class.getName());
  initializeRemoteControlRegistrationMethods();
  registerMediaButtonEvent();
  registerRemoteControlClient();
  if (audioManager.requestAudioFocus(this,AudioManager.STREAM_MUSIC,AudioManager.AUDIOFOCUS_GAIN) == AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
    Toast.makeText(this,R.string.audioFocusFailed,Toast.LENGTH_LONG).show();
    stop();
  }
  TelephonyManager tmgr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  tmgr.listen(phoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
  MPDApplication app=(MPDApplication)getApplication();
  app.oMPDAsyncHelper.addStatusChangeListener(this);
  app.oMPDAsyncHelper.addConnectionListener(this);
  app.setActivity(this);
  streamSource="http://" + app.oMPDAsyncHelper.getConnectionSettings().getConnectionStreamingServer() + ":"+ app.oMPDAsyncHelper.getConnectionSettings().iPortStreaming+ "/";
}
 

Example 37

From project DownloadProvider, under directory /src/com/mozillaonline/providers/downloads/.

Source file: RealSystemFacade.java

  21 
vote

public boolean isNetworkRoaming(){
  ConnectivityManager connectivity=(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  if (connectivity == null) {
    Log.w(Constants.TAG,"couldn't get connectivity manager");
    return false;
  }
  NetworkInfo info=connectivity.getActiveNetworkInfo();
  boolean isMobile=(info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
  final TelephonyManager mgr=(TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
  boolean isRoaming=isMobile && mgr.isNetworkRoaming();
  if (Constants.LOGVV && isRoaming) {
    Log.v(Constants.TAG,"network is roaming");
  }
  return isRoaming;
}
 

Example 38

From project FBReaderJ, under directory /src/org/geometerplus/zlibrary/ui/android/library/.

Source file: ZLAndroidLibrary.java

  21 
vote

@Override public Collection<String> defaultLanguageCodes(){
  final TreeSet<String> set=new TreeSet<String>();
  set.add(Locale.getDefault().getLanguage());
  final TelephonyManager manager=(TelephonyManager)myApplication.getSystemService(Context.TELEPHONY_SERVICE);
  if (manager != null) {
    final String country0=manager.getSimCountryIso().toLowerCase();
    final String country1=manager.getNetworkCountryIso().toLowerCase();
    for (    Locale locale : Locale.getAvailableLocales()) {
      final String country=locale.getCountry().toLowerCase();
      if (country != null && country.length() > 0 && (country.equals(country0) || country.equals(country1))) {
        set.add(locale.getLanguage());
      }
    }
    if ("ru".equals(country0) || "ru".equals(country1)) {
      set.add("ru");
    }
 else     if ("by".equals(country0) || "by".equals(country1)) {
      set.add("ru");
    }
 else     if ("ua".equals(country0) || "ua".equals(country1)) {
      set.add("ru");
    }
  }
  set.add("multi");
  return set;
}
 

Example 39

From project lullaby, under directory /src/net/sileht/lullaby/player/.

Source file: PlayerService.java

  21 
vote

@Override public void onCreate(){
  Context ctx=getApplicationContext();
  TelephonyManager tmgr=(TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
  tmgr.listen(mPhoneStateListener,0);
  mStreamCacher=new StreamCacher(ctx);
  mStreamCacher.start();
  mPlaylist=new PlayingPlaylist(this);
  mPhoneStateListener=new MyPhoneStateListener();
  mPlayerListeners=new ArrayList<OnStatusListener>();
  mPlayer=new MediaPlayer();
  mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mPlayer.setOnErrorListener(this);
  mPlayer.setOnPreparedListener(this);
  mPlayer.setOnCompletionListener(this);
  mPlayer.setOnBufferingUpdateListener(this);
  setState(STATE.Idle);
  SharedPreferences settings=PreferenceManager.getDefaultSharedPreferences(ctx);
  String id=settings.getString("song_id",null);
  int pos=settings.getInt("playlist_pos",-1);
  if (mPlaylist.load(ctx) && pos != -1) {
    mPlaylist.setCurrentPosition(pos);
  }
  if (id != null && !id.equals("")) {
    AmpacheRequest request=new AmpacheRequest(null,new String[]{"song",id},true,false){
      @Override public void add_objects(      @SuppressWarnings("rawtypes") ArrayList list){
        if (!list.isEmpty() && mSong == null) {
          setSong((Song)list.get(0));
        }
      }
    }
;
    request.send();
  }
  Log.v(TAG,"Lullaby Player Service Start");
  mTickHandler.postDelayed(mTickTask,100);
}
 

Example 40

From project Monetizing-Android-Demo-Project, under directory /src/dk/trifork/geeknight/bigredbutton/.

Source file: SimpleCrypto.java

  21 
vote

/** 
 * Returns a unique seed based on the device. We want to avoid persisting this seed, so use the following priority list: 1. Use Settings.Secure.ANDROID_ID (for Android 2.2+) 2. Use TelephonyManager.getDeviceId() (if != null) 3. Create a UUID and save in SharedPreferences as deviceId.
 * @author Christian Melchior
 */
public static String getDeviceSeed(Context ctx){
  TelephonyManager tm=(TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
  String deviceId;
  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO) {
    deviceId=Settings.Secure.ANDROID_ID;
  }
 else   if (tm.getDeviceId() != null) {
    deviceId=tm.getDeviceId();
  }
 else {
    SharedPreferences sp=ctx.getSharedPreferences("PREF_UNIQUE_ID",Context.MODE_PRIVATE);
    String uniqueId=sp.getString("PREF_UNIQUE_ID",null);
    if (uniqueId == null) {
      uniqueId=UUID.randomUUID().toString();
      Editor editor=sp.edit();
      editor.putString("PREF_UNIQUE_ID",uniqueId);
      editor.commit();
    }
    deviceId=uniqueId;
  }
  return createHashedDeviceId(deviceId);
}
 

Example 41

From project mp3tunes-android, under directory /src/com/mp3tunes/android/service/.

Source file: Mp3tunesService.java

  21 
vote

private int chooseBitrate(){
  int bitrate=Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(this).getString("bitrate","-1"));
  if (bitrate == -1) {
    int[] vals=getResources().getIntArray(R.array.rate_values);
    ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    int type=cm.getActiveNetworkInfo().getType();
    if (type == ConnectivityManager.TYPE_WIFI) {
      bitrate=vals[4];
    }
 else     if (type == ConnectivityManager.TYPE_MOBILE) {
      TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
switch (tm.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
case TelephonyManager.NETWORK_TYPE_GPRS:
        bitrate=vals[2];
      break;
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_UMTS:
    bitrate=vals[3];
  break;
}
}
}
return bitrate;
}
 

Example 42

From project packages_apps_Camera_1, under directory /src/com/android/camera/.

Source file: Util.java

  21 
vote

/** 
 * Returns whether the device is voice-capable (meaning, it can do MMS).
 */
public static boolean isMmsCapable(Context context){
  TelephonyManager telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  if (telephonyManager == null) {
    return false;
  }
  try {
    Class partypes[]=new Class[0];
    Method sIsVoiceCapable=TelephonyManager.class.getMethod("isVoiceCapable",partypes);
    Object arglist[]=new Object[0];
    Object retobj=sIsVoiceCapable.invoke(telephonyManager,arglist);
    return (Boolean)retobj;
  }
 catch (  java.lang.reflect.InvocationTargetException ite) {
  }
catch (  IllegalAccessException iae) {
  }
catch (  NoSuchMethodException nsme) {
  }
  return true;
}
 

Example 43

From project packages_apps_Camera_2, under directory /src/com/android/camera/.

Source file: Util.java

  21 
vote

/** 
 * Returns whether the device is voice-capable (meaning, it can do MMS).
 */
public static boolean isMmsCapable(Context context){
  TelephonyManager telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  if (telephonyManager == null) {
    return false;
  }
  try {
    Class partypes[]=new Class[0];
    Method sIsVoiceCapable=TelephonyManager.class.getMethod("isVoiceCapable",partypes);
    Object arglist[]=new Object[0];
    Object retobj=sIsVoiceCapable.invoke(telephonyManager,arglist);
    return (Boolean)retobj;
  }
 catch (  java.lang.reflect.InvocationTargetException ite) {
  }
catch (  IllegalAccessException iae) {
  }
catch (  NoSuchMethodException nsme) {
  }
  return true;
}
 

Example 44

From project platform_packages_apps_camera, under directory /src/com/android/camera/.

Source file: Util.java

  21 
vote

/** 
 * Returns whether the device is voice-capable (meaning, it can do MMS).
 */
public static boolean isMmsCapable(Context context){
  TelephonyManager telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  if (telephonyManager == null) {
    return false;
  }
  try {
    Class<?> partypes[]=new Class[0];
    Method sIsVoiceCapable=TelephonyManager.class.getMethod("isVoiceCapable",partypes);
    Object arglist[]=new Object[0];
    Object retobj=sIsVoiceCapable.invoke(telephonyManager,arglist);
    return (Boolean)retobj;
  }
 catch (  java.lang.reflect.InvocationTargetException ite) {
  }
catch (  IllegalAccessException iae) {
  }
catch (  NoSuchMethodException nsme) {
  }
  return true;
}
 

Example 45

From project platform_packages_apps_CytownPhone, under directory /src/com/android/phone/.

Source file: CallNotifier.java

  21 
vote

public CallNotifier(PhoneApp app,Phone phone,Ringer ringer,BluetoothHandsfree btMgr,CallLogAsync callLog){
  mSettings=CallFeaturesSetting.getInstance(app);
  mApplication=app;
  mCM=app.mCM;
  mCallLog=callLog;
  mAudioManager=(AudioManager)mApplication.getSystemService(Context.AUDIO_SERVICE);
  mPowerManager=(PowerManager)mApplication.getSystemService(Context.POWER_SERVICE);
  registerForNotifications();
  try {
    mSignalInfoToneGenerator=new ToneGenerator(AudioManager.STREAM_VOICE_CALL,TONE_RELATIVE_VOLUME_SIGNALINFO);
  }
 catch (  RuntimeException e) {
    Log.w(LOG_TAG,"CallNotifier: Exception caught while creating " + "mSignalInfoToneGenerator: " + e);
    mSignalInfoToneGenerator=null;
  }
  mRinger=ringer;
  mBluetoothHandsfree=btMgr;
  TelephonyManager telephonyManager=(TelephonyManager)app.getSystemService(Context.TELEPHONY_SERVICE);
  telephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR | PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR);
}
 

Example 46

From project TABuss, under directory /src/org/ubicompforall/BusTUC/Queries/.

Source file: Browser.java

  21 
vote

public String getRequestServer(String stop,Boolean formated,Location location,int numStops,int dist,Context context){
  String html_string=null;
  HttpGet m_get=new HttpGet();
  try {
    stop=URLEncoder.encode(stop,"UTF-8");
  }
 catch (  UnsupportedEncodingException e1) {
    e1.printStackTrace();
  }
  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);
    html_string=httpF.requestServer(m_response);
    Log.v("html_string","Returned html: " + html_string);
  }
 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;
}
 

Example 47

From project titanium_modules, under directory /beintoosdk/mobile/android/src/com/beintoo/beintoosdkutility/.

Source file: DeviceId.java

  21 
vote

public static String getUniqueAndroidDeviceId(Context context){
  final TelephonyManager tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  String tmDevice, tmSerial, androidId=null;
  try {
    tmDevice="" + tm.getDeviceId();
    tmSerial=tm.getSimSerialNumber() != null ? tm.getSimSerialNumber() : "";
    androidId=android.provider.Settings.Secure.getString(context.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);
    if (androidId == null) {
      return toSHA1(DeveloperConfiguration.apiKey);
    }
 else     if (androidId.equals(BUGGED_ANDROID_ID) && ("000000000000000".equals(tmDevice))) {
      return toSHA1(DeveloperConfiguration.apiKey);
    }
 else     if ((androidId.equals(BUGGED_ANDROID_ID)) && (tmSerial.equals(""))) {
      return null;
    }
 else {
      UUID deviceUuid=new UUID(androidId.hashCode(),((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
      String deviceId=deviceUuid.toString();
      return deviceId;
    }
  }
 catch (  Exception e) {
    return null;
  }
}
 

Example 48

From project yammp, under directory /src/org/yammp/.

Source file: MusicPlaybackService.java

  21 
vote

@Override public void onDestroy(){
  if (isPlaying()) {
    Log.e(LOGTAG_SERVICE,"Service being destroyed while still playing.");
  }
  if (mEqualizer != null) {
    mEqualizer.setEnabled(false);
    mEqualizer.release();
  }
  mPlayer.release();
  mPlayer=null;
  mAudioManager.abandonAudioFocus(mAudioFocusListener);
  TelephonyManager telephonyManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  telephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_NONE);
  mDelayedStopHandler.removeCallbacksAndMessages(null);
  mMediaplayerHandler.removeCallbacksAndMessages(null);
  if (mCursor != null) {
    mCursor.close();
    mCursor=null;
  }
  unregisterReceiver(mIntentReceiver);
  unregisterReceiver(mA2dpReceiver);
  unregisterReceiver(mExternalAudioDeviceStatusReceiver);
  if (mUnmountReceiver != null) {
    unregisterReceiver(mUnmountReceiver);
    mUnmountReceiver=null;
  }
  mWakeLock.release();
  mNotificationManager.cancelAll();
  removeStickyBroadcast(mPlaybackIntent);
  super.onDestroy();
}
 

Example 49

From project iohack, under directory /src/org/alljoyn/bus/sample/chat/.

Source file: StartScreen.java

  20 
vote

public void onCreate(Bundle savedInstanceState){
  Log.i(TAG,"onCreate()");
  super.onCreate(savedInstanceState);
  prefs=getSharedPreferences(PREFS_NAME,0);
  if (prefs.getBoolean(HAVE_INFO,false)) {
    startActivity(new Intent(this,ViewChannelActivity.class));
  }
  setContentView(R.layout.startscreen);
  String number=((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).getLine1Number();
  phoneNum=(TextView)findViewById(R.id.st_phone);
  phoneNum.setText(number);
  String possibleEmail=null;
  Pattern emailPattern=Patterns.EMAIL_ADDRESS;
  Account[] accounts=AccountManager.get(getBaseContext()).getAccounts();
  for (  Account account : accounts) {
    if (emailPattern.matcher(account.name).matches()) {
      possibleEmail=account.name;
    }
  }
  email=(TextView)findViewById(R.id.st_email);
  email.setText(possibleEmail);
  name=(TextView)findViewById(R.id.st_name);
}
 

Example 50

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/guice/.

Source file: AirCastingModule.java

  19 
vote

@Override protected void configure(){
  requestStaticInjection(HttpBuilder.class);
  bind(Gson.class).toProvider(GsonProvider.class).in(Scopes.SINGLETON);
  bind(HttpClient.class).to(DefaultHttpClient.class);
  bind(AirCastingDB.class).toProvider(AirCastingDBProvider.class);
  bind(NoteOverlay.class).toProvider(NoteOverlayProvider.class);
  bind(Geocoder.class).toProvider(GeocoderProvider.class);
  bind(EventBus.class).in(Scopes.SINGLETON);
  bindConstant().annotatedWith(SharedPreferencesName.class).to("pl.llp.aircasting_preferences");
  bind(BluetoothAdapter.class).toProvider(BluetoothAdapterProvider.class);
  bind(TelephonyManager.class).toProvider(new SystemServiceProvider<TelephonyManager>(Context.TELEPHONY_SERVICE));
}
 

Example 51

From project AlarmApp-Android, under directory /src/org/alarmapp/services/.

Source file: AudioPlayerService.java

  19 
vote

@Override public void onCreate(){
  mVibrator=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
  mTelephonyManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  mTelephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
  LogEx.verbose("Aquire CPU Wakelock");
  AlarmAppWakeLock.acquireCpuWakeLock(this);
}
 

Example 52

From project android-context, under directory /src/edu/fsu/cs/contextprovider/sensor/.

Source file: TelephonyService.java

  19 
vote

@Override public void onCallStateChanged(int state,String incomingNumber){
  super.onCallStateChanged(state,incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
    PHONE_STATE="CALL_STATE_IDLE";
  PHONE_STATE_UPDATE=Long.valueOf(System.currentTimeMillis());
if (DEBUG) Log.d(TAG,"State: " + PHONE_STATE);
break;
case TelephonyManager.CALL_STATE_RINGING:
PHONE_STATE="CALL_STATE_RINGING";
PHONE_STATE_UPDATE=Long.valueOf(System.currentTimeMillis());
if (DEBUG) Log.d(TAG,"State: " + PHONE_STATE);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
PHONE_STATE="CALL_STATE_IDLE";
PHONE_STATE_UPDATE=Long.valueOf(System.currentTimeMillis());
if (DEBUG) Log.d(TAG,"State: " + PHONE_STATE);
break;
}
}
 

Example 53

From project androidpn, under directory /androidpn-client/src/org/androidpn/client/.

Source file: NotificationService.java

  19 
vote

@Override public void onCreate(){
  Log.d(LOGTAG,"onCreate()...");
  telephonyManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  sharedPrefs=getSharedPreferences(Constants.SHARED_PREFERENCE_NAME,Context.MODE_PRIVATE);
  deviceId=telephonyManager.getDeviceId();
  Editor editor=sharedPrefs.edit();
  editor.putString(Constants.DEVICE_ID,deviceId);
  editor.commit();
  if (deviceId == null || deviceId.trim().length() == 0 || deviceId.matches("0+")) {
    if (sharedPrefs.contains("EMULATOR_DEVICE_ID")) {
      deviceId=sharedPrefs.getString(Constants.EMULATOR_DEVICE_ID,"");
    }
 else {
      deviceId=(new StringBuilder("EMU")).append((new Random(System.currentTimeMillis())).nextLong()).toString();
      editor.putString(Constants.EMULATOR_DEVICE_ID,deviceId);
      editor.commit();
    }
  }
  Log.d(LOGTAG,"deviceId=" + deviceId);
  xmppManager=new XmppManager(this);
  taskSubmitter.submit(new Runnable(){
    public void run(){
      NotificationService.this.start();
    }
  }
);
}
 

Example 54

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/deviceinfo/.

Source file: Status.java

  19 
vote

private void updateDataState(){
  int state=mTelephonyManager.getDataState();
  String display=mRes.getString(R.string.radioInfo_unknown);
switch (state) {
case TelephonyManager.DATA_CONNECTED:
    display=mRes.getString(R.string.radioInfo_data_connected);
  break;
case TelephonyManager.DATA_SUSPENDED:
display=mRes.getString(R.string.radioInfo_data_suspended);
break;
case TelephonyManager.DATA_CONNECTING:
display=mRes.getString(R.string.radioInfo_data_connecting);
break;
case TelephonyManager.DATA_DISCONNECTED:
display=mRes.getString(R.string.radioInfo_data_disconnected);
break;
}
setSummaryText("data_state",display);
}
 

Example 55

From project android_packages_apps_CellBroadcastReceiver, under directory /src/com/android/cellbroadcastreceiver/.

Source file: CellBroadcastAlertAudio.java

  19 
vote

@Override public void onCreate(){
  PowerManager pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
  mWakeLock=pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,TAG);
  mWakeLock.acquire();
  mVibrator=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
  mAudioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  mTelephonyManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  mTelephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
}
 

Example 56

From project Cafe, under directory /testservice/src/com/baidu/cafe/remote/.

Source file: SystemLib.java

  19 
vote

public SystemLib(Context context){
  mContext=context;
  mTelephonyManager=(TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
  mKeyguardManager=(KeyguardManager)mContext.getSystemService(Context.KEYGUARD_SERVICE);
  mBatteryState=new BatteryState(mContext);
  mAudioManager=(AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
  mPowerManager=(PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
  mWifiManager=(WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
  mPackageManager=mContext.getPackageManager();
  mIntentFilter=new IntentFilter();
  mIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
  mWakeLock=mPowerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,"Test Acquired!");
  mActivityManager=(ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
}
 

Example 57

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/feed/objects/.

Source file: PhoneStateObj.java

  19 
vote

private String asText(JSONObject obj){
  StringBuilder status=new StringBuilder();
  String a=obj.optString(ACTION);
  String b=obj.optString(NUMBER);
  if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(a)) {
    status.append("Calling ");
  }
 else   if (TelephonyManager.EXTRA_STATE_IDLE.equals(a)) {
    status.append("Ending phone call with ");
  }
 else   if (TelephonyManager.EXTRA_STATE_RINGING.equals(a)) {
    status.append("Inbound call from ");
  }
  status.append(b).append(".");
  return status.toString();
}
 

Example 58

From project ElectricSleep, under directory /src/com/androsz/electricsleepbeta/alarmclock/.

Source file: AlarmKlaxon.java

  19 
vote

@Override public void onCallStateChanged(final int state,final String ignored){
  if (state != TelephonyManager.CALL_STATE_IDLE && state != mInitialCallState) {
    sendKillBroadcast(mCurrentAlarm);
    stopSelf();
  }
}
 

Example 59

From project GSM-Signal-Tracking-, under directory /gpstracker/src/nl/sogeti/android/gpstracker/logger/.

Source file: GPSLoggerService.java

  19 
vote

/** 
 * Called by the system when the service is first created. Do not call this method directly. Be sure to call super.onCreate().
 */
@Override public void onCreate(){
  super.onCreate();
  Log.d(TAG,"onCreate()");
  GPSLoggerServiceThread looper=new GPSLoggerServiceThread();
  looper.start();
  try {
    looper.ready.acquire();
  }
 catch (  InterruptedException e) {
    Log.e(TAG,"Interrupted during wait for the GPSLoggerServiceThread to start, prepare for trouble!",e);
  }
  mWeakLocations=new Vector<Location>(3);
  mAltitudes=new LinkedList<Double>();
  mLoggingState=Constants.STOPPED;
  mStartNextSegment=false;
  mLocationManager=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
  mNoticationManager=(NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
  mNoticationManager.cancel(R.layout.map);
  mTelephonyManager=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
  mTelephonyManager.listen(mPhoneStateChangeListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
  SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(this);
  mSpeedSanityCheck=sharedPreferences.getBoolean(Constants.SPEEDSANITYCHECK,true);
  boolean startImmidiatly=PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.LOGATSTARTUP,false);
  crashRestoreState();
  if (startImmidiatly && mLoggingState == Constants.STOPPED) {
    startLogging();
    ContentValues values=new ContentValues();
    values.put(Tracks.NAME,"Recorded at startup");
    getContentResolver().update(ContentUris.withAppendedId(Tracks.CONTENT_URI,mTrackId),values,null,null);
  }
 else {
    broadCastLoggingState();
  }
}
 

Example 60

From project incubator-cordova-android, under directory /framework/src/org/apache/cordova/.

Source file: Device.java

  19 
vote

/** 
 * Listen for telephony events: RINGING, OFFHOOK and IDLE Send these events to all plugins using DroidGap.onMessage("telephone", "ringing" | "offhook" | "idle")
 */
private void initTelephonyReceiver(){
  IntentFilter intentFilter=new IntentFilter();
  intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
  this.telephonyReceiver=new BroadcastReceiver(){
    @Override public void onReceive(    Context context,    Intent intent){
      if ((intent != null) && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
        if (intent.hasExtra(TelephonyManager.EXTRA_STATE)) {
          String extraData=intent.getStringExtra(TelephonyManager.EXTRA_STATE);
          if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            LOG.i(TAG,"Telephone RINGING");
            webView.postMessage("telephone","ringing");
          }
 else           if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
            LOG.i(TAG,"Telephone OFFHOOK");
            webView.postMessage("telephone","offhook");
          }
 else           if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
            LOG.i(TAG,"Telephone IDLE");
            webView.postMessage("telephone","idle");
          }
        }
      }
    }
  }
;
  this.cordova.getActivity().registerReceiver(this.telephonyReceiver,intentFilter);
}
 

Example 61

From project jamendo-android, under directory /src/com/teleca/jamendo/service/.

Source file: PlayerService.java

  19 
vote

@Override public void onCreate(){
  Log.i(JamendoApplication.TAG,"Player Service onCreate");
  mPlayerEngine=new PlayerEngineImpl();
  mPlayerEngine.setListener(mLocalEngineListener);
  mTelephonyManager=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
  mPhoneStateListener=new PhoneStateListener(){
    @Override public void onCallStateChanged(    int state,    String incomingNumber){
      Log.e(JamendoApplication.TAG,"onCallStateChanged");
      if (state == TelephonyManager.CALL_STATE_IDLE) {
      }
 else {
        if (mPlayerEngine != null) {
          mPlayerEngine.pause();
        }
      }
    }
  }
;
  mTelephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
  mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  mWifiManager=(WifiManager)getSystemService(Context.WIFI_SERVICE);
  mWifiLock=mWifiManager.createWifiLock(JamendoApplication.TAG);
  mWifiLock.setReferenceCounted(false);
  JamendoApplication.getInstance().setConcretePlayerEngine(mPlayerEngine);
  mRemoteEngineListener=JamendoApplication.getInstance().fetchPlayerEngineListener();
}
 

Example 62

From project Juggernaut_SystemUI, under directory /src/com/android/systemui/statusbar/.

Source file: CallWidget.java

  19 
vote

@Override public void onCallStateChanged(int state,String incomingNumber){
  super.onCallStateChanged(state,incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
    mMuteOn.setEnabled(false);
  mMuteOff.setEnabled(false);
mTimer.setVisibility(View.GONE);
hideMusic();
show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
mMuteOn.setEnabled(true);
mMuteOff.setEnabled(true);
show();
hideMusic();
mTimer.setVisibility(View.VISIBLE);
mTimer.setBase(SystemClock.elapsedRealtime());
mTimer.start();
break;
case TelephonyManager.CALL_STATE_IDLE:
hide();
showMusic();
mTimer.setVisibility(View.GONE);
mMuteOn.setEnabled(true);
mMuteOff.setEnabled(true);
break;
}
updateWidget();
}
 

Example 63

From project MobiPerf, under directory /android/src/com/mobiperf/util/.

Source file: PhoneUtils.java

  19 
vote

/** 
 * Returns "GSM", "CDMA". 
 */
private String getTelephonyPhoneType(){
switch (telephonyManager.getPhoneType()) {
case TelephonyManager.PHONE_TYPE_CDMA:
    return "CDMA";
case TelephonyManager.PHONE_TYPE_GSM:
  return "GSM";
case TelephonyManager.PHONE_TYPE_NONE:
return "None";
}
return "Unknown";
}
 

Example 64

From project MWM-for-Android, under directory /src/org/metawatch/manager/.

Source file: CallStateListener.java

  19 
vote

@Override public void onCallStateChanged(int state,String incomingNumber){
  super.onCallStateChanged(state,incomingNumber);
  if (!MetaWatchService.Preferences.notifyCall)   return;
  if (incomingNumber == null)   incomingNumber="";
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
    Call.startCall(context,incomingNumber);
  break;
case TelephonyManager.CALL_STATE_IDLE:
Call.endCall(context);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Call.endCall(context);
break;
}
}
 

Example 65

From project myPlan, under directory /src/com/conzebit/myplan/android/receiver/.

Source file: AfterCallReceiver.java

  19 
vote

@Override public void onReceive(Context context,Intent intent){
  if (!Settings.isTrapAfterCall(context)) {
    return;
  }
  NotificationManager notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
  Bundle extras=intent.getExtras();
  if (extras != null) {
    String state=extras.getString(TelephonyManager.EXTRA_STATE);
    if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
      incomingCall=true;
    }
 else     if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {
      if (!incomingCall) {
        try {
synchronized (context) {
            context.wait(5000);
          }
        }
 catch (        Exception e) {
        }
        AndroidMsisdnTypeStore androidMsisdnTypeStore=new AndroidMsisdnTypeStore(context);
        MsisdnTypeService.getInstance(androidMsisdnTypeStore);
        Call lastCall=LogStoreService.getInstance().getLastCall(context);
        if (lastCall != null && lastCall.getDuration() > 0 && lastCall.getType() == Call.CALL_TYPE_SENT) {
          notifyUser(context,notificationManager);
        }
      }
      incomingCall=false;
    }
  }
}
 

Example 66

From project npr-android-app, under directory /src/org/npr/android/news/.

Source file: PlaybackService.java

  19 
vote

@Override public void onCreate(){
  mediaPlayer=new MediaPlayer();
  mediaPlayer.setOnBufferingUpdateListener(this);
  mediaPlayer.setOnCompletionListener(this);
  mediaPlayer.setOnErrorListener(this);
  mediaPlayer.setOnInfoListener(this);
  mediaPlayer.setOnPreparedListener(this);
  notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  Log.w(LOG_TAG,"Playback service created");
  telephonyManager=(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
  listener=new PhoneStateListener(){
    @Override public void onCallStateChanged(    int state,    String incomingNumber){
switch (state) {
case TelephonyManager.CALL_STATE_OFFHOOK:
case TelephonyManager.CALL_STATE_RINGING:
        if (isPlaying()) {
          pause();
          isPausedInCall=true;
        }
      break;
case TelephonyManager.CALL_STATE_IDLE:
    if (isPausedInCall) {
      seekTo(Math.max(0,getPosition() - RESUME_REWIND_TIME));
      play();
    }
  break;
}
}
}
;
telephonyManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);
}
 

Example 67

From project OneMoreDream, under directory /src/com/dixheure/.

Source file: AlarmKlaxon.java

  19 
vote

@Override public void onCallStateChanged(int state,String ignored){
  if (state != TelephonyManager.CALL_STATE_IDLE && state != mInitialCallState) {
    sendKillBroadcast(mCurrentAlarm);
    stopSelf();
  }
}
 

Example 68

From project packages_apps_ROMControl, under directory /src/com/aokp/romcontrol/service/.

Source file: FlipService.java

  19 
vote

@Override public int onStartCommand(Intent intent,int flags,int startId){
  if (!mRegistered) {
    IntentFilter filter=new IntentFilter();
    am=(AudioManager)service.getSystemService(Context.AUDIO_SERVICE);
    vib=(Vibrator)service.getSystemService(Context.VIBRATOR_SERVICE);
    if (getUserFlipAudioMode(service) != -1) {
      getSensorManager().registerListener(sl,getSensorManager().getDefaultSensor(Sensor.TYPE_ORIENTATION),SensorManager.SENSOR_DELAY_UI);
    }
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    registerReceiver(screenReceiver,filter);
    mRegistered=true;
    log("register sensor manager");
  }
  return START_STICKY;
}
 

Example 69

From project pandoroid, under directory /src/com/aregner/android/pandoid/.

Source file: PandoraRadioService.java

  19 
vote

@Override public void onCreate(){
synchronized (lock) {
    super.onCreate();
    instance=this;
    pandora=new PandoraRadio();
    media=new MediaPlayer();
    notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    telephonyManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    prefs=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    telephonyManager.listen(new PhoneStateListener(){
      boolean pausedForRing=false;
      @Override public void onCallStateChanged(      int state,      String incomingNumber){
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
          if (pausedForRing && !media.isPlaying()) {
            if (prefs.getBoolean("behave_resumeOnHangup",true)) {
              media.start();
              setNotification();
              pausedForRing=false;
            }
          }
        break;
case TelephonyManager.CALL_STATE_OFFHOOK:
case TelephonyManager.CALL_STATE_RINGING:
      if (media.isPlaying()) {
        media.pause();
        pausedForRing=true;
      }
    break;
}
}
}
,PhoneStateListener.LISTEN_CALL_STATE);
}
}
 

Example 70

From project platform_packages_apps_alarmclock, under directory /src/com/android/alarmclock/.

Source file: AlarmKlaxon.java

  19 
vote

@Override public void onCallStateChanged(int state,String ignored){
  if (state != TelephonyManager.CALL_STATE_IDLE && state != mInitialCallState) {
    sendKillBroadcast(mCurrentAlarm);
    stopSelf();
  }
}
 

Example 71

From project platform_packages_apps_im, under directory /src/com/android/im/service/.

Source file: RemoteImService.java

  19 
vote

private Map<String,String> loadProviderSettings(long providerId){
  ContentResolver cr=getContentResolver();
  Map<String,String> settings=Imps.ProviderSettings.queryProviderSettings(cr,providerId);
  NetworkInfo networkInfo=mNetworkConnectivityListener.getNetworkInfo();
  if ("1".equals(SystemProperties.get("ro.kernel.qemu"))) {
    settings.put(ImpsConfigNames.MSISDN,"15555218135");
  }
 else   if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
    if (!TextUtils.isEmpty(settings.get(ImpsConfigNames.SMS_ADDR))) {
      settings.put(ImpsConfigNames.SMS_AUTH,"true");
      settings.put(ImpsConfigNames.SECURE_LOGIN,"false");
    }
 else {
      String msisdn=TelephonyManager.getDefault().getLine1Number();
      if (TextUtils.isEmpty(msisdn)) {
        Log.w(TAG,"Can not read MSISDN from SIM, use a fake one." + " SMS related feature won't work.");
        msisdn="15555218135";
      }
      settings.put(ImpsConfigNames.MSISDN,msisdn);
    }
  }
  return settings;
}
 

Example 72

From project platform_packages_apps_mms, under directory /src/com/android/mms/.

Source file: MmsApp.java

  19 
vote

/** 
 * @return Returns the TelephonyManager.
 */
public TelephonyManager getTelephonyManager(){
  if (mTelephonyManager == null) {
    mTelephonyManager=(TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
  }
  return mTelephonyManager;
}
 

Example 73

From project platform_packages_providers_downloadprovider, under directory /src/com/android/providers/downloads/.

Source file: RealSystemFacade.java

  19 
vote

public boolean isNetworkRoaming(){
  ConnectivityManager connectivity=(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  if (connectivity == null) {
    Log.w(Constants.TAG,"couldn't get connectivity manager");
    return false;
  }
  NetworkInfo info=connectivity.getActiveNetworkInfo();
  boolean isMobile=(info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
  boolean isRoaming=isMobile && TelephonyManager.getDefault().isNetworkRoaming();
  if (Constants.LOGVV && isRoaming) {
    Log.v(Constants.TAG,"network is roaming");
  }
  return isRoaming;
}
 

Example 74

From project PowerTutor, under directory /src/edu/umich/PowerTutor/components/.

Source file: Threeg.java

  19 
vote

public Threeg(Context context,PhoneConstants phoneConstants){
  this.phoneConstants=phoneConstants;
  telephonyManager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  String interfaceName=phoneConstants.threegInterface();
  threegState=new ThreegStateKeeper();
  uidStates=new SparseArray<ThreegStateKeeper>();
  transPacketsFile="/sys/devices/virtual/net/" + interfaceName + "/statistics/tx_packets";
  readPacketsFile="/sys/devices/virtual/net/" + interfaceName + "/statistics/rx_packets";
  readBytesFile="/sys/devices/virtual/net/" + interfaceName + "/statistics/rx_bytes";
  transBytesFile="/sys/devices/virtual/net/" + interfaceName + "/statistics/tx_bytes";
  uidStatsFolder=new File("/proc/uid_stat");
  sysInfo=SystemInfo.getInstance();
}
 

Example 75

From project roboguice, under directory /roboguice/src/main/java/roboguice/config/.

Source file: RoboModule.java

  19 
vote

/** 
 * Configure this module to define Android related bindings.<br /> <br /> If you want to provide your own bindings, you should <strong>NOT</strong> override this method, but rather create a  {@link Module} implementationand add it to the configuring modules by overriding {@link roboguice.application.RoboApplication#addApplicationModules(List)}.<br />
 */
@SuppressWarnings("unchecked") @Override protected void configure(){
  bindScope(ContextScoped.class,contextScope);
  bind(ContextScope.class).toInstance(contextScope);
  bind(Context.class).toProvider(throwingContextProvider).in(ContextScoped.class);
  bind(Activity.class).toProvider(ActivityProvider.class);
  bind(AssetManager.class).toProvider(AssetManagerProvider.class);
  bind(SharedPreferences.class).toProvider(SharedPreferencesProvider.class);
  bind(Resources.class).toProvider(ResourcesProvider.class);
  bind(ContentResolver.class).toProvider(ContentResolverProvider.class);
  bind(EventManager.class).toInstance(eventManager);
  for (Class<?> c=application.getClass(); c != null && Application.class.isAssignableFrom(c); c=c.getSuperclass())   bind((Class<Object>)c).toInstance(application);
  bind(LocationManager.class).toProvider(new SystemServiceProvider<LocationManager>(Context.LOCATION_SERVICE));
  bind(WindowManager.class).toProvider(new SystemServiceProvider<WindowManager>(Context.WINDOW_SERVICE));
  bind(LayoutInflater.class).toProvider(new SystemServiceProvider<LayoutInflater>(Context.LAYOUT_INFLATER_SERVICE));
  bind(ActivityManager.class).toProvider(new SystemServiceProvider<ActivityManager>(Context.ACTIVITY_SERVICE));
  bind(PowerManager.class).toProvider(new SystemServiceProvider<PowerManager>(Context.POWER_SERVICE));
  bind(AlarmManager.class).toProvider(new SystemServiceProvider<AlarmManager>(Context.ALARM_SERVICE));
  bind(NotificationManager.class).toProvider(new SystemServiceProvider<NotificationManager>(Context.NOTIFICATION_SERVICE));
  bind(KeyguardManager.class).toProvider(new SystemServiceProvider<KeyguardManager>(Context.KEYGUARD_SERVICE));
  bind(SearchManager.class).toProvider(new SystemServiceProvider<SearchManager>(Context.SEARCH_SERVICE));
  bind(Vibrator.class).toProvider(new SystemServiceProvider<Vibrator>(Context.VIBRATOR_SERVICE));
  bind(ConnectivityManager.class).toProvider(new SystemServiceProvider<ConnectivityManager>(Context.CONNECTIVITY_SERVICE));
  bind(WifiManager.class).toProvider(new SystemServiceProvider<WifiManager>(Context.WIFI_SERVICE));
  bind(InputMethodManager.class).toProvider(new SystemServiceProvider<InputMethodManager>(Context.INPUT_METHOD_SERVICE));
  bind(SensorManager.class).toProvider(new SystemServiceProvider<SensorManager>(Context.SENSOR_SERVICE));
  bind(TelephonyManager.class).toProvider(new SystemServiceProvider<TelephonyManager>(Context.TELEPHONY_SERVICE));
  bindListener(Matchers.any(),resourceListener);
  bindListener(Matchers.any(),extrasListener);
  bindListener(Matchers.any(),viewListener);
  if (preferenceListener != null)   bindListener(Matchers.any(),preferenceListener);
  if (eventManager.isEnabled())   bindListener(Matchers.any(),new ObservesTypeListener(contextProvider,eventManager));
  requestInjection(eventManager);
  requestStaticInjection(Ln.class);
  requestStaticInjection(RoboThread.class);
  requestStaticInjection(RoboAsyncTask.class);
}
 

Example 76

From project Speedometer, under directory /android/src/com/google/wireless/speed/speedometer/util/.

Source file: PhoneUtils.java

  19 
vote

/** 
 * Returns "GSM", "CDMA". 
 */
private String getTelephonyPhoneType(){
switch (telephonyManager.getPhoneType()) {
case TelephonyManager.PHONE_TYPE_CDMA:
    return "CDMA";
case TelephonyManager.PHONE_TYPE_GSM:
  return "GSM";
case TelephonyManager.PHONE_TYPE_NONE:
return "None";
}
return "Unknown";
}
 

Example 77

From project TextSecure, under directory /src/org/thoughtcrime/securesms/service/.

Source file: MmsSender.java

  19 
vote

private void handleSendMmsContinued(MasterSecret masterSecret,SendReq[] requests){
  Log.w("MmsSenderService","Handling MMS send continuation...");
  MmsDatabase db=DatabaseFactory.getEncryptingMmsDatabase(context,masterSecret);
  String number=((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
  for (int i=0; i < requests.length; i++) {
    SendReq request=requests[i];
    long messageId=request.getDatabaseMessageId();
    long messageBox=request.getDatabaseMessageBox();
    if (MmsDatabase.Types.isSecureMmsBox(messageBox))     request=getEncryptedMms(masterSecret,request,messageId);
    sendMms(db,request,number,messageId,MmsDatabase.Types.isSecureMmsBox(messageBox));
  }
  if (this.pendingMessages.isEmpty())   finishConnectivity();
}
 

Example 78

From project tinfoil-sms, under directory /branches/prephase3/src/com/tinfoil/sms/.

Source file: Prephase3Activity.java

  19 
vote

/** 
 * Called when the activity is first created. 
 */
public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  ((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).listen(pSL,pSL.LISTEN_SIGNAL_STRENGTHS);
  MessageService.mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  MessageService.mNotificationManager.cancelAll();
  if (MessageService.dba == null) {
    MessageService.dba=new DBAccessor(this);
  }
  if (this.getIntent().hasExtra(MessageService.multipleNotificationIntent)) {
    this.getIntent().removeExtra(MessageService.multipleNotificationIntent);
  }
  if (this.getIntent().hasExtra(MessageService.notificationIntent)) {
    Intent intent=new Intent(this,MessageView.class);
    intent.putExtra(selectedNumberIntent,this.getIntent().getStringExtra(MessageService.notificationIntent));
    this.getIntent().removeExtra(MessageService.notificationIntent);
    startActivity(intent);
  }
  setContentView(R.layout.main);
  sharedPrefs=PreferenceManager.getDefaultSharedPreferences(this);
  MessageReceiver.myActivityStarted=true;
  list=(ListView)findViewById(R.id.conversation_list);
  msgList=MessageService.dba.getConversations();
  conversations=new ConversationAdapter(this,R.layout.listview_item_row,msgList);
  list.setAdapter(conversations);
  list.setOnItemClickListener(new OnItemClickListener(){
    public void onItemClick(    AdapterView<?> parent,    View view,    int position,    long id){
      Intent intent=new Intent(getBaseContext(),MessageView.class);
      intent.putExtra(Prephase3Activity.selectedNumberIntent,msgList.get(position)[0]);
      startActivity(intent);
    }
  }
);
}
 

Example 79

From project TweakGS2, under directory /src/net/sakuramilk/TweakGS2/Receiver/.

Source file: PhoneStateReceiver.java

  19 
vote

@Override public void onReceive(Context context,Intent intent){
  final String extraState=intent.getStringExtra(TelephonyManager.EXTRA_STATE);
  Log.d(TAG,"onReceive state=" + extraState);
  final NotificationSetting notificationSetting=new NotificationSetting(context);
  final boolean isBacklightFlash=notificationSetting.loadBlnOnIncoming();
  final SoundAndVibSetting soundAndVibSetting=new SoundAndVibSetting(context);
  final String vibNormalLevel=soundAndVibSetting.loadVibNormalLevel();
  final String vibIncomingLevel=soundAndVibSetting.loadVibIncomingLevel();
  if (TelephonyManager.EXTRA_STATE_RINGING.equals(extraState)) {
    if (isBacklightFlash) {
      Log.d(TAG,"start service");
      Intent serviceIntent=new Intent(context,KeyBacklightFlashService.class);
      context.startService(serviceIntent);
    }
    if (!Misc.isNullOfEmpty(vibNormalLevel) && !Misc.isNullOfEmpty(vibIncomingLevel)) {
      if (!vibNormalLevel.equals(vibIncomingLevel)) {
        soundAndVibSetting.setVibLevel(vibIncomingLevel);
      }
    }
  }
 else   if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(extraState) || TelephonyManager.EXTRA_STATE_IDLE.equals(extraState)) {
    if (isBacklightFlash) {
      Log.d(TAG,"stop service");
      Intent serviceIntent=new Intent(context,KeyBacklightFlashService.class);
      context.stopService(serviceIntent);
    }
    if (!Misc.isNullOfEmpty(vibNormalLevel) && !Misc.isNullOfEmpty(vibIncomingLevel)) {
      if (!vibNormalLevel.equals(vibIncomingLevel)) {
        soundAndVibSetting.setVibLevel(vibNormalLevel);
      }
    }
  }
}
 

Example 80

From project vlc-android, under directory /vlc-android/src/org/videolan/vlc/android/.

Source file: PhoneStateReceiver.java

  19 
vote

@Override public void onCallStateChanged(int state,String incomingNumber){
  if (state == TelephonyManager.CALL_STATE_RINGING) {
    LibVLC libVLC=LibVLC.getExistingInstance();
    if (libVLC != null && libVLC.isPlaying())     libVLC.pause();
  }
}