【发布时间】:2019-08-20 00:35:34
【问题描述】:
我已经编写了创建通知的代码。
我希望通知直接打开一个名为“StepsFragment”的片段类。
但是,每当我点击通知时,什么都没有发生。 这可能是什么问题?
我在 Stack Overflow 上尝试过以下解决方案:
Receive a notification issue and open a fragment
How to open current fragment from notification?
Open a dialog fragment from childfragment from Notification
它们导致我遇到语法错误,因此我无法构建我的项目。
这是我用来打开通知片段的代码。
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String input = intent.getStringExtra("inputExtra");
Intent notificationIntent = new Intent(this, StepsFragment.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Steps Tracker")
.setContentText("Steps tracked : " + input )
.setSmallIcon(R.drawable.steps)
.setContentIntent(pendingIntent)
.build();
startForeground(1,notification);
return START_NOT_STICKY;
}
如何打开通知,以便在我点击通知时将我带到 StepsFragment 而不是什么都不做?
【问题讨论】:
标签: android android-intent notifications fragment