FileDocCategorySizeDatePackage
PackageBrowser.javaAPI DocAndroid 1.5 API6467Wed May 06 22:41:08 BST 2009com.android.development

PackageBrowser

public class PackageBrowser extends android.app.ListActivity

Fields Summary
private PackageListAdapter
mAdapter
private List
mPackageInfoList
private android.os.Handler
mHandler
private static final Comparator
sDisplayNameComparator
Constructors Summary
Methods Summary
private voiddeletePackage()

        final int curSelection = getSelectedItemPosition();
        if (curSelection >= 0) {
            // todo: verification dialog for package deletion
            final PackageInfo packageInfo = mAdapter.itemForPosition(curSelection);
            if (packageInfo != null) {
                getPackageManager().deletePackage(packageInfo.packageName,
                                                  new IPackageDeleteObserver.Stub() {
                    public void packageDeleted(boolean succeeded) throws RemoteException {
                        if (succeeded) {
                            mPackageInfoList.remove(curSelection);
                            mHandler.post(new Runnable() {
                                    public void run() {
                                        mAdapter.notifyDataSetChanged();
                                    }
                                });

                            // todo: verification dialog for data directory
                            final String dataPath = packageInfo.applicationInfo.dataDir;
                            // todo: delete the data directory
                        } else {
                            mHandler.post(new Runnable() {
                                    public void run() {
                                        new AlertDialog.Builder(PackageBrowser.this)
                                            .setTitle("Oops")
                                            .setMessage("Could not delete package." +
                                                "  Maybe it is in /system/app rather than /data/app?")
                                            .show();
                                    }
                                });

                        }
                    }
                },
                                                  0);
            }
        }
    
protected voidonCreate(android.os.Bundle icicle)


    
        
        super.onCreate(icicle);
        setupAdapter();
        mHandler= new Handler();
        registerIntentReceivers();
    
public booleanonCreateOptionsMenu(android.view.Menu menu)

        menu.add(0, 0, 0, "Delete package").setOnMenuItemClickListener(
                new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                deletePackage();
                return true;
            }
        });
        return true;
    
protected voidonListItemClick(android.widget.ListView l, android.view.View v, int position, long id)

        PackageInfo info =
            mAdapter.itemForPosition(position);
        if (info != null) {
            Intent intent = new Intent(
                null, Uri.fromParts("package", info.packageName, null));
            intent.setClass(this, PackageSummary.class);
            startActivity(intent);
        }
    
private voidregisterIntentReceivers()

        IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addDataScheme("package");
        registerReceiver(new ApplicationsIntentReceiver(), filter);
    
private voidsetupAdapter()

        mAdapter = new PackageListAdapter(this);
        setListAdapter(mAdapter);