Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data passing to another application in Android

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 hereenter image description here

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

like image 772
Dinesh Chandra Avatar asked Jul 01 '14 14:07

Dinesh Chandra


People also ask

Can an app access data from another app?

Apps won't be able to access other apps' data from May 5, according to Google's new policy. Many users may not be aware that any single app on your smartphone can see every other app that you have installed on your device.

How pass data from activity to another activity in Android?

putExtra() method is used for send the data, data in key-value pair key is variable name and value can be Int, String, Float etc. getStringExtra() method is for getting the data(key) which is send by above method. according the data type of value there are other methods like getIntExtra(), getFloatExtra()


2 Answers

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

like image 100
Manuel Allenspach Avatar answered Sep 22 '22 23:09

Manuel Allenspach


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);
like image 20
Anandroid Avatar answered Sep 20 '22 23:09

Anandroid