简体   繁体   中英

Android activity open while push notification is received without clicking on push

Here is my question.

I want to open the Activity while any GCM push notification is received without clicking on push notification in android. When i get the instance of Activity at that time i can open the Activity but when application is killed then also i want to open the activity. How can i achieve this.

See the attachment of one of good application 在此处输入图片说明

When any push notification comes i want to open something like this.

Any help would be appreciated.

create a custom dialog box in separate class from following code`

public class CustomeDialog {
    Context context;
    public CustomeDialog(Context context) {
        this.context = context;
    }
public void creatDialogBoxWihList() {
         final Dialog dialog = new Dialog(context);
         dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
         dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
         dialog.setCancelable(false);
         dialog.setContentView(R.layout.dialog_layout);
       // dialog.getWindow().setBackgroundDrawable(null);  //for making dialog to fill window completely

         Button ok = (Button) dialog.findViewById(R.id.ok);
         Button cancel = (Button) dialog.findViewById(R.id.can);

         ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
         });

         dialog.show();
         Window window = dialog.getWindow();

        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
   }}

add permission in android menifests

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

Call this class from BroadcastReceiver onReceive function. if you want help in this. use this link

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