Data passing to another application in Android

2019-03-28 05:55发布

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.

7条回答
你好瞎i
2楼-- · 2019-03-28 06:01

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()

查看更多
Juvenile、少年°
3楼-- · 2019-03-28 06:06

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.

查看更多
We Are One
4楼-- · 2019-03-28 06:06

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);
}
查看更多
老娘就宠你
5楼-- · 2019-03-28 06:08

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);
查看更多
三岁会撩人
6楼-- · 2019-03-28 06:08

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

查看更多
做个烂人
7楼-- · 2019-03-28 06:17

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.

查看更多
登录 后发表回答