0

我正在使用 Xtify 向 Android 应用程序发送推送通知,我在使用 Xtify SDK for GCM 时遇到问题

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

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

4

2 回答 2

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>
于 2012-10-23T13:19:07.973 回答
0

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

使用 json 有效负载 {"com.xtify.sdk.NOTIF_ACTION_TYPE":"NONE"}

并将 Simple Notification Click Action: 设置为 Rich 通知。

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

于 2015-06-24T08:50:36.143 回答