【问题标题】:Google Cloud Messaging / GCM谷歌云消息传递/GCM
【发布时间】:2014-12-22 13:33:42
【问题描述】:

我想将 GCM 添加到我的应用程序中,但清单存在一些问题。 这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.comanderkai77.gssvertretungsplan"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="21" />

    <permission
        android:name="de.comanderkai77.gssvertretungsplan.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="de.comanderkai77.gssvertretungsplan.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <service android:name=".GCM" />

        <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="de.comanderkai77.gssvertretungsplan" />
            </intent-filter>
        </receiver>

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".GCM_Intent" >
        </activity>
    </application>

</manifest>

Java 代码没问题。当我调用 GCMRegistrar.register(MainActivity.this, GCM.SENDER_ID);什么都没发生。 logcat 说没什么用。你知道如何解决这个问题吗?

【问题讨论】:

    标签: java push-notification google-cloud-messaging


    【解决方案1】:

    GCMRegistrar 似乎已被弃用。

    你可以试试GoogleCloudMessaging:但是,这个课程需要 Google Play 服务 3.1 或更高版本。

    GoogleCloudMessaging 文档页面中有一个有用的代码块。所以你会得到一些有用的信息来了解问题可能是你无法访问 googlecloudmessaging 服务或其他东西,用这些错误控制语句包装你的代码。

    // Check device for Play Services APK. If check succeeds, proceed with
    //  GCM registration.
    if (checkPlayServices()) {
       gcm = GoogleCloudMessaging.getInstance(this);
       regid = getRegistrationId(context);
    
       if (regid.isEmpty()) {
           registerInBackground();
       }
     } else {
       Log.i(TAG, "No valid Google Play Services APK found.");
     }
    

    顺便检查一下,它与 gcm 的通信是否正确?它是返回设备的 registerId 还是其代码的任何错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      相关资源
      最近更新 更多