OneSignal - 无法通过单击通知打开已关闭的应用程序
OneSignal - Can't open closed app by clicking on notification
我无法通过单击 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>
通过在清单
上的应用程序标签内添加 OneSignal 推送应用程序 class 解决
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".OneSignalPushApplication"
android:theme="@style/AppTheme">
我无法通过单击 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>
通过在清单
上的应用程序标签内添加 OneSignal 推送应用程序 class 解决<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".OneSignalPushApplication"
android:theme="@style/AppTheme">