Android Open Source - android-sms-relay Android Relay






From Project

Back to project page android-sms-relay.

License

The source code is released under:

GNU General Public License

If you think the Android project android-sms-relay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nyaruka.androidrelay;
/*  w w  w .  j av a  2  s .c o  m*/
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.preference.PreferenceManager;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.nyaruka.androidrelay.data.TextMessageHelper;

public class AndroidRelay extends Application {

  public static final String TAG = "AndroidRelay";
  
  private TextMessageHelper m_helper;
  private PhoneState m_phoneState;
  
    @Override
    public void onCreate() {
        super.onCreate();
        
        // migrate old preferences
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        if (prefs.contains("rapidsms_hostname")){
          Editor editor = prefs.edit();
          editor.putString("router_hostname", prefs.getString("rapidsms_hostname", null));
          editor.putString("router_password", prefs.getString("rapidsms_password", null));
          editor.putString("router_backend", prefs.getString("rapidsms_backend", null));
          
          editor.remove("rapidsms_hostname");
          editor.remove("rapidsms_password");
          editor.remove("rapidsms_backend");
          
          editor.commit();
        }
        
        m_helper = new TextMessageHelper(this);
        m_phoneState = new PhoneState();
        
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
        telephonyManager.listen(m_phoneState, PhoneStateListener.LISTEN_CALL_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    }
    
    public static void clearMessages(Context context){
      getHelper(context).clearMessages();
      MainActivity.clearMessages();
    }
        
    public static TextMessageHelper getHelper(Context context){
      return ((AndroidRelay)context.getApplicationContext()).m_helper;
    }
    
    public static PhoneState getPhoneState(Context context){
      return ((AndroidRelay)context.getApplicationContext()).m_phoneState;
    }
    
  public static String getVersionNumber(Context context) {
    String version = "?";
    try {
      PackageInfo packagInfo = context.getPackageManager()
          .getPackageInfo(context.getPackageName(), 0);
      version = packagInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
    };

    return version;
  }
  
  static class PhoneState extends PhoneStateListener {
    public int state = 0;
    public int strength = 0;
    
    public void onServiceStateChanged(ServiceState serviceState){
      Log.d(TAG, "Service State changed to: " + serviceState.getState() + " -- " + serviceState.getOperatorAlphaLong());
      state = serviceState.getState();
    }
    
    public void  onSignalStrengthsChanged(SignalStrength signalStrength){
      //Log.d(TAG, "Signal strength changed to: " + signalStrength.getGsmSignalStrength());
      strength = signalStrength.getGsmSignalStrength();
    }
  }
}




Java Source Code List

com.commonsware.cwac.wakeful.AlarmReceiver.java
com.commonsware.cwac.wakeful.WakefulIntentService.java
com.nyaruka.android.actionbarcompat.ActionBarActivity.java
com.nyaruka.android.actionbarcompat.ActionBarHelperBase.java
com.nyaruka.android.actionbarcompat.ActionBarHelperHoneycomb.java
com.nyaruka.android.actionbarcompat.ActionBarHelperICS.java
com.nyaruka.android.actionbarcompat.ActionBarHelper.java
com.nyaruka.android.actionbarcompat.SimpleMenuItem.java
com.nyaruka.android.actionbarcompat.SimpleMenu.java
com.nyaruka.androidrelay.AlarmListener.java
com.nyaruka.androidrelay.AndroidRelay.java
com.nyaruka.androidrelay.BootStrapper.java
com.nyaruka.androidrelay.CheckService.java
com.nyaruka.androidrelay.MainActivity.java
com.nyaruka.androidrelay.MessageListFragment.java
com.nyaruka.androidrelay.RebootService.java
com.nyaruka.androidrelay.RelayService.java
com.nyaruka.androidrelay.SMSModem.java
com.nyaruka.androidrelay.SettingsActivity.java
com.nyaruka.androidrelay.data.TextMessageHelper.java
com.nyaruka.androidrelay.data.TextMessage.java
com.nyaruka.log.LogCollector.java