views:

271

answers:

3

I'm writing a program for the Android Platform and I would like to implement the code of a preexisting application found here (http://blogoscoped.com/archive/2008-12-15-n14.html) 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?

A: 

(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.

CommonsWare
+1  A: 

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.

Mike
A: 

Thanks guy's you two are awesome!

Pitney