gpt4 book ai didi

java - 如何覆盖android中的权限管理器

转载 作者:行者123 更新时间:2023-11-30 01:51:00 25 4
gpt4 key购买 nike

我正在创建有权在启动时自动启动的应用程序。并且它在那些不包含权限管理器的手机上运行良好。

我想像 Whats App 和微信以及其他应用程序一样启动我的应用程序。但权限管理器阻止我的应用程序自动启动 - MI Redme Note 4g 手机和三星手机。基本上,我想覆盖权限管理器设置,以便我的应用启动

目前我正在使用这些代码

 <receiver
android:name=".BootComplete"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<service android:name=".AutoStartUp" >
</service>

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

请建议我让我的应用程序像Whats App、Wechat、Youtube 和其他应用程序一样自动启动

提前致谢

最佳答案

你的代码在这里做的是:当设备启动时,它会告诉广播接收器,现在广播接收器需要启动服务或应用程序或任何你想启动的:

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyBroadcastReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent0) {



if(! isMyServiceRunning(MyFirstService.class, context)){//test

Intent startServiceIntent = new Intent(context, MyFirstService.class);
context.startService(startServiceIntent);
}




}

private boolean isMyServiceRunning(Class<?> serviceClass,Context context) {


ActivityManager manager = (ActivityManager)context. getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}

}

此代码还会检查服务是否已在运行(出于某种原因),如果需要,您可以删除该部分。

关于java - 如何覆盖android中的权限管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33052425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com