问题
We are implementing the Baidu push service for out customers without enabled Playservices.
Everything is working quite nicely, but I am experiencing huge delays, up to one hour. We are located in Europe and I am testing on a Europe Samsung Galaxy S8.
The Push Notification is been sent via the Baidu Push Console, so there is no intermediate server that could delay the notification.
I noticed that there is a process running called :bdservice_v1
. I assume that this service is responsible for receiving the notification and passing it to the main app process. How do I ensure to keep this process alive, even if the app is been killed?
Update:
I am revisiting this issue now and figured out, that everything is fine if the following conditions are met.
- App has been deinstalled
- Device has been rebooted
- App has been reinstalled
- Execution of
PushManager.startWork
The delay I mentioned above is due to the execution of PushManager.startWork
within a specific time (haven't figured out yet how long exactly). I guess that Baidu has implemented some sort of queueing and is pushing the missed notifications to the device after PushManager.startWork
.
I also contacted Baidu support multiple times in the meantime, but haven't heard back anything. Not even an automated response!
AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:installLocation="auto" android:versionCode="xxxx" android:versionName="xxxx" package="tld.d.x" tools:node="replace" xmlns:amazon="http://schemas.amazon.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" />
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="false" />
<uses-feature android:name="android.hardware.nfc.hce" android:required="false" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:maxSdkVersion="18" android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
<uses-feature android:name="android.hardware.microphone" android:required="false" />
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<permission android:name="tld.d.x.permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="tld.d.x.permission.RECEIVE_ADM_MESSAGE" />
<uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="baidu.push.permission.WRITE_PUSHINFOPROVIDER.tld.d.x" />
<permission
android:name="baidu.push.permission.WRITE_PUSHINFOPROVIDER.tld.d.x"
android:protectionLevel="signature">
</permission>
<application android:allowBackup="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/d.x" tools:replace="android:label" android:usesCleartextTraffic="true">
<uses-library android:name="org.apache.http.legacy" android:required="false" />
<meta-data
tools:node="replace"
android:name="android.support.VERSION"
android:value="28.0.0"
/>
<activity android:alwaysRetainTaskState="true" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/d.x" android:launchMode="singleTask" android:name=".MainActivity" android:screenOrientation="fullSensor" android:theme="@style/DarkTheme" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/d.x">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:exported="true" android:name=".pushnotification.PushHandlerActivity" />
<receiver android:name=".pushnotification.NotificationBroadcastReceiver">
<intent-filter>
<action android:name="notification_cancelled" />
</intent-filter>
</receiver>
<meta-data android:name="AmazonAPIKey" android:value="iuztgjhklöopiuzhj" />
<service android:exported="false" android:name=".pushnotification.pushServiceProviders.AdmMessageHandler" />
<service android:name=".pushnotification.pushServiceProviders.FcmMessagingService"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<amazon:enable-feature android:name="com.amazon.device.messaging" android:required="true" />
<receiver android:name=".pushnotification.pushServiceProviders.AdmMessageHandler$MessageAlertReceiver" android:permission="com.amazon.device.messaging.permission.SEND">
<intent-filter>
<action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
<action android:name="com.amazon.device.messaging.intent.RECEIVE" />
<category android:name="tld.d.x" />
</intent-filter>
</receiver>
<activity android:alwaysRetainTaskState="false" android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:launchMode="singleInstance" android:name=".BackgroundCmdActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar">
...
</activity>
<provider android:authorities="tld.d.x.file_provider_authority" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_provider_paths" />
</provider>
<service android:exported="true" android:name=".nfc.NfcHceService" android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="@xml/aid_list" />
</service>-->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="tld.d.x.file_provider_authority"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
<!-- Baidu Start -->
<receiver android:name="com.baidu.android.pushservice.PushServiceReceiver"
android:process=":bdservice_v1" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="com.baidu.android.pushservice.action.notification.SHOW" />
<action android:name="com.baidu.android.pushservice.action.media.CLICK" />
<!-- Drastically improves the receiving time -->
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</receiver>
<receiver android:name="com.baidu.android.pushservice.RegistrationReceiver"
android:process=":bdservice_v1" >
<intent-filter>
<action android:name="com.baidu.android.pushservice.action.METHOD" />
<action android:name="com.baidu.android.pushservice.action.BIND_SYNC" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<service android:name="com.baidu.android.pushservice.PushService" android:exported="true"
android:process=":bdservice_v1" >
<intent-filter >
<action android:name="com.baidu.android.pushservice.action.PUSH_SERVICE" />
</intent-filter>
</service>
<service android:name="com.baidu.android.pushservice.CommandService"
android:exported="true" />
<provider
android:name="com.baidu.android.pushservice.PushInfoProvider"
android:authorities="tld.d.x.bdpush"
android:writePermission="baidu.push.permission.WRITE_PUSHINFOPROVIDER.tld.d.x"
android:protectionLevel = "signature"
android:exported="true" />
<receiver android:name=".pushnotification.pushServiceProviders.BaiduPushMessageReceiver">
<intent-filter>
<action android:name="com.baidu.android.pushservice.action.MESSAGE" />
<action android:name="com.baidu.android.pushservice.action.RECEIVE" />
<action android:name="com.baidu.android.pushservice.action.notification.CLICK" />
</intent-filter>
</receiver>
<!-- Baidu Push -->
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
</manifest>
来源:https://stackoverflow.com/questions/55137626/delayed-baidu-push-notification