devicePolicyManager.lockNow()不工作的摩托罗拉平板电脑 [英] devicePolicyManager.lockNow() is not working for Motorola Tablets
问题描述
public final static void lockDevice()
{
try
{
if (devicePolicyManager.isAdminActive(adminComponent))
{
devicePolicyManager.lockNow();
}
}
catch (final Exception ex)
{
...
}
}
以上code不抛出任何异常,也没有锁定在屏幕上仅摩托罗拉Xoom平板电脑。 (无论Homeycomb和冰淇淋Sandwitch)同样code完美的作品在其他Homeycomb和ICS平板电脑。
The above code does not throw any exception nor it locks the screen for motorola xoom tablets only. (Both Homeycomb and Icecream Sandwitch) The same code works perfectly on other Homeycomb and ICS tablets.
我用Google搜索,但没有得到任何解决方案。任何想法.....?
I googled, but did not get any solution. Any Ideas.....?
推荐答案
可能的原因问题
1)我认为有一些问题,接收器的元数据在AndroidManifest.xml中
1) I think there is some problem with receiver's meta-data in your AndroidManifest.xml
2)你还没有添加正确的类(扩展DeviceAdminReceiver)要么adminComponent或到Android:接收器的name属性。
2) You haven't added the correct class(extended with DeviceAdminReceiver) to either adminComponent OR to android:name property of receiver.
在这个花费大量的时间我已经创建了code。
After spending lot of time on this i have created the code.
code为主要活动
public class LockerTest extends Activity {
protected static final int REQUEST_ENABLE = 0;
DevicePolicyManager devicePolicyManager;
ComponentName adminComponent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(btnListener);
}
Button.OnClickListener btnListener = new Button.OnClickListener() {
public void onClick(View v) {
adminComponent = new ComponentName(LockerTest.this, Darclass.class);
devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
if (!devicePolicyManager.isAdminActive(adminComponent)) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponent);
startActivityForResult(intent, REQUEST_ENABLE);
} else {
devicePolicyManager.lockNow();
}
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (REQUEST_ENABLE == requestCode) {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
创建一个新的类 - Darclass - code
import android.app.admin.DeviceAdminReceiver;
public class Darclass extends DeviceAdminReceiver{
}
创建文件夹XML中的资源。然后创建XML文件夹my_admin.xml文件。 $ C $下my_admin.xml。注意在&LT添加此接收器; /活动>
和前< /用途>
Create a folder 'xml' in 'res'. Then create my_admin.xml file in 'xml' folder. Code for my_admin.xml. Note add this receiver after </activity>
and before </application>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
</uses-policies>
</device-admin>
最后补充波纹管给你的AndroidManifest.xml中接收
Finally add the receiver given bellow to your AndroidManifest.xml
<receiver
android:name=".Darclass"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/my_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
它应该在设备上运行。
这篇关于devicePolicyManager.lockNow()不工作的摩托罗拉平板电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!