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

如果我创建的应用程序依赖于另一个应用程序(例如:Facebook和Twitter应用程序),但它们未安装,是否有方法检查这些依赖关系并将它们与我自己的应用程序同时安装?


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


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.


Start from this:

Intent mediaIntent = new Intent("com.example.intent.action.NAME");
// add needed categories
List<ResolveInfo> listResolveInfo = getPackageManager().queryIntentServices(mediaIntent, 0);
if (listResolveInfo.size() != 0) {
  //normal behavior
} else {
  //install what you need
}

I give you example of querying services. If you want to check activities, then you will call queryIntentActivities().

链接地址: http://www.djcxy.com/p/41872.html

上一篇: Android在安装过程中检查依赖应用程序?

下一篇: 如何制作依赖于其他应用的Android应用?