gpt4 book ai didi

android - GCMRegistrar.getRegistrationId(this) 始终返回空字符串(使用 GCM 的 Android 推送通知)

转载 作者:行者123 更新时间:2023-11-30 03:12:15 25 4
gpt4 key购买 nike

 public void registerClient()
{
try
{
// Check that the device supports GCM (should be in a try / catch)
GCMRegistrar.checkDevice(this);

// Check the manifest to be sure this app has all the required
// permissions.
GCMRegistrar.checkManifest(this);

// Get the existing registration id, if it exists.
regId = GCMRegistrar.getRegistrationId(this);

if (regId.equals(""))
{

// register this device for this project
GCMRegistrar.register(this, PROJECT_ID);
regId = GCMRegistrar.getRegistrationId(this);

regId = GCMRegistrar.getRegistrationId(这个);总是返回一个空字符串。 GCMRegister 类是否已弃用?我已经从 sdk/extras/google/gcm/gcm-client 路径添加了 gcm jar。我也尝试添加 google play 服务库并执行代码(删除 gcm.jar)但它然后说 GCMRegistrar 类未找到异常我检查了所有权限,它们似乎是正确的。这是我的 list 文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gcmclient"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />

<!-- receives GCM messages -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google services -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- GCM requires a Google account -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.READ_OWNER_DATA" />

<!-- wake the processor if a GCM message is received -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<permission
android:name="com.example.gcmclient.permission.C2D_MESSAGE"
android:protectionLevel="signature" >
</permission>

<uses-permission android:name="com.example.gcmclient.permission.C2D_MESSAGE" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

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

<category android:name="com.example.gcmclient" />

<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

<category android:name="com.example.gcmclient" />
</intent-filter>
</receiver>

<service android:name=".GCMIntentService" >
</service>
</application>

</manifest>

最佳答案

您的代码看起来不错,但是当您使用 GCM 时,您必须从设置中同步帐户。按照步骤。

转到设置 ---> 添加帐户 --->google

关于android - GCMRegistrar.getRegistrationId(this) 始终返回空字符串(使用 GCM 的 Android 推送通知),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20741505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com