1

I want to create an application that will lock the screen of the android device.

For example, Android A and Android B is connected to the same network/wifi. Is it possible to control Android A by Android B? I just want to lock the screen of Android A using B.

MMakati
  • 693
  • 1
  • 15
  • 33

2 Answers2

4

If:

  • Your app is installed on both A and B, and

  • You arrange for B to notify A that it needs to be locked, and

  • Your app on A is a properly-configured device administrator

Then your app on A can call lockNow() on DevicePolicyManager to lock the device.

The part that you ABSOLUTELY HAVE TO GET RIGHT is the communications from B to A. What you do not want to do is allow arbitrary other parties, such as the world's script kiddies, to go around locking people's devices on them. Using something (relatively) assured to be local, like Bluetooth, would help in this regard.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Do you have sample codes, or snippets or how to start with this? I don't know what to search in the internet. Thanks. – MMakati Dec 09 '13 at 15:13
  • 1
    @MMakati: Please be more specific. I mean, to learn how to program in Android, visit http://developer.android.com. If that is not what you meant, please explain **precisely** what you are lacking. – CommonsWare Dec 09 '13 at 15:35
  • @MMakati Asking for code snippets aren't a way to resolve issue, Instead how about doing R&D yourself first and then include it in question if it's not resolved still. – Paresh Mayani Feb 28 '14 at 17:00
1

Yes, it is possible, but you have to deploy your programs on device A and B. You need a program which have a service and accepts connections to it in the background. This is device A. On device A you have to write a code snippet, like this How to programmatically lock screen in Android?

And on device B you have to have a program which communicates with this service on device A.

If you're not developing this for just yourself I think you should consider safety above all. (not enabling for anyone to just lock anyone else's screen)

Community
  • 1
  • 1
abbath
  • 2,444
  • 4
  • 28
  • 40
  • Do you have sample codes for this. I dont know how to search this one in google. probably I don't know the proper terms for this one. – MMakati Dec 09 '13 at 15:11
  • I have a link in the reply (this : http://stackoverflow.com/questions/3594532/how-to-programmaticaly-lock-screen-in-android) this is for locking. – abbath Dec 09 '13 at 15:13
  • For communication there are a couple of choices; the mentioned bluetooth, or through http. For the service in the background, check this page http://developer.android.com/reference/android/app/Service.html – abbath Dec 09 '13 at 15:15
  • If I want to do over the wifi connection. what is the best way to do? – MMakati Dec 09 '13 at 15:16
  • 1
    check these search words "device to device communication android" google will help you with pages like this: http://stackoverflow.com/questions/5396220/device-to-device-communication-in-android – abbath Dec 09 '13 at 15:23