一些Android设备由于定制的Android调整由制造商完成,有一些关于电源管理的政治,打破了一些功能,如推送通知.
我想收集意图来启动各自的工具,但我发现只有华为和小米.
Intent INTENT_HUAWEI = new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
Intent INTENT_XIAOMI = new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
if (getPackageManager().resolveActivity(INTENT_HUAWEI, PackageManager.MATCH_DEFAULT_ONLY) != null)
startActivity(INTENT_HUAWEI);
else if (getPackageManager().resolveActivity(INTENT_XIAOMI, PackageManager.MATCH_DEFAULT_ONLY) != null)
startActivity(INTENT_XIAOMI);
Run Code Online (Sandbox Code Playgroud)
我需要其他所有制作人的帮助
我已经startforeground()在我用了Service,但是Service当我清除所有最近的应用程序时,Android一直在杀死我.
这是我的服务代码:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Text")
.setTicker("Text")
.setContentText("Text")
.setSmallIcon(R.drawable.icon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon))
.build();
startForeground(100, notification);
return START_STICKY;
}
Run Code Online (Sandbox Code Playgroud)
我用这段代码做错了吗?