FileDocCategorySizeDatePackage
UninstallerActivity.javaAPI DocAndroid 1.5 API7330Wed May 06 22:42:46 BST 2009com.android.packageinstaller

UninstallerActivity

public class UninstallerActivity extends android.app.Activity implements android.view.View.OnClickListener

Fields Summary
private static final String
TAG
private boolean
localLOGV
private static final int
UNINSTALL_CONFIRM
private static final int
UNINSTALL_PROGRESS
private static final int
UNINSTALL_DONE
private int
mCurrentState
android.content.pm.PackageManager
mPm
private android.content.pm.ApplicationInfo
mAppInfo
private android.widget.Button
mOk
private android.widget.Button
mCancel
private static final int
DLG_BASE
private static final int
DLG_APP_NOT_FOUND
private static final int
DLG_UNINSTALL_FAILED
Constructors Summary
Methods Summary
private voidfinishAndReturn()

        finish();
    
protected voidonActivityResult(int requestCode, int resultCode, android.content.Intent data)

        boolean finish = true;
        switch(requestCode) {
        case UNINSTALL_PROGRESS:
            finish = false;
            mCurrentState = UNINSTALL_DONE;
            //start the next screen to show final status of installation
            if (resultCode==UninstallAppProgress.SUCCEEDED) {
                startUninstallDone();
            } else {
                showDialogInner(DLG_UNINSTALL_FAILED);
            }
            break;
        case UNINSTALL_DONE:
            //neednt check for result code here
            break;
        default:
            break;
        }
        if(finish) {
            //finish off this activity to return to the previous activity that launched it
            Log.i(TAG, "Finishing off activity");
            finish();
        }
    
public voidonClick(android.view.View v)

        if(v == mOk) {
            //initiate next screen
            startUninstallProgress();
        } else if(v == mCancel) {
            finishAndReturn();
        }
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        //get intent information
        final Intent intent = getIntent();
        Uri packageURI = intent.getData();
        String packageName = packageURI.getEncodedSchemeSpecificPart();
        if(packageName == null) {
            Log.e(TAG, "Invalid package name:"+packageName);
            showDialog(DLG_APP_NOT_FOUND);
            return;
        }
        //initialize package manager
        mPm = getPackageManager();
        boolean errFlag = false;
        try {
            mAppInfo = mPm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (NameNotFoundException e) {
            errFlag = true;
        }
        if(mAppInfo == null || errFlag) {
            Log.e(TAG, "Invalid application:"+packageName);
            showDialog(DLG_APP_NOT_FOUND);
        } else {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            //set view
            setContentView(R.layout.uninstall_confirm);
            PackageUtil.initAppSnippet(this, mAppInfo, R.id.app_snippet);
            //initialize ui elements
            mOk = (Button)findViewById(R.id.ok_button);
            mCancel = (Button)findViewById(R.id.cancel_button);
            mOk.setOnClickListener(this);
            mCancel.setOnClickListener(this);
        }
    
public android.app.DialogonCreateDialog(int id)

        switch (id) {
        case DLG_APP_NOT_FOUND :
            return new AlertDialog.Builder(this)
                    .setTitle(R.string.app_not_found_dlg_title)
                    .setIcon(com.android.internal.R.drawable.ic_dialog_alert)
                    .setMessage(R.string.app_not_found_dlg_text)
                    .setNeutralButton(getString(R.string.dlg_ok), 
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    finish();
                                }})
                    .create();
        case DLG_UNINSTALL_FAILED :
            // Guaranteed not to be null. will default to package name if not set by app
           CharSequence appTitle = mPm.getApplicationLabel(mAppInfo);
           String dlgText = getString(R.string.uninstall_failed_msg,
                    appTitle.toString());
            // Display uninstall failed dialog
            return new AlertDialog.Builder(this)
                    .setTitle(R.string.uninstall_failed)
                    .setIcon(com.android.internal.R.drawable.ic_dialog_alert)
                    .setMessage(dlgText)
                    .setNeutralButton(getString(R.string.dlg_ok), 
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    finish();
                                }})
                    .create();
        }
        return null;
    
private voidshowDialogInner(int id)

    
        
            showDialog(id);
    
private voidstartUninstallDone()

        Intent newIntent = new Intent(Intent.ACTION_VIEW);
        newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO, 
                                                  mAppInfo);
        newIntent.putExtra(PackageUtil.INTENT_ATTR_INSTALL_STATUS, true);
        newIntent.setClass(this, UninstallAppDone.class);
        startActivityForResult(newIntent, UNINSTALL_DONE);
    
private voidstartUninstallProgress()

        Intent newIntent = new Intent(Intent.ACTION_VIEW);
        newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO, 
                                                  mAppInfo);
        newIntent.setClass(this, UninstallAppProgress.class);
        startActivityForResult(newIntent, UNINSTALL_PROGRESS);