GCM不工作 [英] GCM not Working
问题描述
我学习的 GCM(谷歌云消息)
我完成了以下步骤
I am learning GCM(Google cloud Messaging)
I Completed Following steps
1 - 激活并获得了浏览器的应用程序密钥
1 - Activated and Obtained a Key for browser apps
2 - 增加以下清单中
2 - added following in manifest
的使用许可的:com.google.android.c2dm.permission.RECEIVE
Uses permission : com.google.android.c2dm.permission.RECEIVE
注册和接受Android应用程序的信息创建的权限,以prevent其他Android应用程序
Created permission to prevent other Android applications from registering and receiving the Android application's messages
创建为com.google.android.c2dm.intent.RECEIVE一个接收机,与设定为applicationPackage类别。接收机应要求com.google.android.c2dm.SEND批准
Created a receiver for com.google.android.c2dm.intent.RECEIVE, with the category set as applicationPackage. The receiver should require the com.google.android.c2dm.SEND permission
3 - 在接收器
@Override
public void onReceive(Context context, Intent intent) {
ComponentName comp = new ComponentName(context.getPackageName(),
GcmMessageHandler.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
GcmMessageHandler 这是一个打算服务上显示收到GCM message.following通知是onHandleIntent方法 GcmMessageHandler
GcmMessageHandler it’s a Intend Service to show a notification on receive gcm message.following is onHandleIntent Method in GcmMessageHandler.
@Override
protected void onHandleIntent(Intent intent) {
handler.post(new Runnable() {
@Override
public void run() {
NotificationManager manager = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext());
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setContentTitle("GCM Received");
mBuilder.setContentText("GCM Message");
manager.notify(1, mBuilder.build());
}
});
Log.i("app", "Received ");
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
4 - MainActivity-注册并获得克林特ID,从日志的猫我拷入该ID
4 - MainActivity-to register and get clint ID, from log cat I copyed that id.
5 - 从浏览器中我做POST请求 https://开头的Android。 googleapis.com/gcm/send~~V 与授权,内容类型和registration_ids。
5 - from browser I make post request to https://android.googleapis.com/gcm/send with authorization,content-type,and registration_ids.
其获得成功的消息。
但我的设备没有显示通知。
Its gets success message.
But my device not showing notification.
推荐答案
对不起大家,
其实我的计划是正确的。我认为这是我的电话有问题。
(我不能接收来自Facebook Messenger消息也)
Actually my program is correct. I think it’s a problem with my phone. (I can’t receive messages from Facebook messenger also,)
但今天早上我吃了一惊,我从我的测试应用程序(消息,我送3天前),脸谱等每一个消息。
but Today morning I surprised, I got every messages from my test app(message that I send 2 days ago), Facebook ,etc.
感谢大家。
这篇关于GCM不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!