OneSignal-无法通过单击通知来打开已关闭的应用程序 [英] OneSignal - Can't open closed app by clicking on notification

查看:147
本文介绍了OneSignal-无法通过单击通知来打开已关闭的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过单击OneSignal中的通知来打开我的应用程序.关闭应用程序后无任何反应.仅当我在应用程序中(打开)时,它才有效.我没有任何日志错误.我究竟做错了什么?任何帮助都将非常有用,我对此一无所知.

I can't open my app by clicking on a notification in OneSignal. Nothing happens when the app is closed; it only works if I'm in the app (open). I don't get any log errors. What am I doing wrong? Any help would be great, I'm stuck on this.

public class OneSignalPushApplication extends Application{
    @Override
    public void onCreate() {
        super.onCreate();

        // Logging set to help debug issues, remove before releasing your app.
        //OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.WARN);

        OneSignal.startInit(this)
                .setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
                .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
                .autoPromptLocation(true)
                .init();
    }

    private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
        // This fires when a notification is opened by tapping on it.
        @Override
        public void notificationOpened(OSNotificationOpenResult result) {

            String title=result.notification.payload.title;
            String desc=result.notification.payload.body;

            Log.d("xiomi", "Received Title "+title);
            Log.d("xiomi", "Received Desc "+desc);


            Intent intent = new Intent(getApplicationContext(), Intro.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra("push_title", title);
            intent.putExtra("push_message", desc);
            startActivity(intent);

        }
    }
}

我的Intro调用最后调用MainActivity:

public class Intro extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getIntent().setAction("Already created");
        String title = getIntent().getStringExtra("title");
        Toast.makeText(this, title , Toast.LENGTH_LONG).show();



                EasySplashScreen config = new EasySplashScreen(Intro.this)
                        .withFullScreen()
                        .withTargetActivity(MainActivity.class)
                        .withSplashTimeOut(2000)
                        .withBackgroundResource(R.drawable.spash);


                View easySplashScreenView = config.create();
                setContentView(easySplashScreenView);


        }



    @Override
    protected void onResume() {
       // Log.v("Resume", "onResume");
        super.onResume();
    }

}

该应用的清单:

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

推荐答案

通过在清单的application标记内添加OneSignalPushApplication类来解决

Soved by adding the OneSignalPushApplication class inside application tag on the manifest

<application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:name=".OneSignalPushApplication"
        android:theme="@style/AppTheme">

这篇关于OneSignal-无法通过单击通知来打开已关闭的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆