gpt4 book ai didi

java - 为什么 isLockTaskPermitted 标志为假

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:59:43 25 4
gpt4 key购买 nike

我正在尝试以编程方式在 Android L 上固定屏幕。我的应用程序包含带有

的 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<force-lock/>
<watch-login/>
<disable-camera/>
<disable-keyguard-features/>
<encrypted-storage/>
<expire-password/>
<limit-password/>
<reset-password/>
<set-global-proxy/>
<wipe-data/>
</uses-policies>
</device-admin>

我在定义 AdminReceiver 的 AndroidManifest 文件中使用正确的行安装了应用程序。几周前一切正常,但现在当我回到这个项目时 - 每次应用程序启动时,应用程序都会要求我确认“Pin screen”弹出窗口。

当我调试时,我注意到奇怪的行为devicePolicyManager.isAdminActive(componentName) 为真devicePolicyManager.isDeviceOwnerApp(getPackageName()) 为真

但是

devicePolicyManager.isLockTaskPermitted(getPackageName()) 为 false

使用 adb commend dpm set-device-owner ... 或将 device_owner.xml 文件推送到/data/system/将应用程序设置为设备所有者都没有关系

我的问题是为什么应用没有锁屏权限?

最佳答案

为此你必须调用setLockTaskPackages()

你的代码应该像下面这样。

你的 Activity 应该有

ComponentName mAdminComponentName = DeviceAdminReceiver.getComponentName(this);
//where this will be your Activity

DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager)
getSystemService(Context.DEVICE_POLICY_SERVICE);

mDevicePolicyManager.setLockTaskPackages(mAdminComponentName,new String[]{getPackageName()});

DeviceAdminReceiver.java

// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.codelabs.cosu;

/**
* Created by nyfuchs on 4/26/16.
*/

import android.content.ComponentName;
import android.content.Context;

/**
* Handles events related to the managed profile.
*/
public class DeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
private static final String TAG = "DeviceAdminReceiver";

/**
* @param context The context of the application.
* @return The component name of this component in the given context.
*/
public static ComponentName getComponentName(Context context) {
return new ComponentName(context.getApplicationContext(), DeviceAdminReceiver.class);
}
}

AndroidManifest.xml

    <receiver
android:name="com.google.codelabs.cosu.DeviceAdminReceiver"
android:description="@string/app_name"
android:label="@string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin_receiver" />
<intent-filter>
<action android:name="android.intent.action.DEVICE_ADMIN_ENABLED"/>
<action android:name="android.intent.action.PROFILE_PROVISIONING_COMPLETE"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

关于java - 为什么 isLockTaskPermitted 标志为假,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36908595/

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