Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...