Har*_*ish 3 android push-notification firebase firebase-cloud-messaging
在Motorola中测试应用程序,当该应用程序被杀死时,三星可以正常工作。但是当我在体内测试应用程序时,oppo在应用程序被破坏的情况下无法正常工作。
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage == null)
return;
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
// handleNotification(remoteMessage.getNotification().getBody());
}
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
handleDataMessage(json);
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
Android清单xml:
<service
android:name="notification.MyFirebaseMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="notification.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
我没有收到有关vivo的消息,建议您提供任何帮助。
如果应用程序被杀死,Infinix Note 5(Android One-Oreo)和Oppo F9(Oreo)不会收到推送通知,如果应用程序在后台或前景中,它们都可以正常工作。
从最近的应用程序托盘中刷过应用程序后,使用(氧气操作系统,MIUI等)的中文ROM会终止(类似于强制停止)。由于这个原因,每项任务都会在后台运行,例如服务,因此乔布斯会被该应用杀死。即使是高优先级FCM也看不到中文ROM中的日光
实时问题:
1)您无法获取用户的位置。因此,如果取决于实时位置,则任何应用都无法正常运行
2)您无法接收FCM高优先级通知
3)如果应用不在托盘中,则将没有时间特定的任务/作业会执行,等等。
解
用户需要在应用程序的设置中启用自动启动功能,以保持后台服务/作业的运行。默认情况下,该功能处于关闭状态。要在我们可以使用的某些设备中执行此操作,
样例代码
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent();
String manufacturer = android.os.Build.MANUFACTURER;
switch (manufacturer) {
case "xiaomi":
intent.setComponent(new ComponentName("com.miui.securitycenter",
"com.miui.permcenter.autostart.AutoStartManagementActivity"));
break;
case "oppo":
intent.setComponent(new ComponentName("com.coloros.safecenter",
"com.coloros.safecenter.permission.startup.StartupAppListActivity"));
break;
case "vivo":
intent.setComponent(new ComponentName("com.vivo.permissionmanager",
"com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
break;
}
List<ResolveInfo> arrayList = getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (arrayList.size() > 0) {
startActivity(intent);
}
}
}
Run Code Online (Sandbox Code Playgroud)
消息来源:/sf/ask/3699461181/#52943903
| 归档时间: |
|
| 查看次数: |
3705 次 |
| 最近记录: |