FileDocCategorySizeDatePackage
ResolverActivity.javaAPI DocAndroid 1.5 API15157Wed May 06 22:41:56 BST 2009com.android.internal.app

ResolverActivity

public class ResolverActivity extends AlertActivity implements CheckBox.OnCheckedChangeListener, DialogInterface.OnClickListener
This activity is displayed when the system attempts to start an Intent for which there is more than one matching activity, allowing the user to decide which to go to. It is not normally used directly by application developers.

Fields Summary
private ResolveListAdapter
mAdapter
private android.widget.CheckBox
mAlwaysCheck
private android.widget.TextView
mClearDefaultHint
private android.content.pm.PackageManager
mPm
Constructors Summary
Methods Summary
public voidonCheckedChanged(android.widget.CompoundButton buttonView, boolean isChecked)

        if (mClearDefaultHint == null) return;

        if(isChecked) {
            mClearDefaultHint.setVisibility(View.VISIBLE);
        } else {
            mClearDefaultHint.setVisibility(View.GONE);
        }
    
public voidonClick(android.content.DialogInterface dialog, int which)

        ResolveInfo ri = mAdapter.resolveInfoForPosition(which);
        Intent intent = mAdapter.intentForPosition(which);

        if ((mAlwaysCheck != null) && mAlwaysCheck.isChecked()) {
            // Build a reasonable intent filter, based on what matched.
            IntentFilter filter = new IntentFilter();

            if (intent.getAction() != null) {
                filter.addAction(intent.getAction());
            }
            Set<String> categories = intent.getCategories();
            if (categories != null) {
                for (String cat : categories) {
                    filter.addCategory(cat);
                }
            }
            filter.addCategory(Intent.CATEGORY_DEFAULT);

            int cat = ri.match&IntentFilter.MATCH_CATEGORY_MASK;
            Uri data = intent.getData();
            if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
                String mimeType = intent.resolveType(this);
                if (mimeType != null) {
                    try {
                        filter.addDataType(mimeType);
                    } catch (IntentFilter.MalformedMimeTypeException e) {
                        Log.w("ResolverActivity", e);
                        filter = null;
                    }
                }
            } else if (data != null && data.getScheme() != null) {
                filter.addDataScheme(data.getScheme());

                // Look through the resolved filter to determine which part
                // of it matched the original Intent.
                Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator();
                if (aIt != null) {
                    while (aIt.hasNext()) {
                        IntentFilter.AuthorityEntry a = aIt.next();
                        if (a.match(data) >= 0) {
                            int port = a.getPort();
                            filter.addDataAuthority(a.getHost(),
                                    port >= 0 ? Integer.toString(port) : null);
                            break;
                        }
                    }
                }
                Iterator<PatternMatcher> pIt = ri.filter.pathsIterator();
                if (pIt != null) {
                    String path = data.getPath();
                    while (path != null && pIt.hasNext()) {
                        PatternMatcher p = pIt.next();
                        if (p.match(path)) {
                            filter.addDataPath(p.getPath(), p.getType());
                            break;
                        }
                    }
                }
            }

            if (filter != null) {
                final int N = mAdapter.mList.size();
                ComponentName[] set = new ComponentName[N];
                int bestMatch = 0;
                for (int i=0; i<N; i++) {
                    ResolveInfo r = mAdapter.mList.get(i).ri;
                    set[i] = new ComponentName(r.activityInfo.packageName,
                            r.activityInfo.name);
                    if (r.match > bestMatch) bestMatch = r.match;
                }
                getPackageManager().addPreferredActivity(filter, bestMatch, set,
                        intent.getComponent());
            }
        }

        if (intent != null) {
            startActivity(intent);
        }
        finish();
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        onCreate(savedInstanceState, new Intent(getIntent()),
                getResources().getText(com.android.internal.R.string.whichApplication),
                true);
    
protected voidonCreate(android.os.Bundle savedInstanceState, android.content.Intent intent, java.lang.CharSequence title, boolean alwaysUseOption)

        super.onCreate(savedInstanceState);
        mPm = getPackageManager();
        intent.setComponent(null);

        AlertController.AlertParams ap = mAlertParams;

        ap.mTitle = title;
        ap.mOnClickListener = this;

        if (alwaysUseOption) {
            LayoutInflater inflater = (LayoutInflater) getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
            ap.mView = inflater.inflate(R.layout.always_use_checkbox, null);
            mAlwaysCheck = (CheckBox)ap.mView.findViewById(com.android.internal.R.id.alwaysUse);
            mAlwaysCheck.setText(R.string.alwaysUse);
            mAlwaysCheck.setOnCheckedChangeListener(this);
            mClearDefaultHint = (TextView)ap.mView.findViewById(
                                                        com.android.internal.R.id.clearDefaultHint);
            mClearDefaultHint.setVisibility(View.GONE);
        }
        mAdapter = new ResolveListAdapter(this, intent);
        if (mAdapter.getCount() > 1) {
            ap.mAdapter = mAdapter;
        } else if (mAdapter.getCount() == 1) {
            startActivity(mAdapter.intentForPosition(0));
            finish();
            return;
        } else {
            ap.mMessage = getResources().getText(com.android.internal.R.string.noApplications);
        }

        setupAlert();