无法解析符号“@xml/device_admin”

Cannot resolve symbol '@xml/device_admin'

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

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

我的清单

<?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>

我的 MainActivity

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