我正在使用两个Genymotion模拟器。一个是Android 4.1.1,另一个是4.2.2。 Android 5.0处理通知。
在4.2.2中,通知未到达,但服务器显示是
{ “multicast_id”:6922075632436417470, “成功”:1, “失败”:0, “canonical_ids”:0 “结果”:[{ “MESSAGE_ID”: “0:1455028566785442%2c62c465701c4188”}]}
这是我在服务器中发送的内容
{ “registration_ids”:[ “CA-84oToSM0:APA91bEQ-N1PNvKgKKwpvZSVbUfQV3q6ZBGNrQYGfWqyxNkguiOBztxCpNVkhoAyT53KsPq9j40XcqxvNf0JZAPdJZJME10XTqZRuNYGL3yabOVA1XI69EuGlUO9K4Duktoi0leLL_DK”], “数据”:{ “标题”: “Ejemplo德推”, “消息”: “埃斯托ES homesolutionýTE mandaron未mensaje”, “ticker_text”:“Mensaje HS de Juan”},“collapse_key”:“homesolution_topic”,“delay_while_idle”:false}
delay_while_idle我在真假中测试
服务器没问题,Android应用即可,谷歌播放服务更新
如果我卸载应用程序并再次安装,则推送到达但通知栏已损坏(我无法向下滑动)。如果我打开,使用相同的gcm_id,则推送不会出现
有任何帮助吗?谢谢!
public class RegistrationIntentService extends IntentService {
private static final String TAG = "Test/Registration";
private static final String[] TOPICS = {"global"};
public RegistrationIntentService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
// [START register_for_gcm]
// Initially this call goes out to the network to retrieve the token, subsequent calls
// are local.
// R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
// See https://developers.google.com/cloud-messaging/android/start for details on this file.
// [START get_token]
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
// [END get_token]
Log.i(TAG, "GCM Registration Token: " + token);
// Save the registration token in a global variable
// When a user is registered or logged this will be used
sendRegistrationToServer(token);
// You should store a boolean that indicates whether the generated token has been
// sent to your server. If the boolean is false, send the token to your server,
// otherwise your server should have already received the token.
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
// [END register_for_gcm]
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
// If an exception happens while fetching the new token or updating our registration data
// on a third-party server, this ensures that we'll attempt the update at a later time.
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
}
// Notify UI that registration has completed, so the progress indicator can be hidden.
Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
/**
* Modify this method to associate the user's GCM registration token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(String token) {
final Global global = (Global) getApplicationContext();
global.setGcmId(token);
Log.d(TAG, "Registration token saved as => " + token);
}
}