我的应用程序似乎没有收到我发送给它的通知,使用天蓝色站点内的调试模式,发送测试通知,我也尝试通过一些也不起作用的 .net 代码发送通知,似乎是我的通知集线器正在接收这些通知,但我在手机上的应用程序没有,互联网正在运行,usb 调试已打开,并且我没有收到“收到 herpderp 通知”的日志。
我已在通知中心成功注册我的应用程序,并正在等待使用以下代码的响应:
gcm = GoogleCloudMessaging.getInstance(this);
String connectionString = "***THIS IS where my connection string is, and it doesn't contain errors";
hub = new NotificationHub("denlillemandhub", connectionString, this);
NotificationsManager.handleNotifications(this, SENDER_ID, MyHandler.class);
registerWithGcm();
registerWithGcm() 方法:
private void registerWithGcm() {
new AsyncTask() {
@Override
protected Object doInBackground(Object... params) {
try {
registrationId = gcm.register(SENDER_ID);
Log.i(TAG, "Registered with id: " + registrationId);
} catch (Exception e) {
return e;
}
return null;
}
protected void onPostExecute(Object result) {
Log.d("Done", "attempt to register was done loading");
/**lblRegistration.setText(mRegistrationId);
lblStatus.setText(getResources().getString(R.string.status_registered)); */
};
}.execute(null, null, null);
}
MyHandler 类(我将 notificationHandler 作为参数):
import com.microsoft.windowsazure.notifications.NotificationsHandler;
public class MyHandler extends NotificationsHandler
{
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
Context ctx;
@Override
public void onReceive(Context context, Bundle bundle) {
ctx = context;
String nhMessage = bundle.getString("msg");
Log.d("line 27", "onReceive");
sendNotification(nhMessage);
}
private void sendNotification(String msg) {
Log.d("line 32", "sendNotification");
mNotificationManager = (NotificationManager)
ctx.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
new Intent(ctx, ToDoActivity.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ctx)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notification Hub Demo")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
}
最后(我的 androidManifest 只是显示权限):
<uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="com.example.denlillemand.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.denlillemand.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<receiver android:name="com.microsoft.windowsazure.notifications.NotificationsBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.denlillemand" />
</intent-filter>
</receiver>
我的建议是假设我在服务器端的脚本是正确的,并且我的 GCM / Azure API 密钥/设置都是正确的。显然,我的通知集线器按预期接收,但似乎 GCM 要么没有传递到注册的设备,要么设备确实收到了通知,但没有正确处理它。
我要感谢任何想通读所有这些内容以给出一个合格的猜测的人,非常感谢,我真的一直在努力解决这个问题。
谢谢。