我无法通过点击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
的{{1}}来电:
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();
}
}
答案 0 :(得分: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">