首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >可处理意图{ act=android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS dat=package:com.example.batterop }的活动

可处理意图{ act=android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS dat=package:com.example.batterop }的活动
EN

Stack Overflow用户
提问于 2022-03-08 17:49:16
回答 1查看 631关注 0票数 1
代码语言:javascript
运行
复制
when run this code that exception throw 
Intent intent=new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);  //intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);  //intent.setData(Uri.parse("package:" + getPackageName()));

//intent.addCategory(Intent.CATEGORY_ALTERNATIVE);Uri uri =Uri.fromParts(“包”,getPackageName(),空);intent.setData(uri);startActivity(意图);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(意图);

代码语言:javascript
运行
复制
2022-03-08 22:55:45.172 3715-3715/com.example.batterop E/Error: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS dat=package:com.example.batterop } 
EN

回答 1

Stack Overflow用户

发布于 2022-08-30 18:40:21

添加Manifest文件:

代码语言:javascript
运行
复制
 <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

在科特林用这样的词:

代码语言:javascript
运行
复制
  @SuppressLint("BatteryLife")
    fun permissionBattery() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            val packageName: String = baseContext.packageName
            val pm: PowerManager =
                baseContext.getSystemService(Context.POWER_SERVICE) as PowerManager
            if (!pm.isIgnoringBatteryOptimizations(packageName)) {
                val intent = Intent()
                intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
                intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
                intent.data = Uri.parse("package:$packageName")
                baseContext.startActivity(intent)
            }

        }


    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71399428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档