简体   繁体   English

我可以在后台的广播接收器中显示自定义视图吗?

[英]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) (每次调用 onReceive 方法时)

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?我可以从 BroadcastReciever 中的手机顶部显示我自己的自定义视图(只是一些带有一些文字的图片)吗? (very similar to what the messenger is doing when u get a message in facebook) (非常类似于当您在 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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