FCM Android-点击通知-打开webview
我使用的模板: 实际上,该模板没有fcm功能。我手动添加了它。我在这里引用,以便您查看mainactivity文件 我想在用户单击我的通知时打开特定链接 我的通知生成器是:FCM Android-点击通知-打开webview,android,firebase-cloud-messaging,android-webview,Android,Firebase Cloud Messaging,Android Webview,我使用的模板: 实际上,该模板没有fcm功能。我手动添加了它。我在这里引用,以便您查看mainactivity文件 我想在用户单击我的通知时打开特定链接 我的通知生成器是: // pending implicit intent to view url Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// pending implicit intent to view url
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("LINK",link);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, ADMIN_CHANNEL_ID)
.setLargeIcon(BitmapFactory.decodeResource(getBaseContext().getResources(), R.mipmap.ic_launcher)) //set it in the notification
.setSmallIcon(R.mipmap.ic_launcher) //a resource for your custom small icon
.setContentTitle(title) //the "title" value you sent in your notification
.setContentText(message) //ditto
.setContentIntent(pendingIntent)
.setAutoCancel(true) //dismisses the notification on click
.setSound(defaultSoundUri)
.setStyle(new NotificationCompat.BigPictureStyle()
.setSummaryText(message)
.bigPicture(bitmap)
.setBigContentTitle(title));
我在MainActivity中尝试了以下方法:
Intent intent = getIntent();
if (getIntent().getExtras() != null && getIntent().getExtras().getString("link", null) != null && !getIntent().getExtras().getString("link", null).equals("")) {
String url = null;
if (getIntent().getExtras().getString("link").contains("http")) {
url = getIntent().getExtras().getString("link");
} else {
url = "http://" + getIntent().getExtras().getString("link");
}
aswm_view(url, false);
} else {
//Rendering the default URL
aswm_view(ASWV_URL, false);
}
(near lines 250)
但是,一切都不起作用。有人能帮我吗
谢谢。我认为您应该使用
intent.getString()
而不是intent.getExtras().getString()
:
根据您的意图。getExtras()
将返回null
,因为它从未被分配
返回以前使用putExtra()添加的所有附加的映射,如果为空,则返回null
没有添加任何内容
意向。额外(“链接”,链接)
字符串url=getIntent().getString(“链接”,null)
这是我的错误。(链接和链接是不同的
我为这个愚蠢的错误花了将近一周的时间。我很快就会尝试的。
Intent intent = getIntent();
String url = getIntent().getString("link", null)
if (url != null) {
if (!url.startsWith("http")) {
url = "http://" + url;
}
aswm_view(url, false);
} else {
//Rendering the default URL
aswm_view(ASWV_URL, false);
}