Transferring data to another Android application

I have two Android apps (app A, app B) as shown in the image below. I want to call application B by clicking the β€œFirst” button from application β€œA”, and when application β€œB” starts, the text box will contain the text that I want to transfer from application A.

** Note.

  • I have access to Application A, so I can change the code of application A. I do not have access to application B.

  • I saw a lot of posts on Stackoverflow.com and other sites that explain data transfer to the second application, but I saw that this is only possible when you have access to code modifications of both classes. Here, in my case, I do not have access to application 2, it is just an APK that is installed on my phone.

  • I just want to implement how we did this to automate the web page through Selenium, where we can access the text field and enter a value in this text field and.

  • Appendix B is for reference only. It can be any application with text fields.

  • Actually, I want to automate the process of logging in to the application (Applicaion B) using application A. Application A has several credentials, and selecting credentials from application A, it will launch application B and enter the credit status on the login screen of application B. **

enter image description hereenter image description here

Hope I can explain my problem. If I need more information, I can explain.

+6
source share
7 answers

You have 2 options:

  • Appendix B is awaiting input (through intent). Then you can run application B and pass the value using the intent:

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

    You need to know which key application B uses, otherwise you cannot do this.

  • Appendix B does not wait for input . This is not easy and requires root access to the phone:

    With permission INJECT_EVENTS, you can type text or send clicks to any window. You can do it:

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

    You can find in this section here . If you need help compiling your application, these 2 links will help you: How to compile an Android application with system rights , Android Permission INJECT_EVENTS

+7
source

Pass the data below. And then get it from another application.

 PackageManager pm = context.getPackageManager(); Intent appStartIntent = pm.getLaunchIntentForPackage(appPackageName); context.startActivity(appStartIntent); 
+2
source

I don’t think it’s possible, since you have no control over application B. Since there are several ways to send data to application B from A (intent, content provider and broadcast receivers, etc.), but you don’t know that B will accept these values ​​or not and will manipulate the views according to the data sent from A, since you have no control over B.

+2
source

I will just give you a head so that you can transfer data between the two applications that you manage 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); } 
+1
source

If another application has not configured the intention to get a different application value, it cannot be executed. If you need to do this, convert B APK and then add an implicit intention to process the data forms you need and create a new APK

+1
source

If you are trying to write tests or do something in an automated way (similar to scirpts WebDriver), you can use MonkeyRunner http://developer.android.com/tools/help/monkeyrunner_concepts.html but which connects remotely to the device via adb from the host computer .

Depending on how application B fills in the data in these input fields, you may interact with the content provider of application B. You will probably want to chat with the author of application B in this case.

+1
source

Starting with API 18, there is a UiAutomation class that can send custom events to other applications without INJECT_EVENTS permission.

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

0
source

Source: https://habr.com/ru/post/971601/


All Articles