6

I have two Android Application(Application A,Application B) as shown in below figure. I want to call application B by clicking on Button from first Application A and when Application B launches then the text box will contain the text which I want to pass from Application A.

**Note-

  1. I have access of Application A so I can modify the code of Application A . I have no access to application B.

  2. I have seen many post on Stackoverflow.com and other sites that explain passing data to second application but I saw it is only possible when you have access to modify the code of both class. Here in my case I have no access to Application 2, It is just a APK which is installed on my phone.

  3. I want to just implement like we did in automating a web page through Selenium where we can access a text field and enter value in that text field and .

  4. Application B only for example purpose. It can be any Application having text boxes.

  5. Actually I want to automate the login process of an application(Applicaion B) with the help of Application A .Application A have a number of credential and by selecting a credential from Application A it will launch the Application B and enter the credentioal to Login screen of Application B . **

enter image description here enter image description here

Hope I am able to explain my problem.If some more input require I can explain.

Dinesh Chandra
  • 329
  • 1
  • 2
  • 27

7 Answers7

7

You have 2 options:

  • Application B expects an input (via intent). Then you can launch the app B and pass the value via intent:

    intent.putExtra("Key", "Your data here");
    

    You need to know which key the application B uses, otherwise you can't do this.

  • Application B doesn't expect an input. This is not easy and requieres root-access to the phone:

    With the permission INJECT_EVENTS it is possible to type text or send clicks to any window. You can do this:

    Instrumentation m_Instrumentation = new Instrumentation();
    m_Instrumentation.sendKeyDownUpSync( KeyEvent.KEYCODE_B ); //send key B
    

    you can find more to this topic here. If you need help to compile your app, these 2 links will help you: How to compile Android Application with system permissions, Android INJECT_EVENTS permission

Community
  • 1
  • 1
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
  • After going through link provided by you it seems that it is possible. I am able to do it within same application but got stuck in when calling to second appication and Injecting value in that applicaion field. – Dinesh Chandra Jul 09 '14 at 11:50
2

Pass the data to the below intent. And then get it from the other app.

PackageManager pm = context.getPackageManager();
Intent appStartIntent = pm.getLaunchIntentForPackage(appPackageName);
context.startActivity(appStartIntent);
Anandroid
  • 403
  • 4
  • 14
2

I don't think this is possible as you do not have any control over the application B.As there are several ways of sending data to application B from A(intent,Content provider and Broadcast recievers etc) but you do not know will B accept those values or not and will manipulate the views according to the data you have sent from A as you have no control over the B.

Pramod Yadav
  • 2,316
  • 2
  • 23
  • 36
1

i'm just gonna give you a heads up in order for you to pass data between two application which you have control over them, then you should use intent for example

intent.putExtra("MyData", "This is a data ");

and in your other application use this to get this data

    Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("MyData");
    myText.setText(value);
}
Kosh
  • 6,140
  • 3
  • 36
  • 67
  • @SweetWisherツ as you can see he has updated his question, before that he never mentioned anything about it, and as you can see from my answer i purposely stated i'm just gonna give you a heads up in order for you to pass data **between two application which you have control over them**, then you should use intent for example – Kosh Jul 04 '14 at 06:28
  • @SweetWisherツ as you can see from his question, he forgot to edit this **I have two Android Application(Application A,Application B)** which make it more clearer, so do me a favor and remove your down vote. – Kosh Jul 04 '14 at 06:32
1

Unless another application has set up an intent to receive another application's value, it can't be done. If you have to do it, reverse engineer B's APK, then add implicit intent to handle forms of data you need and create a newer APK

Bijay Koirala
  • 525
  • 5
  • 9
1

If you're trying to write tests or do something in an automated fashion (similar to WebDriver scirpts) you can use MonkeyRunner http://developer.android.com/tools/help/monkeyrunner_concepts.html but that connects remotely to a device over adb from a host computer.

Depending on how application B populates the data in those input fields you may be able to interact with application B's content provider. You'd probably want to communicate with the author of Application B in that case.

PaulR
  • 3,223
  • 1
  • 21
  • 32
  • In this case I am not wrtting the test cases but exactly want to do the same through Aoolication A.Please read the point Note:-5 to get more Idea about the same. – Dinesh Chandra Jul 09 '14 at 11:45
0

Starting from API 18 there is UiAutomation class, which can send custom events to other applications without need of INJECT_EVENTS permission.

For more information see http://developer.android.com/reference/android/app/Instrumentation.html#getUiAutomation()