推送通知点击不打开我的愿望活动

时间:2016-06-06 06:58:41

标签: android notifications android-notifications

点击通知时打开我的愿望活动时遇到问题。当应用程序处于活动状态时工作正常并打开我的欲望活动。但是当我将应用程序置于暂停状态或最小化它时,总是打开我的启动活动。

这是我的通知代码

private void createNotification(String title, String body) 
{
    Context context = getBaseContext();
    if(sharedata.getDrivermode()) {
        if (sharedata.getDrivermode() == true) {

            notificationIntent = new Intent(this, MapFragmentDriver.class);
            notificationIntent.putExtra("dialog", "true");
        }

   if (sharedata.getDrivermode() == false) {
            if (pntype.equals("jr-driverDroped")) {
                notificationIntent = new Intent(this, Ratingscreenpassenger.class);
            } else {
                notificationIntent = new Intent(this, MapFragment.class);
            }
        }
    }

     notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setAutoCancel(true)
            .setPriority(2)
            .setTicker(title)
            .setContentText(body)
            .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT))
            .setWhen(System.currentTimeMillis())
            .setContentTitle(title)
            .setDefaults(Notification.DEFAULT_ALL);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, builder.build());
}

这是我的清单文件

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.live.wheelz">

    <permission
        android:name="com.javapapers.currentlocationinmap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <permission android:name="com.live.wheelz.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.live.wheelz.permission.C2D_MESSAGE" />
    <uses-feature
        android:name="android.hardware.touchscreen.multitouch"
        android:required="false" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:name="com.live.utilities.Config"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_api_key" />

        <activity
            android:name=".SplashActivity"
            android:screenOrientation="portrait"

            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait"
            android:noHistory="true"
            ></activity>
        <activity
            android:name=".VerifyToken"
            android:screenOrientation="portrait"></activity>

        <activity
            android:name=".SetPassword"
            android:screenOrientation="portrait"></activity>
        <activity
            android:name=".Profile"
            android:screenOrientation="portrait"
            ></activity>
        <activity
            android:name=".Login"
            android:screenOrientation="portrait"></activity>
        <activity
            android:name=".ForgetPassword"
            android:screenOrientation="portrait"></activity>
        <activity
            android:name=".ResetPassword"
            android:screenOrientation="portrait"></activity>
        <activity
            android:name=".ResetPasswordForget"
            android:screenOrientation="portrait"></activity>
        <activity
            android:name="com.live.utilities.GalleryUtil"
            android:screenOrientation="portrait"></activity>
        <activity
            android:name=".VheelzRide"
            android:screenOrientation="portrait"></activity>
        <activity
            android:name=".CreditCardNo"
            android:screenOrientation="portrait"></activity>
        <activity
            android:name=".MapFragment"
            android:screenOrientation="portrait"
            ></activity>
        <activity
            android:name=".BaseActivity"
            android:screenOrientation="portrait"></activity>
        <activity
            android:name=".VheelzRideActive"
            android:screenOrientation="portrait"
            ></activity>
        <activity
            android:name=".MapFragmentDriver"
            android:screenOrientation="portrait"
            android:exported="true"
            android:launchMode="singleTop"
            ></activity>
        <activity
            android:name=".Ratingscreendriver"
            android:screenOrientation="portrait"
            android:exported="true"
            ></activity>
        <activity
            android:name=".Ratingscreenpassenger"
            android:screenOrientation="portrait"
            android:exported="true"
            ></activity>
        <activity
            android:name=".DialogActivityDriver"
            android:theme="@android:style/Theme.Holo.Light.Dialog"
            android:screenOrientation="portrait"
            >
        </activity>
        <activity
            android:name=".DialogActivityCancel"
            android:theme="@android:style/Theme.Holo.Light.Dialog"
            android:screenOrientation="portrait"
            >
        </activity>

        <service
            android:name="com.live.utilities.GcmMessageHandler"

            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.live.wheelz" />
            </intent-filter>
        </receiver>

        <service
            android:name=".MyInstanceIDListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID"/>
            </intent-filter>
        </service>
        <service
            android:name="com.live.locationservices.LocationServiceDriver"
            android:exported="false" />
        <service
            android:name="com.live.locationservices.LocationService"
            android:exported="false" />
        <service android:name=".RegistrationIntentService" android:exported="false"/>

    </application>

</manifest>

3 个答案:

答案 0 :(得分:0)

添加到意图标志:

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

答案 1 :(得分:0)

请尝试这些,它将重定向愿望活动

NotificationManager mNotificationManager = (NotificationManager) this
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.logo)

                        .setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                        .setContentText(msg);
                mBuilder.setContentIntent(contentIntent);
                mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

答案 2 :(得分:0)

我使用有效负载中的数据而非通知数据对象遵循您的代码流,您可以使用推送通知执行任何操作。我使用以下代码而不是通知,并从服务器发送数据对象而不是通知对象。

String payloads = data.getString("data");