簡體   English   中英

錯過呼叫Android后如何開啟活動?

[英]How to open activity after Missed call android?

我已經開發了未接電話號碼的回電代碼。 在我的代碼中,我混淆了我打算從事新活動的位置。 我還在來電時打開活動。 但是在打錯電話的時候,我感到困惑。 那么,如何在未接來電后打開“活動”。

 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;

            }

        }

    }

}

這是完整的解決方案。

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();
                       }
          }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM