问题
I am trying to automate android app(Relocation services)using robotium. In this app there are media section and email and phone native dialer options so when i click on any of this option(Video, audio, phone, email) it takes you to the native app(video,audio, phone, email) of the phone. So how to handle external application activity using robotium(Like click on back button to come back to my app, or close native camera or video app to come back to my app)
Any answer will be great help.
回答1:
I think, Using Robotium
you can't access other application resources from your target testing application.
Just use Instrumentation
for this,
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
But be sure if you are doing this in Activity
then put this in separate thread for run this code..
回答2:
You can only access your own app from within the instrumentation framework. There are some options:
- remove the default apps and add some fake apps to handle the intent (see https://github.com/bryanl/FakeCamera) for an example. to remove the app: http://oneclickandroid.blogspot.de/2009/01/how-to-remove-defaultpreloaded.html
- resign the apps you want to control with your key so you can instrument them (see http://code.google.com/p/robotium/wiki/RobotiumForPreInstalledApps)
- install your app with system permissions ( Android INJECT_EVENTS permission ), but haven't tried method yet
回答3:
Sorry to bump this...
I've just put the camera stub and gallery stub that I made / use on the play store... thought might be of use to you / others for testing the camera and gallery in automated tests :)
https://play.google.com/store/apps/details?id=com.hitherejoe.CameraStub&hl=en
https://play.google.com/store/apps/details?id=com.hitherejoe.GalleryStub&hl=en_GB
来源:https://stackoverflow.com/questions/9696449/how-to-handle-external-application-activity-in-android-using-robotium