Code example for Intent

Methods: setClassNametoUri

0
            appListView.setAdapter(appAdapter);
            appListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override 
                public boolean onChildClick(ExpandableListView parent, View v,
                        int groupPosition, int childPosition, long id) {
                    Intent shortIntent = new Intent(Intent.ACTION_MAIN);
                    String pkgName = ((GroupInfo)parent.getExpandableListAdapter().getGroup(groupPosition))
                            .info.packageName;
                    String actName = ((GroupInfo)parent.getExpandableListAdapter().getGroup(groupPosition))
                            .info.activities[childPosition].name;
                    shortIntent.setClassName(pkgName, actName);
                    completeSetCustomApp(shortIntent);
                    mAlertDialog.dismiss();
                    return true; 
                } 
            }); 
            Builder builder = new Builder(mParent);
            builder.setView(appListView);
            mAlertDialog = builder.create();
            mAlertDialog.setTitle(mParent.getString(R.string.select_custom_activity_title));
            mAlertDialog.show();
            mAlertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override 
                public void onCancel(DialogInterface dialog) {
                    mListener.shortcutPicked(null, null, false);
                } 
            }); 
        } else { 
            startFragmentOrActivity(intent, requestCodeShortcut);
        } 
    } 
 
    public class AppExpandableAdapter extends BaseExpandableListAdapter {
 
        ArrayList<GroupInfo> allList = new ArrayList<GroupInfo>();
        final int groupPadding;
 
        public class LabelCompare implements Comparator<GroupInfo>{
            @Override 
            public int compare(GroupInfo item1, GroupInfo item2) {
                String rank1 = item1.label.toLowerCase();
                String rank2 = item2.label.toLowerCase();
                int result = rank1.compareTo(rank2);
                if(result == 0) {
                    return 0; 
                } else if(result < 0) {
                    return -1; 
                } else { 
                    return +1; 
                } 
            } 
        } 
 
        class GroupInfo { 
            String label;
            PackageInfo info;
            GroupInfo (String l, PackageInfo p) {
                label = l;
                info = p;
            } 
        } 
 
        public AppExpandableAdapter(List<PackageInfo> pInfos, Context context) {
            for (PackageInfo i : pInfos) {
                allList.add(new GroupInfo(i.applicationInfo.loadLabel(mPackageManager).toString(), i));
            } 
            Collections.sort(allList, new LabelCompare());
            groupPadding = context.getResources().getDimensionPixelSize(R.dimen.shortcut_picker_left_padding);
        } 
 
        public String getChild(int groupPosition, int childPosition) {
            return allList.get(groupPosition).info.activities[childPosition].name;
        } 
 
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        } 
 
        public int getChildrenCount(int groupPosition) {
            if (allList.get(groupPosition).info.activities != null) {
                return allList.get(groupPosition).info.activities.length;
            } else { 
                return 0; 
            } 
        } 
 
 
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = View.inflate(mParent, android.R.layout.simple_list_item_1, null);
                convertView.setPadding(groupPadding, 0, 0, 0);
 
            } 
            TextView textView = (TextView)convertView.findViewById(android.R.id.text1);
            textView.setText(getChild(groupPosition, childPosition).replaceFirst(allList.get(groupPosition).info.packageName + ".", ""));
            return convertView;
        } 
 
        public GroupInfo getGroup(int groupPosition) {
            return allList.get(groupPosition);
        } 
 
        public int getGroupCount() { 
            return allList.size();
        } 
 
        public long getGroupId(int groupPosition) {
            return groupPosition;
        } 
 
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
            if (convertView == null) {
                convertView = View.inflate(mParent, android.R.layout.simple_list_item_1, null);
                convertView.setPadding(70, 0, 0, 0);
            } 
            TextView textView = (TextView)convertView.findViewById(android.R.id.text1);
            textView.setText(getGroup(groupPosition).label.toString());
            return convertView;
        } 
 
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true; 
        } 
 
        public boolean hasStableIds() { 
            return true; 
        } 
 
    } 
 
    private void completeSetCustomApp(Intent data) {
        mListener.shortcutPicked(data.toUri(0), getFriendlyActivityName(data, false), true);
    } 
 
    private void completeSetCustomShortcut(Intent data) {
        Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
        /* preserve shortcut name, we want to restore it later */