gpt4 book ai didi

java - 无法解析符号 '@xml/device_admin'

转载 作者:搜寻专家 更新时间:2023-11-01 08:24:02 24 4
gpt4 key购买 nike

我正在尝试在 Android 5.1 设备上实现屏幕固定。我遇到了This Answer ,并尝试将 intent-filter 添加到我的 list 中,我收到此错误:Cannot resolve symbol '@xml/device_admin'

我假设这是因为 xml/device_admin 不存在,所以如果是这种情况,我应该在哪里创建它?

我的 list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="MY_PACKAGE">

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.app.action.PROFILE_PROVISIONING_COMPLETE" />
</intent-filter>
</activity>

<receiver
android:name=".MyDeviceAdminReceiver"
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" />

<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<!-- <receiver android:name=".BootReceiver"> -->
<!-- <intent-filter > -->
<!-- <action android:name="android.intent.action.BOOT_COMPLETED"/> -->
<!-- </intent-filter> -->
<!-- </receiver> -->

</application>

</manifest>

我的主要 Activity

package MY_PACKAGE;

import android.content.ComponentName;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.app.admin.*;

public class MainActivity extends AppCompatActivity {

private WebView mWebView;
private static final String TAG = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ComponentName deviceAdmin = new ComponentName(this, MyDeviceAdminReceiver.class);
DevicePolicyManager mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

mWebView = (WebView) findViewById(R.id.activity_main_webview);

// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("my_website.com"); //Note that this is a placeholder website.

if (mDpm.isDeviceOwnerApp(getPackageName())) {
mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
}

if (mDpm.isLockTaskPermitted(this.getPackageName()))
startLockTask();

// try {
// Runtime.getRuntime().exec("dpm set-device-owner MY_PACKAGE/.MyDeviceAdminReceiver");
// } catch (Exception e) {
// Log.e(TAG, "device owner not set");
// Log.e(TAG, e.toString());
// e.printStackTrace();
// }

try {
startLockTask();
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
System.out.print("LOCKED IN PLACE!");
}
}



}

最佳答案

I assume this is because xml/device_admin doesn't exist, so if this is the case, where do I create it?

在层次结构中创建文件夹 application/src/main/res/xml 将文件 device_admin.xml 保存在此 XML 文件夹中

device_admin.xml 文件的结构是

<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
<disable-camera />
</uses-policies>
</device-admin>

Device_admin GuideLine

关于java - 无法解析符号 '@xml/device_admin',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47191668/

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