Tag: 谷歌云的消息

如何在Android中实现推送通知

我试图用一天多的时间用gcm实现一个简单的PUSH通知,但是无法实现它。 我何时添加此权限 我通过移动设备调试时收到此错误消息 pkg: /data/local/tmp/Android.Test Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED] 有人可以告诉我我在做什么。 为了进一步的帮助,我将整个manifest.xml文件 编辑1:这就是我试图将消息从C#发送到我的Android设备…..我从博客中找到了这段代码。 private string SendGCMNotification(string apiKey, string postData, string postDataContentType = “application/json”) { ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate); // // MESSAGE CONTENT byte[] byteArray = Encoding.UTF8.GetBytes(postData); // // CREATE REQUEST HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(“https://android.googleapis.com/gcm/send”); Request.Method = “POST”; Request.KeepAlive = false; Request.ContentType = postDataContentType; Request.Headers.Add(string.Format(“Authorization: key={0}”, apiKey)); Request.ContentLength = […]

为什么InstanceID服务会自动启动,我该如何预防?

我有一个Android应用程序,我正在使用GCM。 我正在按照教程并使用InstanceIDListenerService类,我试图在用户输入一些信息的“订阅”页面之后将其作为IntentService 。 在幕后的启动画面上,还有一些初步代码在此订阅页面之前触发。 在我进入SubscriptionActivity之前,SplashScreen活动中正在调用InstanceIDListenerService构造函数(以及随后的onHandleIntent)。 它为什么这样做? 意图服务是否可以从它自己开始? 我确实在AndroidManifest.xml文件中注册了服务,当我注释掉以下行时,它不会触发实例自动创建,应用程序按预期工作(直到我需要使用实例当然.. 。) SplashScreen.java public class SplashScreen extends Activity { private BroadcastReceiver dbInsertReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); if(bundle != null) { // Handle results and move to next activity, should // be the subscribe activity where I […]

Google Cloud Messaging:向“所有”用户发送消息

我正在学习本教程以了解GCM系统。 我对这部分有疑问: 可以向每个注册用户发送消息,但是如何更改该代码以便我可以向所有注册的设备发送单个消息? 我已经找到了答案: 使用GCM向多个Android设备发送推送通知 和 在多个设备上发送推送通知 (几乎相同的问题) – 但找不到解决我问题的答案。 getAllUsers(); if ($users != false) $no_of_users = mysql_num_rows($users); else $no_of_users = 0; ?> No of Devices Registered: 0) { ?> <form id="” name=”” method=”post” onsubmit=”return sendPushNotification(”)”> Name: Email: <input type="hidden" name="regId" value="”/> No Users Registered Yet! 我试图改变代码,但随着我的改变它不起作用.. 我想把所有regID作为数组放入sendPushNofiy … getAllUsers(); if ($users != false) $no_of_users […]

指定有效的唤醒锁定级别

在GCM支持下使用应用程序,没有任何问题。 但是当我推送通知时,应用程序崩溃,LogCat说如下: 03-21 14:32:13.276:E / AndroidRuntime(4457):java.lang.RuntimeException:无法启动活动ComponentInfo {de.yanniks.cm_updatechecker / de.yanniks.cm_updatechecker.UpdateChecker}:java.lang.IllegalArgumentException:Must指定有效的唤醒锁定级别。 如何定义有效的唤醒锁定级别? 请帮忙!

无法通过GCM获取我的InstanceID

我正在尝试首次在我的应用程序中实现GCM,所以我按照这些步骤操作,并且出现了一个错误,导致我的应用程序无法在我的sv中获得注册令牌。 它说: 09-30 23:05:52.196 31461-31514/com.comgonzalovillarbaribus E/GMPM﹕ getGoogleAppId failed with status: 10 09-30 23:05:52.200 31461-31514/com.comgonzalovillarbaribus E/GMPM﹕ Uploading is not possible. App measurement disabled 我不知道问题是什么,我的清单是正确的,我的GCM_SENDER_ID 。 这是我要求我的令牌的地方: // Set GCM if (checkPlayServices()) { InstanceID instanceID = InstanceID.getInstance(this); String token = null; try { token = instanceID.getToken(Constants.GCM_SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); sendRegistrationToServer(token); } catch (IOException e) { e.printStackTrace(); } } […]

android gcm服务器中的ssl握手exception

嗨朋友我是android新手。 我正在尝试创建gcm服务器。 我的代码是 System.setProperty(“javax.net.ssl.trustStore”,”/usr/bin/keystore.jks”); String id = “cliend id”; String msg = “Test”; Sender sender = new Sender(Api key); Message message = new Message.Builder() .addData(“message”, “this is the message”) .addData(“other-parameter”, “some value”) .build(); Result result; result = sender.sendNoRetry(message, id); 我创建密钥库但仍然有如下错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested […]

无法使用Google App Engine(GAE)连接到Google Cloud Messaging(GCM)服务器

我正在尝试为我的应用设置谷歌云消息,我正在为我的服务器使用Google App Engine。 我有我的API密钥,但我似乎无法连接到谷歌云消息服务器。 这是我的代码。 HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(“https://android.googleapis.com/gcm/send”); try { List nameValuePairs = new ArrayList(2); nameValuePairs.add(new BasicNameValuePair(“registration_id”, regId)); nameValuePairs.add(new BasicNameValuePair(“data.message”, messageText)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); post.setHeader(“Authorization”, “key=*MY_API_KEY_HERE*”); post.setHeader(“Content-Type”, “application/x-www-form-urlencoded;charset=UTF-8”); Header[] s=post.getAllHeaders(); System.out.println(“The header from the httpclient:”); for(int i=0; i < s.length; i++){ Header hd = s[i]; System.out.println("Header Name: "+hd.getName() +" […]

服务器端GCM返回错误400

我想实施GCM。 我写了一个测试代码来了解它是如何工作的,但我在响应中不断收到错误400。 我正在用Java编写(JDK 7)。 我跟着这个关于这个主题的动词。 我在那里修改了给定的代码,并将ObjectMapper的使用改为Gson。 这是我的Data对象代码: public class Data { private ArrayList registration_ids; public Data() { this.registration_ids = new ArrayList(); this.registration_ids.add(“APA91…”); // There is the real device registration id here. } } *我在服务器参考中看到,在HTTP协议中,我只能使用registration_ids发送消息。 (所有其他都是可选的) 以下是发送消息的代码: public static void post(String apiKey, Data data){ try{ // 1. URL URL url = new URL(“https://android.googleapis.com/gcm/send”); // 2. Open […]

发布到GoogleCloudMessaging会返回400 InvalidTokenFormat

我正在尝试发布到谷歌云消息传递Api(GCM) ,但我的请求失败,响应HTTP/1.1 400 InvalidTokenFormat 。 但是,如果我改变我的程序以便它连接到localhost,而我只是将请求传递给其他将请求发送到GCM的其他东西,请求成功。 以下是失败的代码: import java.net.URL; import java.net.HttpURLConnection; import java.io.OutputStream; public class GcmPostMe { public static void main (String[] args) { String data = “{\”to\”:\” *** censored recipient token *** \”}”; String type = “application/json”; try { URL u = new URL(“https://android.googleapis.com/gcm/send/”); HttpURLConnection conn = (HttpURLConnection) u.openConnection(); conn.setDoOutput(true); conn.setRequestMethod(“POST”); conn.setRequestProperty( “Authorization”, “key=” […]

Android – GCM推送通知未出现在通知列表中

我正在开发我的第一个Android应用,以使用Google云消息传递(GCM)服务进行推送通知。 我已经到了可以从我的服务器应用程序成功发送消息的位置,并在客户端应用程序上的GCMIntentService类中的onMessage事件中记录消息的内容。 但是,我没有在设备上看到任何收到消息的可视指示。 我期待这条消息出现在手机的下拉通知列表中,就像在iPhone上一样。 这是否必须手动编码? 还有一种显示消息的常用方法,无论当前哪个活动处于活动状态,以及应用程序是否在后台处于空闲状态? 任何帮助赞赏。