Home > Mobile >  Help take a look at this service background is not running, over a period of time will be automatica
Help take a look at this service background is not running, over a period of time will be automatica

Time:11-03

 package com. Zzy. Eqclient. Service; 

The import android. App. Service;
The import android. The content. The Context;
The import android. Content. Intent;
The import android. OS. IBinder;
The import android. Telephony. CellLocation;
The import android. Telephony. PhoneStateListener;
The import android. Telephony. SignalStrength;
The import android. Telephony. TelephonyManager;
The import android. Telephony. Cdma. CdmaCellLocation;
The import android. Telephony. GSM. GsmCellLocation;
The import android. Util. Log;

The import com. Zzy. Eqclient. Util. ShareUtil;

Public class StrengthService extends the Service {

@ Override
Public IBinder onBind (Intent Intent) {
return null;
}

@ Override
Public void onCreate () {
Super. The onCreate ();
Final TelephonyManager TelephonyManager=(TelephonyManager) getApplicationContext () getSystemService (Context. TELEPHONY_SERVICE);
TelephonyManager. Listen (new MyPhoneListener (), PhoneStateListener. LISTEN_SIGNAL_STRENGTHS);
}

@ Override
Public void onDestroy () {
Super. OnDestroy ();
System. Out.println (" service be destroyed... ");
}

//@ Override
//public int onStartCommand (Intent Intent, int flags, int startId) {
//return super. OnStartCommand (intent, flags, startId);
//}

Private class MyPhoneListener extends PhoneStateListener {
@ Override
Public void onCellLocationChanged (CellLocation location) {
If (the location instanceof GsmCellLocation) {
Int cid=((GsmCellLocation) location). GetCid ();
Log. I (" access to the CID: ", CID + "");
ShareUtil. PutInt (getApplicationContext (), "cid", cid);
{} else if (the location instanceof CdmaCellLocation)
Int id=((CdmaCellLocation) location). GetBaseStationId ();
Log. I (get ID: "", ID +" ");
ShareUtil. PutInt (getApplicationContext (), "id", id);
}
}

@ Override
Public void onSignalStrengthsChanged (SignalStrength SignalStrength) {
//this ltedbm is 4 g signal value
String signalinfo=signalStrength. ToString ();
String [] parts=signalinfo. Split (" ");
Int DBM=Integer. ParseInt (parts [9]);
Int asu=140 + DBM;
If (asu==0) {
//the DBM is 2 g and 3 g signal value
Asu=signalStrength. GetGsmSignalStrength ();
DBM=- 113 + 2 * asu;
}
ShareUtil. PutInt (getApplicationContext (), "DBM, DBM);
ShareUtil. PutInt (getApplicationContext (), "asu," asu);
Log. I (get to DBM: "", DBM +" \ n "+" access to the ASU: "+ ASU +" ");
Super. OnSignalStrengthsChanged (signalStrength);
}
}
}


Open the activity, the normal operation of the service, the program won't cut to the background continue to print log, why

CodePudding user response:

Is anyone here, try using dynamic radio also not line
  • Related