OneSignal - cannot open activity after push clicked

放肆的年华 提交于 2019-12-05 04:31:16
dsouza

I think the better way, add line bellow in your activity:

<application ...>
   <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
</application>

By default OneSignal will open the launcher Activity when a notification is opened. In your case your ImageDetail Activity is probably starting and then the launcher Activity is being displayed over it.

You will need to add com.onesignal.NotificationOpened.RECEIVE to a BroadcastReceiver to override the default action of opening the launcher Activity. See OneSignal's documenation on Changing the open action of a notification for the required manifest entries and more details. Your BroadcastReceiver does not need any code to take any action as you already have a OneSignal.NotificationOpenedHandler setup in your Application class. The manifest and receiver just need to be present to override the default behavior.

Yes finally. I get the push information and redirect.

       Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    Log.d("mesaj", "Sonuç: " + bundle);


    if (bundle != null) {
        try {
            Log.d("mesaj", "String bundle : " + bundle.getString("onesignal_data"));

            String jsonData = bundle.getString("onesignal_data");
            Log.d("mesaj", "json: " + jsonData);

            if (jsonData != null) {
                JSONArray json = new JSONArray(jsonData);

                Log.d("mesaj", "json size: " + json.length());

                if (json.length() < 2) {

                    Log.d("mesaj", " siz < 2 json get0: " + json.get(0));

                } else {

                    for (int i = 1; i < json.length(); i++) {
                        object = json.getJSONObject(i);
                        Log.d("mesaj", "json details: " + object.getString("custom") + object.getString("alert"));
                        String obj = new JSONObject(object.getString("custom")).getString("a");
                        String action = new JSONObject(obj).getString("action");
                        String actionid = new JSONObject(obj).getString("id");

                        if (action.equals("openboard")) {
                            Intent intent2 = new Intent(MainActivity.this, BoardDetail.class);
                            intent2.putExtra("boardid", actionid);
                            intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent2);
                        } else if (action.equals("openimage")) {
                            Intent intent2 = new Intent(MainActivity.this, ImageDetail.class);
                            intent2.putExtra("imageid", actionid);
                            intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent2);
                        } else if (action.equals("openblog")) {
                            Intent intent2 = new Intent(MainActivity.this, BlogDetail.class);
                            intent2.putExtra("blogid", actionid);
                            intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent2);
                        }
                    }

                }

            }
        } catch (JSONException e) {
            e.printStackTrace();
            Log.d("Push Exception : ", String.valueOf(e));
        }

    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!