OneSignal - 无法通过单击通知打开已关闭的应用程序
Posted
技术标签:
【中文标题】OneSignal - 无法通过单击通知打开已关闭的应用程序【英文标题】:OneSignal - Can't open closed app by clicking on notification 【发布时间】:2018-03-30 11:25:57 【问题描述】:我无法通过单击 OneSignal 中的通知来打开我的应用程序。关闭应用程序时没有任何反应;仅当我在应用程序中(打开)时才有效。我没有收到任何日志错误。我究竟做错了什么?任何帮助都会很棒,我坚持这一点。
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>
【问题讨论】:
参考此链接***.com/questions/35105612/… @MohammadAli 仍然无法打开 日志中有任何错误?? @ALTegani 是的,我在日志中没有找到,这很奇怪 【参考方案1】:通过在清单的应用程序标签内添加 OneSignalPushApplication 类来解决
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".OneSignalPushApplication"
android:theme="@style/AppTheme">
【讨论】:
以上是关于OneSignal - 无法通过单击通知打开已关闭的应用程序的主要内容,如果未能解决你的问题,请参考以下文章
Android 应用程序未在 Com.onesignal 通知中启动单击