我正在使用Xtify将推送通知发送到Android应用,我对GCM
的XTIFY SDK有问题当推送通知来自Xtify,用户单击它时,它将打开应用程序的主要活动,但是我需要它打开特定的活动。我应该如何使用它?
这是我的清单。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生成(不打开我想通过通知打开的活动),另一个由GenerateNotification生成的活动(上下文," Zzzzz",M
在您的接收器上,例如: <receiver android:name="com.xtify.samples.gcm.XtifyNotifier">
使用 CallBack
实现自己的处理方法:
public void onMessage(Context context, Bundle msgExtras)
您可以在其中添加通知的完整处理,或者只需覆盖该方法:
public static void processNotifExtras(Context context, Bundle msgExtras)
上的 CC_3 class
ps:您必须添加自己的接收器:
<receiver android:name="com.xtify.samples.gcm.XtifyNotifier" >
<intent-filter>
<action android:name="com.xtify.sdk.NOTIFIER" />
</intent-filter>
</receiver>
用于禁用XTIFY SDK的默认通知以下步骤
使用JSON有效载荷{" com.xtify.sdk.notif_action_type":" none"}
并设置简单的通知单击操作:作为丰富的通知。
它将通过XTIFY SDK禁用默认通知。