标签: google-cloud-messaging

Android gcm示例给出了注册:http错误400

我按照http://developer.android.com/guide/google/gcm/gs.html上给出的步骤操作,每次尝试从我的设备注册时都会收到以下错误(在froyo上运行)

07-04 22:48:31.178:D/C2DMRegistrar(3880):[C2DMRegistrar.66]注册:http错误400

对于senderId,我尝试过使用projectID(根据Google),电子邮件ID和API密钥但没有效果.

我有Android市场并在设备上签署了谷歌帐户.

android android-c2dm google-cloud-messaging

1
推荐指数
1
解决办法
6810
查看次数

使用php向Google Cloud Messaging发送通知会给我带来未经授权的错误401

搜索有关如何使用GCM但使用PHP而不是servlet发送通知的一些信息,我发现:GCM与PHP(Google云消息传递)

我测试了这些问题的响应的工作代码,我也创建了一个用于浏览器应用程序的密钥(带有引用者),并且我给了这个ip的权限:.mywebsite.com /(te php文件在这个网址上:" http: //www.mywebsite.com/~jma/cHtml5/cap/kk.php ")

但我得到了这样的回应:未经授权的错误401

我做错了什么?

这是php文件:

<?php
    // Replace with real server API key from Google APIs        
    $apiKey = "fictional key";

    // Replace with real client registration IDs
    $registrationIDs = array( "APA91asdasdSDGGS232S13S4213abGqiNhCIXKjlxrkUYe_xTgTacNGB5n16b380XDd8i_9HpKGRHkvm8DDet4_WK3zumjDEKkTRWLgPS7kO-BrKzWz7eWFQaDD9PJ8zA6hlSqL9_zH21P8K22ktGKmo_VIF6YAdU9ejJovrKBTpgQktYkBZBf9Zw","APAasdasd32423dADFG91bHYYxYB7bFiX5ltbJt6A-4MBiNg7l4RS4Bqf3jIfYviaaUfZ810XJo2o66DY9-jdeJk_JR8FIZCyrmCv-eu_WLkGZ8KaoHgEDR_16H2QPm98uHpe1MjKVXbzYc4J89WMmcIrl5tHhWQnIQNzaI6Zp6yyFUNUQ");

    // Message to be sent
    $message = "Test Notificación PHP";

    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';

    $fields = array(
        'registration_ids' => $registrationIDs,
        'data' => array( "message" => $message ),
    );

    $headers = array(
        'Authorization: key=' . $apiKey,
        'Content-Type: application/json' …
Run Code Online (Sandbox Code Playgroud)

php android push-notification android-c2dm google-cloud-messaging

1
推荐指数
1
解决办法
5500
查看次数

为什么C2DM/GCM不使用SMS作为传输来节省电池寿命?

据我了解,GCM使用长轮询推送实现立即推送.

与SMS或与Blackberry推送类似的技术(假设使用特定的GSM MAP)通知电话通过TCP联系服务器获取有效负载相比,这会花费很多电池.

谷歌没有采用GSM推送机制来节省电池寿命的原因是什么?

android battery android-c2dm google-cloud-messaging

1
推荐指数
1
解决办法
799
查看次数

GCMRegistrar.register不起作用

我试图在我的应用程序上使用GCM,但GCMRegistrar.register总是返回空字符串.这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="net.andromedya.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="net.andromeya.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />

<permission
    android:name="net.andromedya.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<permission
    android:name="net.andromedya.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

<application
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock.Light" >
    <activity
        android:name="net.andromedya.activities.MainActivity" …
Run Code Online (Sandbox Code Playgroud)

android push-notification google-cloud-messaging

1
推荐指数
1
解决办法
4211
查看次数

在Android应用程序中,调用onResume方法时,在状态栏中清除小图标

我正在使用推送通知开发Android应用程序.

我想在调用onResume方法时清除推送通知中出现的状态栏中的小图标.

然后,我编写以下代码,但它不能正常工作.

※※PushHandlerActivity.java

@Override
public void onResume() {
    super.onResume();

    GCMIntentService.cancelNotification(this);
    finish();
}
Run Code Online (Sandbox Code Playgroud)

※※GCMIntentService.java

public class GCMIntentService extends GCMBaseIntentService {

public static final int NOTIFICATION_ID = 1234;
private static final String TAG = "GCMIntentService";

public GCMIntentService() {
    super("GCMIntentService");
}

public void createNotification(Context context, Bundle extras)
{
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);

    Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(context.getApplicationInfo().icon) …
Run Code Online (Sandbox Code Playgroud)

android push-notification android-notifications google-cloud-messaging

1
推荐指数
1
解决办法
2665
查看次数

Google Cloud Messaging-使用PHP向Android发送推送消息

我正在开发一个Android项目,我需要使用GCM来推送消息.我想只使用PHP而不是HTML发送通知.我该如何实现这一目标?我尝试的方式只是将gcm_regid和消息作为参数放到$ gcm-> send_notification($ registration_ids,$ msg)但我不断收到错误说: - 字段"data"必须是JSON数组:["你有一个通知!"]

在哪里"你有通知!" 是我的消息!! 请帮忙!!谢谢!

send_notification的代码是

 public function send_notification($registatoin_ids, $message) {

    include_once './config.php';

    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';

    $fields = array(
        'registration_ids' => $registatoin_ids,
        'data' => $message,
    );

    $headers = array(
        'Authorization: key=' . GOOGLE_API_KEY,
        'Content-Type: application/json'
    );
    // Open connection
    $ch = curl_init();

    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, …
Run Code Online (Sandbox Code Playgroud)

html php android json google-cloud-messaging

1
推荐指数
1
解决办法
5539
查看次数

使用Gradle更改包名称时GCM无法注册

在我的常规构建gcm工作正常,但当我使用flavor改变com名称时,事情就停止了.我的IntentService永远不会被初始化.我应该如何设置我的清单文件以便发生这种情况?

  • 我已将它们添加到开发人员控制台.
  • 我正在使用gradle com.android.tools.build:gradle:0.11.+'

我得到了日志

V/GCMBroadcastReceiver? onReceive: com.google.android.c2dm.intent.REGISTRATION
V/GCMBroadcastReceiver? GCM IntentService class: com.sample.app.dev.GCMIntentService
V/GCMBaseIntentService? Acquiring wakelock
Run Code Online (Sandbox Code Playgroud)

然后什么也没有.我的自定义IntentService类永远不会被初始化,我的registrationId保持为空.我目前的实现类似于这里的实现:https: //stackoverflow.com/a/20334397/198034

我应该如何设置我的清单以获得0.11.+味道与gcm一起使用?

下面是我的一个版本的清单,我在主清单中有更多代码(所有需要的权限等),但没有其他处理gcm.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sample.app"
    android:versionCode="45"
    android:versionName="0.6.5" >

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />


    <permission android:name="com.sample.app.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.sample.app.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name" >


        <service android:name=".GCMIntentService" />
        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="${packageName}" />
            </intent-filter>
        </receiver>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

android gradle push-notification google-cloud-messaging android-gradle-plugin

1
推荐指数
1
解决办法
5022
查看次数

无法在API级别17获取令牌

我正在运行这些命令以获取令牌:

  InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
  String token = instanceID.getToken(Config.GOOGLE_PROJECT_ID,
                             GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
Run Code Online (Sandbox Code Playgroud)

但得到这个例外:

java.io.IOException: MISSING_INSTANCEID_SERVICE
            at com.google.android.gms.iid.zzc.zza(Unknown Source)
            at com.google.android.gms.iid.zzc.zzb(Unknown Source)
            at com.google.android.gms.iid.zzc.zza(Unknown Source)
            at com.google.android.gms.iid.InstanceID.zzc(Unknown Source)
            at com.google.android.gms.iid.InstanceID.getToken(Unknown Source)
            at autofocus.com.autofocus.activity.ItemListActivity$4.doInBackground(ItemListActivity.java:408)
            at autofocus.com.autofocus.activity.ItemListActivity$4.doInBackground(ItemListActivity.java:398)
Run Code Online (Sandbox Code Playgroud)

知道我做错了什么吗?

android push-notification google-cloud-messaging

1
推荐指数
1
解决办法
2782
查看次数

在模拟器上未收到Firebase消息

我按照/sf/answers/2703847891/中的说明将SNS与FCM连接到Android应用。部署到模拟器后,该应用程序会初始化,但不会收到任何消息。同一款应用在我的实际Nexus 6设备上可以正常运行并收到消息。为什么会有这种差异?

android amazon-web-services amazon-sns firebase google-cloud-messaging

1
推荐指数
2
解决办法
4467
查看次数

Android - 收到通知但没有通知弹出窗口(前景)

我的应用正在正确接收通知,但未能显示收到信息的通知(如果应用已打开).

注意:如果应用程序在后台,则会显示通知而不会出现任何问题.


我的代码:

我收到此方法的通知:

@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    if(remoteMessage!=null)
    {
        String id = null;
        String title = null;
        String body = null;
        String launchPage = null;

        if(remoteMessage.getNotification()!=null)
        {
            title = remoteMessage.getNotification().getTitle();
            body = remoteMessage.getNotification().getBody();
        }

        if(remoteMessage.getMessageId()!=null)
        {
            id = remoteMessage.getMessageId();
        }

        Log.i(TAG, "id: " + id);
        Log.i(TAG, "title: "+ title);
        Log.i(TAG, "body: " + body);

        int notif_id = 0;

        sendNotification(notif_id, title, body, launchPage);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后它调用这个(它应该显示我理解的通知):

private void sendNotification(int id, String title, String …
Run Code Online (Sandbox Code Playgroud)

notifications android firebase google-cloud-messaging

1
推荐指数
1
解决办法
828
查看次数