Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an Android app that depends on another app?

Tags:

If I create an app that depends on another app or apps (eg: the Facebook and Twitter apps), yet they are not installed, is there a method of checking for those dependencies and installing them at the same time as my own app?

like image 684
Ande Turner Avatar asked Oct 11 '11 10:10

Ande Turner


People also ask

Can an Android app launch another app?

In android, we can lunch other applications using packing name. This example demonstrate about How to Launch an application from another application on Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

Can one app interact with another app?

At the simplest level, there are two different ways for apps to interact on Android: via intents, passing data from one application to another; and through services, where one application provides functionality for others to use.


2 Answers

I did this in my application which requires the zxing scanner app to be installed. You will want this inside your onclick or ontouch:

try{     Intent intent = new Intent("com.google.zxing.client.android.SCAN");     intent.setPackage("com.google.zxing.client.android");     startActivityForResult(intent, 0); } catch (Exception e) {     createAlert("Barcode Scanner not installed!", "This application uses " +     "the open source barcode scanner by ZXing Team, you need to install " +     "this before you can use this software!", true); } 

which calls

public void createAlert(String title, String message, Boolean button) {     // http://androidideasblog.blogspot.com/2010/02/how-to-add-messagebox-in-android.html     AlertDialog alertDialog;     alertDialog = new AlertDialog.Builder(this).create();     alertDialog.setTitle(title);     alertDialog.setMessage(message);     if ((button == true)) {         alertDialog.setButton("Download Now",         new DialogInterface.OnClickListener() {             public void onClick(DialogInterface arg0, int arg1) {                 Intent browserIntent = new Intent(                     Intent.ACTION_VIEW,                     Uri.parse("market://search?q=pname:com.google.zxing.client.android"));                 startActivity(browserIntent);             }         });     }     alertDialog.show(); } 

Then after sorting out all that code out I realise you asked for it to be installed at the same time as your app. Not sure if i should post this code, but it may be helpful

like image 116
TerryProbert Avatar answered Nov 03 '22 00:11

TerryProbert


Short answer: No, you cannot automatically install other applications as dependencies.

Longer answer:

Android Market does not let you declare other applications to install as a dependency. As a system, Market appears to be designed for single application installs -- not Linux distro style mega dependency graphs.

At runtime, you can test for installed apps and punt your user over to the Market if so. See the techniques suggested by @QuickNick (testing if an app is installed) and @TerryProbert (punting to market) if that's what you want.

Your best bet is probably to design your app to gracefully degrade if dependencies are not available, and suggest (or insist) that they head over to market to install them.

like image 44
mik3y Avatar answered Nov 03 '22 00:11

mik3y