【问题标题】:Issue in getting device token of android using gcm使用 gcm 获取 android 设备令牌的问题
【发布时间】:2014-04-18 08:00:09
【问题描述】:

我无法获取我的设备令牌,我正在使用 GCMRegistrar 我正在给我的代码。我怎么了,我不明白。

我的清单文件包括

<receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>

            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.example.apnsautodial" />
        </intent-filter>
    </receiver>
     <service android:name=".GCMIntentService" />

我的活动包括

GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);       
regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
    GCMRegistrar.register(this, SENDER_ID);
}

请帮帮我

感谢广告

【问题讨论】:

    标签: google-cloud-messaging devicetoken


    【解决方案1】:

    您的“myActivity”没有任何问题。但是为了获得注册 ID,您需要在您的应用中添加连接互联网的权限,以便您的应用可以发出请求并从 GCM 服务器获取 ID。

    在您的清单文件中添加以下行。希望它能解决您的问题。

    <uses-permission android:name="android.permission.INTERNET" />
    

    请访问此链接:http://developer.android.com/google/gcm/client.html 以获得清晰的想法。

    【讨论】:

      【解决方案2】:

      这是您可以使用 Google Cloud Messaging Api 使用的最佳示例,因为旧的 GCM 库方法现已弃用,
      Google Cloud Messaging

      你可以参考这个, http://developer.android.com/google/gcm/client.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-07
        • 1970-01-01
        • 2016-11-08
        • 1970-01-01
        • 2015-11-19
        相关资源
        最近更新 更多