用户点击Notification时如何打开特定活动来自Xtify?

时间:2012-10-23 12:54:57

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

我正在使用Xtify向Android App发送推送通知,我在使用Xtify SDK for GCM时出现问题

当推送通知来自Xtify并且用户点击它时,它会打开应用程序的主要活动,但我需要它来打开特定的活动。我应该如何使用它?

这是我的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>

这也是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);
 }


}

注意:我有两个通知出现,一个由Xtify SDK生成(不打开我想通过通知打开的Activity),另一个由generateNotification生成(context,“zzzzz”,“M

2 个答案:

答案 0 :(得分:2)

在您的接收器上,如:<receiver android:name="com.xtify.samples.gcm.XtifyNotifier">使用CallBack实现您对新消息的处理:

public void onMessage(Context context, Bundle msgExtras)

您可以在其中添加完整的通知处理,或者只是覆盖方法:

public static void processNotifExtras(Context context, Bundle msgExtras)班级

上的

RichNotificationManger.java

PS:你必须添加自己的接收器,如:

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

答案 1 :(得分:0)

要禁用xtify sdk的默认通知,请使用以下步骤

使用json有效负载 {&#34; com.xtify.sdk.NOTIF_ACTION_TYPE&#34;:&#34; NONE&#34;}

并设置简单通知单击操作:作为Rich通知。

它将禁用xtify SDK的默认通知。