1

I'm trying to create an application that allow the user to lock his android device with a password from a website. So i must find a method to lock the device programmatically, it means is there any one that have a code that allow me to set a password for the device and when i unlock my screen it demands to enter the code to access to the home?

kaiz.net
  • 1,984
  • 3
  • 23
  • 31
emna
  • 423
  • 2
  • 6
  • 18

2 Answers2

3

The selected answer is right on the money.

Having said that, if you are interested, here is some sample code you can take a look at:

A PolicyManager that performs remote Locking and remote wiping: http://openmobster.googlecode.com/svn/trunk/cloud/android/connection/src/main/java/org/openmobster/core/mobileCloud/android/module/connection/PolicyManager.java

The AndroidManifest declaration of the receiver:

<receiver android:name="org.openmobster.core.mobileCloud.android.module.connection.PolicyManager$PolicyReceiver"
        android:label="OpenMobster Device Administrator"
        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> 

res/xml/device_admin.xml: http://openmobster.googlecode.com/svn/trunk/cloud/android/cloudManager/res/xml/device_admin.xml

This should give an idea of the PolicyManager code and its corresponding configuration.

As per providing a communication between the server and the device goes, you can use a persistent TCP connection between the two entities. Here is some sample code on how to do that

Creating and Managing a persistent TCP socket: http://openmobster.googlecode.com/svn/trunk/cloud/android/connection/src/main/java/org/openmobster/core/mobileCloud/android/module/connection/NotificationListener.java

Hope this helps with getting started

openmobster
  • 1,027
  • 5
  • 17
1

Check of DevicePolicyManager, http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html

Specifically, the resetPassword, and lockNow() methods.

Please read the entire device admin tutorial to understand how to use DPM in context, http://developer.android.com/guide/topics/admin/device-admin.html

As for locking from the website. android c2dm is the preferred way to get push messages to the device. http://code.google.com/android/c2dm/

Note however that this is intended for occasional "wake up" messages, not for any sort of 2-way communication between the device and some other entity.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
  • 1
    Instead of C2DM now there is GCM. Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection. – hB0 Jun 27 '13 at 05:46