我不知道我的清单问题出在哪里,问题仅出在 android 2.3.6上。在我的 android 4.1.2 平板电脑中,它正在接收消息。我收到了 2.3.6 的注册 ID,但从未收到消息。拜托,有人可以帮助我吗?:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ciqtech.quicky.mobile.passenger"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission
android:name="com.ciqtech.quicky.mobile.passenger.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.ciqtech.quicky.mobile.passenger.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--
GCM CONFIGURATION
-->
<permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.ciqtech.quicky.mobile.passenger.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="..." />
<activity
android:name="com.ciqtech.quicky.mobile.passenger.activities.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>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
<activity android:name="com.facebook.LoginActivity" >
</activity>
<activity
android:name="com.ciqtech.quicky.mobile.passenger.activities.PassengerActivity"
android:label="@string/title_activity_passenger" >
</activity>
<activity
android:name="com.ciqtech.quicky.mobile.passenger.activities.LoginActivity"
android:label="@string/title_activity_login" >
</activity>
<!-- GCM
RECEIVER
-->
<receiver
android:name="com.ciqtech.quicky.mobile.passenger.broadcast_receivers.QuickyGCMBroadcastReceiver"
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.ciqtech.quicky.mobile.passenger" />
</intent-filter>
</receiver>
<service android:name=".services.GCMIntentService" android:enabled="true" />
</application>
</manifest>
更新
QuickyGCMB广播接收器
package com.ciqtech.quicky.mobile.passenger.broadcast_receivers;
import com.ciqtech.quicky.mobile.passenger.services.GCMIntentService;
import com.google.android.gcm.GCMBroadcastReceiver;
import android.content.Context;
import android.util.Log;
public class QuickyGCMBroadcastReceiver extends GCMBroadcastReceiver {
final String TAG = "QuickyGCMBroadcastReceiver";
@Override
protected String getGCMIntentServiceClassName(Context context) {
Log.d(TAG, "GET GCM INTENT SERVICE CLASS NAME");
return GCMIntentService.class.getName();
}
}
GCMIntentService。该设备在 android 2.3.x 中正确注册,但它没有收到消息,我在 onMessage 上的消息日志从未被调用,而在 android 4.1.x 中它运行良好。谢谢你的帮助。
package com.ciqtech.quicky.mobile.passenger.services;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Vibrator;
import android.provider.Settings.Secure;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.ciqtech.quicky.mobile.passenger.R;
import com.ciqtech.quicky.mobile.passenger.activities.LoginActivity;
import com.ciqtech.quicky.mobile.passenger.activities.PassengerActivity;
import com.ciqtech.quicky.mobile.passenger.broadcast_receivers.Device;
import com.ciqtech.quicky.mobile.passenger.configs.GCMSettings;
import com.ciqtech.quicky.mobile.passenger.dto.NotificationDTO;
import com.ciqtech.quicky.mobile.passenger.utils.SessionManager;
import com.google.android.gcm.GCMBaseIntentService;
import com.google.android.gms.gcm.GoogleCloudMessaging;
public class GCMIntentService extends GCMBaseIntentService {
Context ctx;
SharedPreferences prefs;
final String TAG = "GCMIntentService";
NotificationCompat.Builder builder;
public GCMIntentService() {
super(GCMSettings.GCM_SENDER);
}
@Override
public void onError(Context context, String errorId) {
Log.d(TAG + " - onError", "Messaging registration error: " + errorId);
}
@Override
protected boolean onRecoverableError(Context context, String errorId) {
Log.d(TAG + "- onRecoverableError", "Received recoverable error: " + errorId);
return super.onRecoverableError(context, errorId);
}
@Override
protected void onMessage(Context context, Intent intent) {
String msg = intent.getExtras().getString( "msg" );
Log.d(TAG, " - onMessage: " + msg);
// [more code]
}
// Put the GCM message into a notification and post it.
private void sendNotification(String msg) {
}
@Override
public void onRegistered(Context context, String registrationId) {
Log.d(TAG + " - onRegistered", "onRegistered()");
prefs = context.getSharedPreferences("Quickytaxi-Notifications",0);
String deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
SessionManager session = new SessionManager(context);
String uid = session.getUserDetails().get("id");
Log.d(TAG, deviceID + " " + registrationId + " " + uid);
Device.register(deviceID, registrationId, uid);
}
@Override
protected void onUnregistered(Context context, String s) {
Log.d(TAG + "- onUnregistered", "onUnregistered()");
String deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
Device.unregister(deviceID);
}
public void notify(NotificationDTO notificationDTO, Intent intent){
}
}