简体   繁体   中英

Can i show a custom view from within a broadcast receiver in the background?

I have a broadcast receiver that works in the background of my app and I want to show a custom popup view on the phone every time it triggers. (every time the onReceive method is called)

can I show a custom view of my own (just some pic with some text in it) on top of the phone from within the BroadcastReciever? (very similar to what the messenger is doing when u get a message in facebook)

do you have a code example of how I can achieve that?

here is my receiver

public class PhoneStateReciver extends BroadcastReceiver {


    @Override
    public void onReceive(Context context, Intent intent) {

        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

        if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
            //Toast.makeText(context,"Ringing State Number is -"+incomingNumber,Toast.LENGTH_SHORT).show();
            getContactList(context, incomingNumber);
        }
        if ((state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))){
            Toast.makeText(context,"Received State",Toast.LENGTH_SHORT).show();
        }
        if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
            Toast.makeText(context,"Idle State",Toast.LENGTH_SHORT).show();
        }


    }
}

您可以在这种情况下使用小部件https://www.raywenderlich.com/33-android-app-widgets-tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM