Return message from called phonegap app - android

I have two apps created using Phonegap and, at the moment, they run only on Android devices. I call app2 from app1 using Intent. How can I have a return message (or something like this) from app2 to app1?
Thanks.
Omar

So app2 is somehow launching an intent to open up app1 and you want to pass some information from app2 into app1? Intents have a putExtra method that lets you attach more information to them that you can later read in app1; see this stackoverflow question: How do I create an android Intent that carries data?
Now, getting this to work with Cordova might be a bit more tricky - how are you launching the intent? If it is some sort of phonegap plugin, there is probably a way to use putExtra.

Related

Android - how to find Intent for installed app(s)

I know that an App (app2) I have installed on my device can be called from another App (app1). As app1 has a button that will bring up app2. Is there a way to determine what that Intent looks like to start app2 on my device? I want to modify my own app to do the same thing.
For example, this page on the Android Developers site shows you how to make implicit Intent calls for action.
https://developer.android.com/training/basics/intents/sending
But, is there a way to discover what Intents/Activities another App allows/makes-visible such that I can call app2 and open it?
App1 takes some contextual data and starts app2 with that data opened to the pertinent page
You are assuming that app2 has an activity supporting some Intent designed to do that.
Is there a way to determine what that Intent looks like to start app2 on my device?
Talk to the developer of app2.
There are a number of common Intent structures (ACTION_VIEW, ACTION_SEND, etc.). Using PackageManager, you can find out if app2 supports one of those. Through a fair bit of complexity, there are ways that you can get to the manifest and find the <intent-filter> structures supported by any given app2 on a device.
If you are referring to manually examining app2 to see what it supports, there are apps like this one that you can use.
Can I find out what key/value pairs it supports also?
Talk to the developer of app2. That information is internal to the app and is not published in places like the manifest. If app2 happens to be open source, you can examine the source code.

Is it possible to interact to other app like getting the id what view they tapped?

I'm developing an application that can determine the id of view on external app,
(e.g. I have two application, App1 and App2, what I'm going to make is App2 that can determine what App1 doing, like getting the id of the button on App1 using App2 and if gets an error the App2 will catch the log error)
is it possible?
You can interact between 2 application using bound service and Android Interface Definition Language (AIDL).
Check below link for more details.
https://developer.android.com/guide/components/bound-services.html
Other solutions are communicating with a server that stores the information that you need.
Or write the actions on a file accessible by both apps.
Obviously, all the solutions have pros and cons. In the first one, you need to have access to the internet, on the second you need to handle readings and writings simultaneous, etc.

Android call method from another app without starting it

I have two android applications with different packages App1 and App2. Suppose I want to call a method Method1 written in App1, from App2. One solution I found in the following link, Android call method from another app, suggested that we should register a BroadcastReceiver in App1 and call sendBroadcast() from App2. But the problem is, I could call the Method1 only if App1 is running in the background. Otherwise, nothing is happening.
How to resolve this issue? Are there any other ways to call Method1 without having to start App1?
But the problem is, I could call the Method1 only if App1 is running in the background.
This is incorrect, if you register any component (BroadcastReceiver, Service, Activity, etc.) in the AndroidManifest.xml and it is exported, other applications can trigger it with an Intent regardless of the current state of the application process.
Perhaps the issue you are running into is that the example you linked to registers the BroadcastReceiver in Java code. If you instead publish the <receiver> in your manifest, it will be externally accessible always. This is explained in the SDK Documentation for BroadcastReceiver.

Eclipse debugging - any way to pass in "extras" for launching intent?

I'm developing Activity which works on data passed in Intent in extras.
This Activity is supposed to be launched by other activities in my app.
However, during development/debugging, I launch this Activity directly, and want to simulate extras in Intent (obtained from getIntent) to pass in desired testing params (sort of command-line parameters).
In Eclipse Run configurations, I can just select Launch action, but no additional data.
Is there some way? Or I must hardcode testing params in java, and not forget to comment them out when testing is finished?
I think eclipse is just using something comparable to the am start method to launch an application. You should be able to do this manually via adb and specify extras; then once you have it working from the command line you can put it behind a button using eclipse's extensibility features.
Here's a writeup found during a brief search: http://learnandroid.blogspot.com/2008/01/run-android-application-from-command.html
I think you may want to just write some proper tests for this purpose.
Take a look at this:
Android Testing fundamentals
You could then be running your test during development, which would launch the Activity as you want it.

accessing one app from another app

Can someone explain me how to control one application from another application? I'm running a music player in an app1 using service class. And I want to stop that music player from another app.,i.e app2. But, I'm fallin short o the concept.
Depends what you need to do.
Opening another activity (or sending messages) is by using Intents:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
// ...
startActivity(intent);
Starting service is by using startService()
What you are trying to do can also be done using Intent broadcasts but only if your target app supports and listens to specific actions on the broadcast. You need to see if there is such an ACTION supported.
I'd like to continue this question a bit.
In my case, I'm developing the target app and I need to implement few simple procedure calls for the main app. Basically 'start', 'stop' and 'sendData'. As I wrote, I'm developing the target app so I can support whatever I want. Which would you say is the easiest way to handle.
The whole situation a bit more explained. Main app would like my app to start it's work, and if needed they'll request that I turn myself off and when the main app is closing it would request me to send my data forward.
I'm quite new to android development, so code snippets are preferable. Thank you.

Categories

Resources