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。 我也嘗試添加谷歌播放服務庫和執行代碼(刪除gcm.jar),但它然後說GCMRegistrar類沒有發現異常 我已檢查所有權限,他們似乎是正確的。 這裏是我的清單文件GCMRegistrar.getRegistrationId(本)總是返回空字符串(使用GCM的Android推送通知)
<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>
是的,它是過時了,看到http://developer.android.com/reference/com/google/android/gcm/GCMRegistrar.html – NickT