share an object between two apps - android

I want to send an object between two apps .For instance , you can imagin ,there are two apps which calls app A and app B.App A is running and app B should send an object to app A and after reciving the object by app A , app A shold response that I recive the object .
I study several web site but unfortunately I can't understand many thin ,just I understod , there is a simple way for doing this whit SharedPreferences class. I don't want to use this way becuase I don't want the object to save ...
please guid me.
Thanks.

You can use Intents for that. Just send an Intent for Activity Z of App A in App B and put your parameters in the Extras bundle.
In Activity Z do the same with the reply for Activity Y of App B.

Related

Android SIP send location

I'm developing an app with the SDK API SIP. Ive got all the call stablishment ok, but my real problem is that i want to show the location of the user that is calling me during the proccess of call.
I've been reading about PARCEL cause SIP API have 2 functions of it, but i dont think thats the way. I just want to send the coordinates to put them in the API that Google offers me to show the map.
Does anybody can tell me an idea of how to send those values from the caller to the receiver??
Could be a solution, put those values as extra values in the PendingIntent that u create for the open function? If i the caller put them in, the receiver will receive them?
Thanks!!!
Yep, I'm noob in android. It's my first app XD

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-
I have access of Application A so I can modify the code of Application A . I have no access to application B.
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.
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 .
Application B only for example purpose. It can be any Application having text boxes.
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 .
**
Hope I am able to explain my problem.If some more input require I can explain.
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
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);
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.
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);
}
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
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.
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()

Is there a way to have two different android applications communicate?

I want to make it so that when my app is selected, another app will pop up. Is this possible with intent and service?
Yes it is possible.
You have a couple of ways to do this, here is two of them:
If you need some kind of long connection and need to move data between the application, you can use two services, one in each side and then communicate with Messenger object. Messenger object is use to implement a message-based communication across processes - two different applications, it's easy to use once you get the idea.
If you need only to start other app when your app is selected you can start an intent with the intent filter you set in the manifest of the app you want to start. This is what you need if you only need to start the second application, without any connection between them.
If you need to start the calculator application, you can try to do it like this:
Intent i = new Intent();
i.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
startActivity(i);
yes it is very much possible
to communicate between the apps use Content Provider
Intent can be use to launch other apps.
you can use IPC (interprocess communication). You can find the doc here

android - is it possible to use private intents instead of global ones?

background:
i've noticed that for regular activities within, it is possible for any application to open the activities of my app .
question:
is it possible to allow only my own app (or apps , or package) to send and receive intents inside the same scope , so that other application won't be able to receive them or interfere with the flow of the app?
example:
suppose i have a broadcastReceiver that listens to some kind of intent , but this intent is only meant to be used by another service/activity that resides either inside my app , or inside another app that i've created , but i don't want others to be able to use this intent.
please help me.
setPackage()
Set an explicit application package name that limits the components this Intent will resolve to. If left to the default value of null, all components in all applications will considered. If non-null, the Intent can only match the components in the given application package.
or you can use setSelector() , but not both.
suppose i have a broadcastReceiver that listens to some kind of intent , but this intent is only meant to be used by another service/activity that resides either inside my app , or inside another app that i've created , but i don't want others to be able to use this intent.
In addition to Reno's fine answer, for your specific requirement quoted above, use LocalBroadcastManager. Not only do you get the security you seek, but it is more efficient. LocalBroadcastManager is available in the Android Support package and AFAIK should work going back to Android 1.6. Here is a sample project using LocalBroadcastManager.

Who manages interlal application intents?

I was studying some sample examples for Android and one of them got me really curious:
the NoteList (or Notepad) example application - here
My question is: Is there any way to make a NoteList shortcut, that always starts the application with its 'Editor' activity, for example. [of course if the creator of that 'third-party' application intended to make it possible by describing the entry points of its application in a proper way in the manifest file. I do not intent to create malware.]
in other words:
Can a third-party application (like the one I wish to make :) ) to get to internal application intents {i.e. action, activity, data} or this is handled by Android and no one else?
What gave the idea that this is possible was the following case:
I opened NoteList, created a few note, and when I was editing the title of one of the notes - I pressed HOME, when I clicked on the icon of NoteList I got the exact same state of the application - editing the title of the note.
thanks!
One has nothing to do with the other. That means that reopen an activity which was paused or killed with a data restoring logic just restores the last state. This is what happened in your example.
Now what you mean I guess is if there is a way to tell Android that you application can do a certain thing thus it should be shown as an option in the action chooser. Yes that is possible through intent filters.
The Intent reference page might also be very informative for you.

Categories

Resources