1
나는 전화 상태를 듣고 그에 따라 행동하는 BroadcastReceiver를 만들었습니다.PhoneStateListener 및 BroadcastReceiver
여기서 문제는 내 데이터베이스에서 적절한 값을하지 않는 것, 처음부터 유휴 상태에서 토스트 두 번 보여주고, 두 번째 호출 후 네 번 등을 보여주고 있다는 점이다...
내가 거기에 내 수업에 문제가있다하지만 난 여기에
코드 조각이 무엇인지 ... 알아낼 수 없습니다 같아요public class PhoneListener extends BroadcastReceiver{
private DBAdapter db;
private Cursor data;
private Cursor options;
private int activer;
private int mouvement;
private int verticalite;
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(new CustomPhoneStateListener(context), PhoneStateListener.LISTEN_CALL_STATE);
}
public void stopService(Context context){
Intent alerte = new Intent(context, SensorOrientation.class);
alerte.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.stopService(alerte);
}
public void startService(Context context){
Intent alerte = new Intent(context, SensorOrientation.class);
alerte.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(alerte);
}
public void startnotif(Context context){
Intent intent = new Intent(context, SecuriteHauteReboot.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(intent);
}
public class CustomPhoneStateListener extends PhoneStateListener {
//private static final String TAG = "PhoneStateChanged";
Context context; //Context to make Toast if required
public CustomPhoneStateListener(Context context) {
super();
this.context = context;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
db = new DBAdapter(context);
data = db.selectWidget();
options = db.selectVerticalite();
activer = data.getInt(data.getColumnIndex("activer"));
mouvement = options.getInt(options.getColumnIndex("activer_alarme_mouvement"));
verticalite = options.getInt(options.getColumnIndex("activer_alarme_verticalite"));
data.close();
options.close();
//when Idle i.e no call
Toast.makeText(context,
String.format(" "+mouvement+" "+activer),
Toast.LENGTH_SHORT).show();
if(activer == 1){
if(mouvement == 1 || verticalite == 1){
Toast.makeText(context,
String.format("and I'm here...."),
Toast.LENGTH_SHORT).show();
startService(context);
startnotif(context);
}
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//when Off hook i.e in call
//Make intent and start your service here
if (activer == 1){
if(mouvement == 1 || verticalite == 1){
stopService(context);
}
}
break;
case TelephonyManager.CALL_STATE_RINGING:
//when Ringing
if (activer == 1){
if(mouvement == 1 || verticalite == 1){
Toast.makeText(context,
String.format("and I'm here...."),
Toast.LENGTH_SHORT).show();
stopService(context);
}
}
break;
default:
break;
}
}
}
}
감사합니다. soulreaver! 그것은 정확히 문제였습니다. 너무 많은 정적 값을 사용하지 않기 때문에 단순히 서비스를 만들었고 매력처럼 작동합니다! 문제 해결됨 :) – MademoiselleLenore