0

cellid gsmの場所が更新されたら、データベースに書き込みたいだけです 。この願いのために、以下に示すように、サービス クラスを実装しようとしました。gsm の場所が自動的に検出され、関数、つまり C() が書き込まれるようにするにはどうすればよいでしょうか。

私の最初の仕事;

public class GpsCell extends Service{
TelephonyManager tel;

@Override
public void onCreate() {
    super.onCreate();

    tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = (GsmCellLocation)telephonyManager.getCellLocation();

}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
    return super.onStartCommand(intent, flags, startId);        
}
4

1 に答える 1

1

PhoneStateListener.LISTEN_CELL_LOCATIONcellid の更新を取得するリスナーを登録できます。

public class GpsCellLogger extends Service{
  TelephonyManager tel;

  @Override
  public void onCreate() {
    super.onCreate();

    tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

    tel.listen(myListener , PhoneStateListener.LISTEN_CELL_LOCATION);

    GsmCellLocation location = (GsmCellLocation)telephonyManager.getCellLocation();


  }
  PhoneStateListener myListener = new PhoneStateListener() {
      public void onCellLocationChanged(CellLocation p_CellLocation)
      {
        //write to database
      }
 }

}
于 2013-02-13T08:08:12.590 に答える