我想在一个活动中打开不同的文章,使用我通过通知发送的不同帖子id。我可以点击通知打开一个帖子,但打开同一个活动后,我无法打开或处理第二个通知。
public void onMessageReceived(RemoteMessage remoteMessage) {
sharedPref = new SharedPref(this);
if (sharedPref.getNotification()) {
// play vibration
if (sharedPref.getVibration()) {
((Vibrator) getSystemService( Context.VIBRATOR_SERVICE)).vibrate(VIBRATION_TIME);
}
RingtoneManager.getRingtone(this, Uri.parse(sharedPref.getRingtone())).play();
JSONObject json = null;
if (remoteMessage.getData().size() > 0) {
Map<String, String> data = remoteMessage.getData();
FcmNotif fcmNotif = new FcmNotif();
fcmNotif.setTitle(data.get("title"));
fcmNotif.setPosttitle( data.get("posttitle"));
fcmNotif.setPost_id(data.get("post_id"));
fcmNotif.setPost_slug( data.get( "post_slug" ) );
fcmNotif.setCat_name(data.get("cat_name"));
fcmNotif.setType(data.get("type"));
if(!data.get("cat_name").equals("No Notification"))
{
displayNotificationIntent(fcmNotif);
}
}
}
}
private void displayNotificationIntent(FcmNotif fcmNotif) {
Intent intent = new Intent(this, MainActivity.class);
if (fcmNotif.getPost_id() != "tnd") {
intent = new Intent(this, PostDetails.class);
intent.putExtra( "PostId",fcmNotif.getPost_id());
intent.putExtra( "type",fcmNotif.getType() );
intent.putExtra( "PostSlug",fcmNotif.getPost_slug() );
intent.putExtra("CategoryName",fcmNotif.getCat_name());
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(fcmNotif.getTitle());
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(fcmNotif.getPosttitle()));
builder.setContentText(Html.fromHtml(fcmNotif.getPosttitle()));
builder.setSmallIcon( R.mipmap.custom_icon);
builder.setDefaults( Notification.DEFAULT_LIGHTS);
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
{
builder.setPriority(Notification.PRIORITY_HIGH);
}
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
int unique_id = (int) System.currentTimeMillis();
notificationManager.notify(unique_id, builder.build());
}
注意:我试过使用intent。setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
可以轻松打开所有通知,但当按下HOME(主页)按钮并从抽屉重新打开应用程序时,它会打开第一个通知,而不是最后一个打开的通知。
XML很简单`
android:name=".PostDetails"
android:label="@string/back"
android:parentActivityName=".AllCategoryList"
android:screenOrientation="portrait"/>
<activity`
终于找到了解决方案:
Intent backIntent = new Intent(this, HomeActivity.class);
backIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent notificationIntent = new Intent(this, NextActivity.class);
final PendingIntent pendingIntent = PendingIntent.getActivities(this, 1,
new Intent[] {backIntent, notificationIntent}, PendingIntent.FLAG_ONE_SHOT);
源自@Jitendra ramoliya的不同问题
我想按下mainactivity中的一个按钮,该按钮将启动一个包含片段的新活动的意图。我写了一个主要的活动。带有main活动和第二个_活动按钮的xml。带有片段的xml。当我单击按钮时,第二个活动将由于xml中的片段而崩溃。我已经添加了一个标志,但它没有帮助。该应用程序的想法是通过按下主活动中的按钮,在第二个活动中获取谷歌地图。 我希望你能帮助我:/ 主要活动: 亚活性: activity_mai
我试图在netty中模拟http握手,但客户端无法发送第二个请求。这就是流程 这是代码https://github.com/Tonghua-Li/Netty-Handshake-Test/tree/master/src/main/java 服务器和客户端日志位于git repo的根文件夹中https://github.com/Tonghua-Li/Netty-Handshake-Test/blob
我把Visual Studio从社区2015升级到了社区2017。现在,当我编译时,我得到错误消息,说“Error (active) E1696无法打开源文件“stdio.h”,引用的行如下所示: 如果我创建一个新项目,则会找到 stdio.h。 因此,我查看了项目配置属性- 所以似乎需要设置VC_IncludePath,但我找不到任何设置的地方。请注意,我找不到宏的,这可能是因为我使用的是 Vi
我需要这段java代码的帮助。我有三个场景登录场景,管理场景,和玩家场景。当我运行程序并输入用户和密码时,第二个应该打开。现在的问题是,第二个场景没有打开。它甚至连接到数据库,但第二个场景没有打开。我已经检查了代码,我看不出有什么问题。能不能请一些帮帮我,发生了什么事。
当第二次打开我的SupportMapFragment(Android maps v2)时(调用setContentView),我得到以下错误: 我不知道这个错误是什么意思。有人能解释一下吗?
在我的应用程序中,我有2个transactionManager,创建如下: 在同一个文件中,我有注释驱动的声明: 为了简化admin transactionManager的可用性,我创建了一个简单的注释: 这是我的带有事务注释的方法: 由于有接口,该方法是从另一个类调用的。bean由Spring@Autowired注释注入。jdbcTemplate对象是用以下代码创建的: 我的问题是当我执行jdb