FCM Android - 点击通知 - 打开 webview [英] FCM Android - On click Notification - Open webview
问题描述
我使用的模板:https://github.com/mgks/Android-SmartWebView一>实际上,模板没有 fcm 功能.我是手动添加的.我提到这里是为了让您查看 mainactivity 文件.
Template which I was using : https://github.com/mgks/Android-SmartWebView Actually, the template has no fcm feature. I added it manually. I referred here so as you look into mainactivity file.
我想在用户点击我的通知时打开特定链接.
I want to open specific link when user clicks my notification.
我的通知生成器是:
// 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 中试过这个:
I tried this in 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)
但是,没有任何效果.有人可以帮我吗?
But, Nothing is working. Can anyone please help me?
谢谢.
推荐答案
intent.putExtra("LINK",link);
intent.putExtra("LINK",link);
String url = getIntent().getString("link", null)
String url = getIntent().getString("link", null)
这是我的错误.(链接和链接不同.
This is my mistake. (LINK & link are different.
我花了将近 1 周的时间来解决这个愚蠢的错误.
I spend near 1 weeks for this silly mistake.
这篇关于FCM Android - 点击通知 - 打开 webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!