Tips/Android

ResolverActivity - 여러 개의 Activity가 Intent에 매칭될 때

dextto™ 2013. 2. 24. 10:28

Default로 설정할 때

ResolverActivity.OnClick() {
.....

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());
    }
}

Default 해제 할 때 (Settings>Launch by default>Clear defaults)

InstalledAppDetails.onClick() {
........
    else if(v == mActivitiesButton) {
      mPm.clearPackagePreferredActivities(packageName);
      mActivitiesButton.setEnabled(false);
    }
........
}
반응형