我找了很久发现有java下有一下sdk,在nuget中没找到相应包 import com.alibaba.sdk.android.push.MessageReceiver; import com.alibaba.sdk.android.push.notification.CPushMessage; import com.alibaba.sdk.android.push.notification.PushData; import com.alibaba.sdk.android.push.notification.b; import com.alibaba.sdk.android.push.notification.d; import com.alibaba.sdk.android.push.notification.e; import com.aliyun.ams.emas.push.AgooMessageReceiver; import com.aliyun.ams.emas.push.notification.CPushMessage; 请问大神,下面的过程怎么在C#中实现: public abstract class MessageReceiver extends AgooMessageReceiver { private d mMessageNotification = new d();
public void onReceive(Context paramContext, Intent paramIntent) { super.onReceive(paramContext, paramIntent); }
public boolean showNotificationNow(Context paramContext, Map<String, String> paramMap) { return (d.a(paramMap) || !e.a(paramContext)); }
public Notification customNotificationUI(Context paramContext, Map<String, String> paramMap) { Notification notification = customNotificationUI(paramContext, PushData.parse(paramContext, paramMap)); if (notification != null) return notification; b b = this.mMessageNotification.a(paramContext, paramMap); return this.mMessageNotification.a(paramContext, b); }
public Notification customNotificationUI(Context paramContext, PushData paramPushData) { return null; }
public void onNotificationReceivedWithoutShow(Context paramContext, String paramString1, String paramString2, Map<String, String> paramMap, int paramInt, String paramString3, String paramString4) { onNotificationReceivedInApp(paramContext, paramString1, paramString2, paramMap, paramInt, paramString3, paramString4); }
public void onNotificationShow(Context paramContext, String paramString1, String paramString2, Map<String, String> paramMap) { onNotification(paramContext, paramString1, paramString2, paramMap); }
public void onMessageArrived(Context paramContext, CPushMessage paramCPushMessage) { onMessage(paramContext, CPushMessage.from(paramCPushMessage)); }
public void onNotificationOpened(Context paramContext, String paramString1, String paramString2, String paramString3, int paramInt) { if (paramInt == 4) { onNotificationClickedWithNoAction(paramContext, paramString1, paramString2, paramString3); } else { onNotificationOpened(paramContext, paramString1, paramString2, paramString3); } }
public void onNotificationRemoved(Context paramContext, String paramString1, String paramString2, String paramString3, int paramInt, String paramString4) { onNotificationRemoved(paramContext, paramString4); }
protected abstract void onNotification(Context paramContext, String paramString1, String paramString2, Map<String, String> paramMap);
protected abstract void onMessage(Context paramContext, CPushMessage paramCPushMessage);
protected abstract void onNotificationOpened(Context paramContext, String paramString1, String paramString2, String paramString3);
protected abstract void onNotificationClickedWithNoAction(Context paramContext, String paramString1, String paramString2, String paramString3);
protected abstract void onNotificationRemoved(Context paramContext, String paramString);
protected abstract void onNotificationReceivedInApp(Context paramContext, String paramString1, String paramString2, Map<String, String> paramMap, int paramInt, String paramString3, String paramString4); }
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.Media;
using Android.OS;
using Android.Support.V4.App;
using Consumer.Mobile.Infra;
using Consumer.Mobile.Services.PushNotification;
using Java.Lang;
using XLabs.Ioc;
using TaskStackBuilder = Android.Support.V4.App.TaskStackBuilder;
namespace Consumer.Mobile.Droid.PushNotification
{
[Service]
public class MyIntentService : IntentService
{
private readonly ILogger _logger;
private readonly IPushNotificationService _notificationService;
private readonly IPushNotificationRegister _pushNotificationRegister;
public MyIntentService()
{
_logger = Resolver.Resolve<ILogger>();
_notificationService = Resolver.Resolve<IPushNotificationService>();
_pushNotificationRegister = Resolver.Resolve<IPushNotificationRegister>();
}
static PowerManager.WakeLock _sWakeLock;
static readonly object Lock = new object();
public static void RunIntentInService(Context context, Intent intent)
{
lock (Lock)
{
if (_sWakeLock == null)
{
// This is called from BroadcastReceiver, there is no init.
var pm = PowerManager.FromContext(context);
_sWakeLock = pm.NewWakeLock(
WakeLockFlags.Partial, "My WakeLock Tag");
}
}
_sWakeLock.Acquire();
intent.SetClass(context, typeof(MyIntentService));
context.StartService(intent);
}
protected override void OnHandleIntent(Intent intent)
{
try
{
Context context = this.ApplicationContext;
string action = intent.Action;
if (action.Equals("com.google.android.c2dm.intent.REGISTRATION"))
{
HandleRegistration(context, intent);
}
else if (action.Equals("com.google.android.c2dm.intent.RECEIVE"))
{
HandleMessage(context, intent);
}
}
finally
{
lock (Lock)
{
//Sanity check for null as this is a public method
if (_sWakeLock != null)
_sWakeLock.Release();
}
}
}
private void HandleMessage(Context context, Intent intent)
{
Intent resultIntent = new Intent(this, typeof(MainActivity));
TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
var c = Class.FromType(typeof(MainActivity));
stackBuilder.AddParentStack(c);
stackBuilder.AddNextIntent(resultIntent);
string alert = intent.GetStringExtra("Alert");
int number = intent.GetIntExtra("Badge", 0);
var imageUrl = intent.GetStringExtra("ImageUrl");
var title = intent.GetStringExtra("Title");
Bitmap bitmap = GetBitmap(imageUrl);
PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.SetAutoCancel(true) // dismiss the notification from the notification area when the user clicks on it
.SetContentIntent(resultPendingIntent) // start up this activity when the user clicks the intent.
.SetContentTitle(title) // Set the title
.SetNumber(number) // Display the count in the Content Info
.SetSmallIcon(Resource.Drawable.Icon) // This is the icon to display
.SetLargeIcon(bitmap)
.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
.SetContentText(alert); // the message to display.
// Build the notification:
Notification notification = builder.Build();
// Get the notification manager:
NotificationManager notificationManager =
GetSystemService(Context.NotificationService) as NotificationManager;
// Publish the notification:
const int notificationId = 0;
notificationManager.Notify(notificationId, notification);
}
private void HandleRegistration(Context context, Intent intent)
{
var token = intent.GetStringExtra("registration_id");
_logger.Info(this.Class.SimpleName, "Received Token : " + token);
if (_pushNotificationRegister.ShouldSendToken(token))
{
var uid = Android.Provider.Settings.Secure.GetString(MainActivity.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId);
_notificationService.AddPushToken(token, DeviceUtils.GetDeviceType(), uid);
}
}
private Bitmap GetBitmap(string url)
{
try
{
System.Net.WebRequest request =
System.Net.WebRequest.Create(url);
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream responseStream =
response.GetResponseStream();
return BitmapFactory.DecodeStream(responseStream);
}
catch (System.Net.WebException)
{
return null;
}
}
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。