我无法在设备上
问题描述:
我一直在努力通过亚行外壳DPM命令设置我的应用,设备所有者我的应用程序设置设备所有者但错误出来我无法在设备上
Error: Bad admin: ComponentInfo{com.example.oshao.autolock/com.example.oshao.
autolock.AdminReceiver}
这里是我的活动和表现
public class MainActivity extends AppCompatActivity {
private DevicePolicyManager mDpm;
private boolean isKioskModeEnabled = false;
private Button btnEnabled;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnEnabled = (Button) findViewById(R.id.btnEnable);
btnEnabled.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
enableKioskMode(!isKioskModeEnabled);
}
});
ComponentName deviceAdmin = new ComponentName(this, AdminReceiver.class);
mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
if (!mDpm.isAdminActive(deviceAdmin)) {
Toast.makeText(this, "This ap is not a device admin", Toast.LENGTH_SHORT).show();
}
if (mDpm.isDeviceOwnerApp(getPackageName())) {
mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
} else {
Toast.makeText(this, "This app is not the device owner", Toast.LENGTH_SHORT).show();
}
}
private void enableKioskMode(boolean enabled) {
if (enabled) {
if (mDpm.isLockTaskPermitted(this.getPackageName())) {
startLockTask();
isKioskModeEnabled = true;
btnEnabled.setText("Exit Kiosk Mode");
} else {
Toast.makeText(this, "Kiosk Mode is not permitted", Toast.LENGTH_SHORT).show();
}
} else {
stopLockTask();
isKioskModeEnabled = false;
btnEnabled.setText("Enter Kiosk Mode");
}
}
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
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>
</activity>
<receiver
android:name="com.example.oshao.autolock.AdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.admin"
android:resource="@xml/device_admin"/>
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</application>
我不知道为什么误差仍然在那里,是因为一个设备只能有一个设置设备所有者单一的应用程序? 另一个问题是,adb命令可以在没有帐户的设备上实现,并连接到PC以便在终端中输入命令。我可以通过应用程序中的代码在设备没有扎根的情况下做到这一点,因为我有几个设备,它很难一一设置它们。谢谢
答
我解决了错误的管理错误:http://www.sureshjoshi.com/mobile/android-kiosk-mode-without-root/
我错过了src/main/res/xml/device_admin.xml
文件,其中仅包含:
<device-admin> </device-admin>
+0
我已经注意到丢失的文件,并将其添加到XML ...仍然无法正常工作,您尝试过的任何其他修改? –
可以有一个以上的应用为DeviceAdmin。检查此链接:https://developer.android.com/guide/topics/admin/device-admin.html –
尝试在清单中为AdminReceiver添加说明,如下所示:'' –
@AkhilSoman \t 我不认为增加在描述XML文件将解决adb错误,我已经试过了,谢谢。 –