Android 推送通知未打开内置外部链接
我使用了完全相同的方法从通知中打开内容意图,但它是在FCM推送通知中打开我的应用程序本身 我的代码:Android 推送通知未打开内置外部链接,android,firebase,firebase-cloud-messaging,Android,Firebase,Firebase Cloud Messaging,我使用了完全相同的方法从通知中打开内容意图,但它是在FCM推送通知中打开我的应用程序本身 我的代码: public class ddkeysFirebaseMsgService extends FirebaseMessagingService { @Override public void onNewToken(String s) { super.onNewToken(s); String deviceToken = s; saveString("deviceToken
public class ddkeysFirebaseMsgService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
String deviceToken = s;
saveString("deviceToken", deviceToken);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent downloadLink = new Intent(Intent.ACTION_VIEW);
downloadLink.setData(Uri.parse("http://www.google.com"));
PendingIntent opendwdlink = PendingIntent.getActivity(getApplicationContext(), 0, downloadLink, 0);
String title = Objects.requireNonNull(remoteMessage.getNotification()).getTitle();
String body = remoteMessage.getNotification().getBody();
cloudNotificationManager.getDkInstance(getApplicationContext())
.cloudNotification(title, body, opendwdlink);
}
}
我的通知生成器在这里,如果这里有任何错误,请纠正我
public class cloudNotificationManager {
private static cloudNotificationManager dkInstance;
private final Context cloudcontext;
private cloudNotificationManager(Context context) {
cloudcontext = context;
}
public static synchronized cloudNotificationManager getDkInstance(Context context) {
if (dkInstance == null) {
dkInstance = new cloudNotificationManager(context);
}
return dkInstance;
}
public void cloudNotification(String title, String body, PendingIntent dwdlink) {
NotificationCompat.Builder cBuilder = new NotificationCompat.Builder(cloudcontext, ddKeys_init.CHANNEL_ID)
.setSmallIcon(R.drawable.ic_logo)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true);
if (dwdlink != null) {
cBuilder.setContentIntent(dwdlink);
}
NotificationManager notificationManager = (NotificationManager) cloudcontext.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(111, cBuilder.build());
}
}
}
我已经按照其他帖子中显示的方式进行了操作,但没有工作
我发现了我的问题
问题在于其他方面。如果我在我的应用程序中(应用程序已打开,任何活动),提供的链接将打开,但如果我没有打开我的应用程序(如其他应用程序中的am或主屏幕中的am),它将打开应用程序
我仍然不知道如何克服这个问题,在你采取行动之前,你必须检查URL是否完美。检查下面的代码,如何检查URL是否适合操作
public Intent getLinkIntent(String url)
{
Intent intent = null;
try {
String patter = "^(http|https|ftp)://.*$";
if (url.matches(patter)) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}else{
String newUrl = "https://" + url;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(newUrl));
}
}catch (Exception e){
e.printStackTrace();
}
return intent;
}
我发现了这个问题。让我检查一下是否有与我的问题相关的帖子。问题包含在我的邮件的最后一剂中。谢谢你的回答,我真的可以在我的应用程序中使用此代码:-)