我想從庫項目中註冊GCM GCMIntentService是在庫項目中定義的。從庫項目中註冊GCM
這裏是我的註冊碼(庫項目內):
public static void init(Context context, String id){
GCMRegistrar.checkDevice(context);
GCMRegistrar.checkManifest(context);
GCMRegistrar.register(context, id);
}
但GCMIntentService的回調都沒有被調用,他們被稱爲只有當我運行庫項目作爲獨立的Android項目。
這裏是我的測試項目清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pushtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.pushtest.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.example.pushtest.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".PushTestApp" >
<activity
android:name="com.example.pushtest.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>
<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="com.example.pushtest" />
</intent-filter>
</receiver>
</application>
//push library definition
<service android:name="com.test.pushlibrary.GCMIntentService" />
</manifest>
休閒教程http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/ – abhi
@abhishesh代碼的作品,我什麼我試圖從圖書館項目開始。 – user1940676
不使用庫項目。只需將gcm.jar放入libs文件夾中 和project-property-java-build-path添加jar,然後它會調用 –