English 中文(简体)
Use Application within Application on Android
原标题:

I m writing a program for the Android Platform and I would like to implement the code of a preexisting application found here .

There is a button in my application menu that says "Show Friends on Map" so I want this program to start from the button press.

For greater detail I will give a small diagram.

User Starts My application > User Presses "Menu" Key > User Presses "Show Friends on Map" > WAMF.apk (the application in the link above) is launched

Is there any way I can do this?

问题回答

If I understand you correctly and all you want to do is launch WAMF, see this blog post.

In it is the following code, which will detect whether the OpenTable (or WAMF, in this question) is installed, and if so invoke it, otherwise take the user to the Android Market to download OpenTable:

public void showReserveButton() {

   // setup the Intent to call OpenTable      
   Uri reserveUri = Uri.parse(String.format( "reserve://opentable.com/%s?refId=5449",
           opentableId));
   Intent opentableIntent = new Intent("com.opentable.action.RESERVE", reserveUri);

   // setup the Intent to deep link into Android Market
   Uri marketUri = Uri.parse("market://search?q=pname:com.opentable");
   Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(marketUri);

   opentableButton.setVisibility(opentableId > 0 ? View.VISIBLE : View.GONE);
   opentableButton.setOnClickListener(new Button.OnClickListener() {
       public void onClick(View v) {
           PackageManager pm = getPackageManager();
           startActivity(pm.queryIntentActivities(opentableIntent, 0).size() == 0  ?
                   opentableIntent : marketIntent);
       }
   });

}

As commonsware says, this is assuming that WAMF is available in the Android market. If not, you re out of luck.

(I m hoping Reto Meier sees your question, as WAMF is his app)

Well, as I see it, you have two main choices.

Option #1 says that WAMF is installed as a separate application. That may be tricky, as it is unclear if this application is available for distribution anywhere (e.g., Android Market). But, assuming it is, and assuming the user has the app installed, when the user invokes your desired menu choice, you need to call startActivity(), using an Intent that will resolve to whatever in WAMF you would like to have displayed. You can also use PackageManager to detect if WAMF is installed (i.e., seeing if there are any activities that would match the Intent you want to use in startActivity()) -- that way, you can disable the menu choice, or have it pop up a dialog telling people to install WAMF, or something.

Option #2 says that, since WAMF is Free Software, you simply integrate the relevant portions of code straight into your app. On the plus side, there s no question whether the code is there. However, should Mr. Meier update the year-old WAMF, you would have to re-integrate his changes. Also, his application is released under GPLv3, which may or may not work with your own app s licensing scheme.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签