好的,你好,我正在尝试在我的 xamarin.android 应用程序上实现 pushwoosh 通知
我在舞台上向客户发送通知,当我单击通知时,它应该将我重定向到某个活动和 ui,这是我的代码
private void DoOnMessageReceive(String message)
{
var messageJson = new JSONObject(message);
if (messageJson.GetString("title") == "akotube")
{
var intent = new Intent(this, typeof(Second));
//intent.PutExtra(PushManager.PushReceiveEvent, messageJson.ToString());
intent.PutExtra("message", "akotube");
StartActivity(intent);
}
`但我不能让它工作,这是我的参考pushwoosh
编辑 这是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest android:versionCode="1" android:versionName="1.0" package="com.pushwosh.sample" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<!--library-->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!--
Creates a custom permission so only this app can receive its messages.
NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
where PACKAGE is the application's package name.
-->
<permission android:name="com.pushwosh.sample.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="com.pushwosh.sample.permission.C2D_MESSAGE"/>
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
<!-- The targetSdkVersion is optional, but it's always a good practice
to target higher versions. -->
<application android:icon="@drawable/Icon" android:label="PushWosh">
<meta-data android:name="PW_APPID" android:value="CXXXX-XXXX"/>
<meta-data android:name="PW_PROJECT_ID" android:value="AXXXXXXXXX"/>
<activity android:name="com.arellomobile.android.push.PushWebview"/>
<activity android:name="com.arellomobile.android.push.MessageActivity"/>
<activity android:name="com.arellomobile.android.push.PushHandlerActivity"/>
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<!-- Receives the actual messages. -->
<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.pushwosh.sample"/>
</intent-filter>
</receiver>
<service android:name="com.arellomobile.android.push.PushGCMIntentService"/>
</application>
</manifest>
这是我的课
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var btn = FindViewById<Button>(Resource.Id.MyButton);
btn.Click += btn_Click;
var goSecond = FindViewById<Button>(Resource.Id.btnGo);
goSecond.Click += goSecond_Click;
var unregister = FindViewById<Button>(Resource.Id.Unregister);
unregister.Click += unregister_Click;
_mMessageReceiver = new LocalMessageBroadcastReceiver {Activity = this};
_mRegisterReceiver = new LocalRegisterBroadcastReceiver {Activity = this};
_manager = PushManager.GetInstance(this);
//Register for push!
//_manager.RegisterForPushNotifications();
CheckMessage(Intent);
}
private void RegisterReceivers()
{
var intentFilter = new IntentFilter(PackageName + ".action.PUSH_MESSAGE_RECEIVE");
if (MBroadcastPush)
{
RegisterReceiver(_mMessageReceiver, intentFilter);
}
RegisterReceiver(_mRegisterReceiver, new IntentFilter(PackageName + "." + PushManager.RegisterBroadCastAction));
}
private void UnregisterReceivers()
{
UnregisterReceiver(_mMessageReceiver);
UnregisterReceiver(_mRegisterReceiver);
}
class LocalMessageBroadcastReceiver : BasePushMessageReceiver
{
public MainActivity Activity { private get; set; }
protected override void OnMessageReceive(Intent intent)
{
Activity.DoOnMessageReceive(intent.GetStringExtra(JsonDataKey));
}
}
class LocalRegisterBroadcastReceiver : RegisterBroadcastReceiver
{
public MainActivity Activity { private get; set; }
protected override void OnRegisterActionReceive(Context p0, Intent intent)
{
Activity.CheckMessage(intent);
}
}
private void CheckMessage(Intent intent)
{
if (null != intent)
{
if (intent.HasExtra(PushManager.PushReceiveEvent))
{
DoOnMessageReceive(intent.Extras.GetString(PushManager.PushReceiveEvent));
}
else if (intent.HasExtra(PushManager.RegisterEvent))
{
DoOnRegistered(intent.Extras.GetString(PushManager.RegisterEvent));
}
else if (intent.HasExtra(PushManager.UnregisterEvent))
{
DoOnUnregisteredError(intent.Extras.GetString(PushManager.UnregisterEvent));
}
else if (intent.HasExtra(PushManager.RegisterErrorEvent))
{
DoOnRegisteredError(intent.Extras.GetString(PushManager.RegisterErrorEvent));
}
else if (intent.HasExtra(PushManager.UnregisterErrorEvent))
{
DoOnUnregistered(intent.Extras.GetString(PushManager.UnregisterErrorEvent));
}
ResetIntentValues();
}
}