java - Android DevicePolicyManager lockNow() -
i'm new android development, that's why hit wall. want application running service, , monitors sms. if specific sms message received, locks phone (as if lock period has expired). kinda remote lock.
i used devicepolicymanager invoke locknow() method. however, triggers error right on part locknow() called.
here's sample code on activity:
public class smsmessagingactivity extends activity { /** called when activity first created. */ public static devicepolicymanager mdpm; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); mdpm = (devicepolicymanager)getsystemservice(context.device_policy_service); } public static void locknow(){ mdpm.locknow(); } } i looked @ http://developer.android.com/resources/samples/apidemos/src/com/example/android/apis/app/deviceadminsample.html reference example.
can me? show me what's wrong code? have tweak enable administrative rights on emulator or device?
thanks!
here's docs:
the calling device admin must have requested uses_policy_force_lock able call method; if has not, security exception thrown.
therefore, should following in oncreate:
componentname devadminreceiver; // have been declared in class body // in oncreate mdpm = (devicepolicymanager)getsystemservice(context.device_policy_service); devadminreceiver = new componentname(context, deviceadminreceiver.class); //then in onresume boolean admin = mdpm.isadminactive(devadminreceiver); if (admin) mdpm.locknow(); else log.i(tag,"not admin"); on side note, example code activity.
that, , should use broadcast receiver implement , monitor sms.
here's api example receiving sms:
Comments
Post a Comment