android - devicePolicyManager.lockNow() is not working for Motorola Tablets -
android - devicePolicyManager.lockNow() is not working for Motorola Tablets -
public final static void lockdevice() { seek { if (devicepolicymanager.isadminactive(admincomponent)) { devicepolicymanager.locknow(); } } grab (final exception ex) { ... } }
the above code not throw exception nor locks screen motorola xoom tablets only. (both homeycomb , icecream sandwitch) same code works on other homeycomb , ics tablets.
i googled, did not solution. ideas.....?
possible reasons problem
1) think there problem receiver's meta-data in androidmanifest.xml
2) haven't added right class(extended deviceadminreceiver) either admincomponent or android:name property of receiver.
after spending lot of time on have created code.
code main activity
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); } } }
create new class - darclass - code
import android.app.admin.deviceadminreceiver; public class darclass extends deviceadminreceiver{ }
create folder 'xml' in 'res'. create my_admin.xml file in 'xml' folder. code my_admin.xml. note add together receiver after </activity>
, 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>
finally add together receiver given bellow 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>
it should work on device.
android locking motorola block-device device-policy-manager
Comments
Post a Comment