6

what is the use of ActivityManager.isUserAMonkey() method?

ActivityManager.isUserAMonkey()
5hssba
  • 8,079
  • 2
  • 33
  • 35
  • possible duplicate of [What exactly is a monkey doing messing with my Android phone?](http://stackoverflow.com/questions/7546402/what-exactly-is-a-monkey-doing-messing-with-my-android-phone) or [Strange function in ActivityManager : isUserAMonkey- what does this mean, what is its use?](http://stackoverflow.com/questions/7792123/strange-function-in-activitymanager-isuseramonkey-what-does-this-mean-what-i) – Rup Mar 26 '12 at 09:52

3 Answers3

5

It will tell you if the user is the Test Monkey or the monkey runner. "The Monkey is a command-line tool that that you can run on any emulator instance or on a device. It sends a pseudo-random stream of user events into the system, which acts as a stress test on the application software you are developing."

You can use it like that:

public boolean wasItTheMonkey(){

     ActivityManager activityManager =  (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

     if(activityManager.isUserAMonkey()) {

           Log.d(TAG,"it was the monkey");
           return true;

     }

     Log.d(TAG,"it was an user");
     return false;
}

See here.

Chris
  • 4,403
  • 4
  • 42
  • 54
3

Monkey is an Android test suite designed to provide reproducible input events to your application. I would imagine the method is related to that.

adelphus
  • 10,116
  • 5
  • 36
  • 46
2

This function returns "true" if the user interface is currently being messed with by a monkey..and The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.... See this link

5hssba
  • 8,079
  • 2
  • 33
  • 35