简体   繁体   中英

How to open specific Activity when user clicks on Notification comes from Xtify?

I am using Xtify to send push notifications to Android App, I have a problem with Xtify SDK for GCM

when the push notification comes from Xtify and the user clicked on it, it opens the Main Activity of the App, but I need it to open a specific Activity. How should I use it ?

And Here is My Manifiest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Knockbook.CookingRecipes"
android:versionCode="2"
android:versionName="1.1" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

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

<permission
    android:name="com.Knockbook.CookingRecipes.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.Knockbook.CookingRecipes.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        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=".AdsActivity" />

    <receiver android:name=".XtifyNotifier" >
        <intent-filter>
            <action android:name="com.xtify.sdk.NOTIFIER" />
        </intent-filter>
    </receiver>

    <provider
        android:name="com.xtify.sdk.db.Provider"
        android:authorities="com.Knockbook.CookingRecipes.XTIFY_PROVIDER"
        android:exported="false" />

    <receiver android:name="com.xtify.sdk.c2dm.C2DMBroadcastReceiver" >
        <intent-filter android:permission="com.google.android.c2dm.permission.SEND" >
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="com.Knockbook.CookingRecipes" />
        </intent-filter>
        <intent-filter android:permission="com.google.android.c2dm.permission.SEND" >
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.Knockbook.CookingRecipes" />
        </intent-filter>
    </receiver>
    <receiver android:name="com.xtify.sdk.NotifActionReceiver" />
    <receiver android:name="com.xtify.sdk.wi.AlarmReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

    <service android:name="com.xtify.sdk.location.LocationUpdateService" />
    <service android:name="com.xtify.sdk.c2dm.C2DMIntentService" />
    <service android:name="com.xtify.sdk.alarm.MetricsIntentService" />
    <service android:name="com.xtify.sdk.alarm.TagIntentService" />
    <service android:name="com.xtify.sdk.alarm.RegistrationIntentService" />
    <service android:name="com.xtify.sdk.alarm.LocationIntentService" />
</application>

also this is XtifyNotifier

package com.Knockbook.CookingRecipes;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PowerManager;
import android.sax.StartElementListener;
import android.util.Log;

import com.xtify.sdk.NotifActionReceiver;
import com.xtify.sdk.NotificationsUtility;
import com.xtify.sdk.api.NotificationsPreference;
import com.xtify.sdk.api.XtifyBroadcastReceiver;
import com.xtify.sdk.api.XtifySDK;

public class XtifyNotifier extends XtifyBroadcastReceiver {

@Override
protected void onC2dmError(Context arg0, String arg1) {
    // TODO Auto-generated method stub

}

@Override
protected void onMessage(Context context, Bundle bundle) {
    Log.d("XRecipes", "enter on Message");
    if(bundle !=null){
    String key = bundle.getString("key1");
    if (key != null) {
        Log.d("VVVVVVVVV ", key);
    }
}
      generateNotification(context, "zzzzz", "M<MMMMM");
}

@Override
protected void onRegistered(Context arg0) {
    // TODO Auto-generated method stub

}

 private static void generateNotification(Context context, String title,
         String message) {
     int icon = R.drawable.ic_launcher;

     NotificationManager notificationManager = (NotificationManager) context
             .getSystemService(Context.NOTIFICATION_SERVICE);
     Notification notification = new Notification(icon, title,
             System.currentTimeMillis());

     Intent notificationIntent = new Intent(context, AdsActivity.class);
     // set intent so it does not start a new activity
     notificationIntent.putExtra("message", message);
     notificationIntent.putExtra("title", title);

     PendingIntent intent=PendingIntent.getActivity(context, 0,
             notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT );
     notification.setLatestEventInfo(context, title, message, intent);
     notification.flags |= Notification.FLAG_AUTO_CANCEL;
     notificationManager.notify(0, notification);
 }


}

Note: I have two Notifications appear, one generated by Xtify SDK (doesn't open the Activity which I want to be opened by the notification ) and another generated by generateNotification(context, "zzzzz", "M

On your receiver like the: <receiver android:name="com.xtify.samples.gcm.XtifyNotifier"> implement your own handling for the new Message using the CallBack :

public void onMessage(Context context, Bundle msgExtras)

where you can add full handling of the notification, or simply override the method:

public static void processNotifExtras(Context context, Bundle msgExtras) on RichNotificationManger.java class

PS: you have to add you own receiver like:

<receiver android:name="com.xtify.samples.gcm.XtifyNotifier" >
            <intent-filter>
                <action android:name="com.xtify.sdk.NOTIFIER" />
            </intent-filter>
        </receiver>

For disabling the default notification for xtify sdk use following steps

use json payload {"com.xtify.sdk.NOTIF_ACTION_TYPE":"NONE"}

and set Simple Notification Click Action: as a Rich notification.

It will disable default notification by xtify SDK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM