android 配置启动参数,Android10开机启动和网络 参数设置 华为EMUI11

开机启动

1、需要请求忽略电池优化

@RequiresApi(api = Build.VERSION_CODES.M)

public void ignoreBatteryOptimization() {

try{

PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);

boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(this.getPackageName());

if(!hasIgnored) {

Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);

intent.setData(Uri.parse("package:"+getPackageName()));

startActivity(intent);

}

}catch(Exception e){

//TODO :handle exception

}

}

2、在 设置里面,打开《应用后台启动、等信息 全部开启》

1e5621901da8b43fc189789d9abd5bd9.png

5f875774bc1f2a333888fc2cb74039a7.png

2636632d3f9318dbe7e0065032c25b40.png

3、添加开机启动权限

请求网络服务

需要在工程路径res/xml路径存储  network_security_config.xml文件 配合下面代码段观看

13c58771e69eea925c69a74f21953677.png

下面是详细配置的XML

package="com.***.***.***">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher_round"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:requestLegacyExternalStorage="true"

android:networkSecurityConfig="@xml/network_security_config"

android:theme="@style/Theme.**">

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值