【问题标题】:Redirect to a specific activity upon push notification is clicked on android studio在 android studio 上单击推送通知后重定向到特定活动
【发布时间】:2016-08-22 01:31:36
【问题描述】:

每当单击所有传入的推送通知时,我都在努力开发 Android 应用程序以将应用程序重定向到特定的活动页面。我是 android 开发新手,对我的编程感到抱歉。

以下是推送通知部分的 android manifest.xml。如果对此主题有任何评论,我们将不胜感激:-

<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<permission
    android:name="com.younginnovators.sjk.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. -->

<uses-permission android:name="com.younginnovators.sjk.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/icon"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- Push Notifications Receiver -->
    <receiver
        android:name=".backgroundservices.PushNotificationBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.younginnovators.sjk" />
        </intent-filter>
    </receiver>
    <!-- /Push Notifications Receiver -->


    <!-- Push Notifications Service -->
    <service android:name=".backgroundservices.PushnotificationService" />
    <!-- /Push Notifications Service -->

【问题讨论】:

  • “GCM”已过时。升级到 Firebase。文档更容易理解......顺便说一句,你没有说实际问题是什么。
  • 嗨muratgu,我的问题是我的应用程序在点击推送通知后当前进入主页,想知道我是否可以在点击推送通知时重定向到特定页面
  • 感谢您的建议,我从未尝试过firebase,会研究一下

标签: android redirect push-notification google-cloud-messaging push


【解决方案1】:

你可以试试这样的

NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);

Intent notificationIntent = new Intent(context, HomeActivity.class);

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
        | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent intent = PendingIntent.getActivity(context, 0,
        notificationIntent, 0);

notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-07
  • 1970-01-01
  • 2019-05-24
  • 2017-09-15
  • 1970-01-01
相关资源
最近更新 更多