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

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.

Related

Using adb to launch apps - using file as input and lacking activity name?

I would like to be able to launch specific apps over adb, reading them from a file.
For example - say I wish to launch 'com.ebay.mobile'. I have a file that has simply 'com.ebay.mobile' as the contents, and I'd then like to use a batch file to launch the contents of that file, for instance filling the rest of the command.
Obviously, this runs into difficulty with the lack of an activity name, so additionally, would it also be possible for the app to launch without specifying this, so the default activity launches?
Thanks for your help!
You can use the following 2 commands (you need to use both) to run an app - if you don't specify an Activity, it will use the Main one defined in the AndroidManifest file.
adb install yourAPKFile.apk
adn run com.your.package

How to create service project without any activity?

Just starting with android.
I try to create project that will send notification ( some bit for example ) to my FTP server every 3 hours.
I don't know how to create this project because each time i create new android project i must have only project with activity - and i don't need any activity - just need a service that will run when i install it on the device.
each time i create new android project i must have only project with activity
If you are using Eclipse, uncheck the "Create activity" checkbox that tells the new project wizard to create an activity.
If you are using android create project, yes, it will create an activity for you. You can delete the Java class and the manifest <activity> entry if you want.
In reality, you will wind up leaving all of it alone.
just need a service that will run when i install it on the device.
First, a service does not run just because you install it on the device. It only runs if you write code to cause it to run.
Second, while you might think "well, I will just get control at boot time and start the service then", that is possible, but it will not work on Android 3.1+ devices unless the user has run an activity first. This is to prevent "drive-by" malware.
So, I suggest that you leave the activity in there, if you want your app to work.
Moreover, unless this app is only for yourself, your users need the activity, to:
Control the behavior of the service, such as changing the "every 3 hours" setting to something they prefer
Read your license agreement
Read your documentation, including how to get support
Etc.

Android: intent started, but which parameters to pass?

I want to add support for several navigation applications in my app. I know how to start another activity as intent and pass parameters - but is there any way to check the naming of the parameters I should pass? For example: Navigon should start with routing calculation and instructions immediately after starting from within my application. So far, I'm not even sure Navigon supports parameter passing, but I don't even know how to figure that out.
Thanks in advance!
You should check the documentation for each app you're interested in supporting. They should have it laid out somewhere. If they don't, they might not support explicit intent extras.
For example, Navigon has their options laid out here(found by searching "android navigon intent"):
http://www.navigon.com/portal/common/faq/files/online_documents/NAVIGON_Android_public_Intent.pdf

Control an application from another application

I read this question and another question and I understand how to launch an application from another application (Let's call the other application LauncherApplication). However, my goal is not only to launch an application, but to use its functions, so I suppose the LauncherApplication should start an activity using an intent (explicit or implicit).
I should know the data and the actions the installed applications react on and I should add these information to an intent instance before starting it. I wish LauncherApplication allows the user (not the developer) to configure this intent, but how do I know in advance the parameters to put in an intent for the installed applications?
I should implement the "LauncherApplication* in order to allow the user to construct an intent via a graphical interface. Or I could make my application supports the addition of plugins: in this way, I could create a plugin for each installed application, where each plugin could be responsible to manage the configuration of the intent concerning the application associated with it.
UPDATE (added details). In particular, the LauncherApplication should be a service with a speech recognizer enabled, so the user may start an application uttering specific keywords: as well as launch an application, the user should be able to close it and use its functions.
For example, I could have installed an application ((Let's call it LibraryApp) to search for available books in a library; this application could have the following functions:
Search for a book (this function may return if the book is available, it has already been loaned or if it was booked by someone else).
Reserving a book (this function should return the completion of the reservation).
In this way, when I pronounce, for example, the words "start LibraryApp", then the LauncherApplication service should launch the LibraryApp application. Once the application is launched, the service should be able to send commands to it to use one of the available functions (search for a book, reserving a book).
How can I send commands to application that is already active, in order to control it?
how do I know in advance the parameters to put in an intent for the installed applications?
You talk to their developers. There are typically zero "parameters" on an Intent to launch the launcher activity (or activities) of an application, since home screens do not put such "parameters" on the Intent.

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.

Categories

Resources