我已经开发了对未接来电号码的回拨代码。在我的代码中,我混淆了我对新活动的意图。我也在来电时开放活动。但在Miscall时我感到困惑。 那么如何在未接来电后打开活动。
Context c;
boolean cut, flag = true;
PhoneStateListener listener;
SharedPreferences prefs;
static boolean ring = false;
static boolean callReceived = false;
public MyPhoneStateListener(Context c) {
// TODO Auto-generated constructor stub
this.c = c;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
Log.d("main", "incoming call receiver.");
PowerManager pm = (PowerManager) c
.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
if (state == TelephonyManager.CALL_STATE_RINGING) {
Log.d("flags", "flags: " + flag);
if (flag) {
cut = true;
flag = false;
CheckMissCall call = new CheckMissCall(c);
call.setName(incomingNumber);
call.setNumber4Sms(incomingNumber);
call.setContactPhoto();
Log.d("main", "state ringing");
prefs = PreferenceManager.getDefaultSharedPreferences(c);
if (!prefs.getBoolean("main_state", false)) {
return;
}
if (!isScreenOn && CheckMissCall.isRunning) {
return;
}
else {
Log.d("main", "EEEEEEEEEEEEEEEE: Unlock hud");
Intent in=new Intent(c, Unlock_hud.class);
in.setFlags( Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
c.startService(in);
}
}
}
else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
Log.d("main", "offhook");
}
else {
if (cut && CheckMissCall.isShown) {
Log.d("main", "Cutted");
c.stopService(new Intent(c, Unlock_hud.class));
flag = true;
}
}
}
}
答案 0 :(得分:2)
这是完整的解决方案。
<强> Start new activity instead of Toast Message in below code.
强>
HapPy编码.. !!
public class IncommingCallReceiver extends BroadcastReceiver
{
static boolean ring=false;
static boolean callReceived=false;
@Override
public void onReceive(Context mContext, Intent intent)
{
// Get the current Phone State
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(state==null)
return;
// If phone state "Rininging"
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
ring =true;
// Get the Caller's Phone Number
Bundle bundle = intent.getExtras();
callerPhoneNumber= bundle.getString("incoming_number");
}
// If incoming call is received
if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
{
callReceived=true;
}
// If phone is Idle
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE))
{
// If phone was ringing(ring=true) and not received(callReceived=false) , then it is a missed call
if(ring==true&&callReceived==false)
{
Toast.makeText(mContext, "It was A MISSED CALL from : "+callerPhoneNumber, Toast.LENGTH_LONG).show();
}
}
}