我在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());
}
}
}
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>
答案 0 :(得分:0)
我也已经在我的主类中实现了以下这些行以开始自动启动,
Intent intent = new Intent();
String manufacturer = android.os.Build.MANUFACTURER;
System.out.println("manufacturer : "+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"));
// intent.setComponent(new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity"));
break;
case "vivo":
intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
break;
case "Honor":
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
break;
/*case "samsung":
intent.setComponent(new ComponentName("com.samsung.android.lool", "com.samsung.android.sm.ui.battery.BatteryActivity"));
break;*/
case "htc":
intent.setComponent(new ComponentName("com.htc.pitroad", "com.htc.pitroad.landingpage.activity.LandingPageActivity"));
break;
case "asus":
intent.setComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.MainActivity"));
break;
}
List<ResolveInfo> arrayList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (arrayList.size() > 0) { startActivity(intent); }
但是在oppo的情况下,不会通过这些行收到通知。
答案 1 :(得分:0)
从近期任务中删除,系统将立即终止该应用程序。因此,请勿执行此操作。
Firebase在中国被GFW阻止。 Google服务无法在中国使用。如果要在中国使用Firebase,请启用VPN。
从8.0开始,API的限制为:https://developer.android.com/about/versions/oreo/background
在中国以外,没有网络问题。 OEM系统具有自己的后台行为限制。即使不从最近删除,当应用程序在后台运行时,它也会被杀死。即使服务startForeground(),它们也不遵循API行为。 很难保留任何后台服务。用户必须先将其添加到白名单中。但是每个OEM系统都有不同的方式。
我就是中国的Android程序员...