lundi 25 mai 2015

Custom share dialog,not working for some apps

I have implemented a custom share dialog,in my android app.I am sharing images,interesting enough it does not work for Evernote application.I can share with Evernote by the default way.But it does not work with this code.I have experienced this only for the Evernote application.

This is my code :

public void doShareCustomDialog() {
    Bitmap curBitmap = ((ImagePagerAdapter) viewPager.getAdapter())
            .getCurrentBitmap();
    final Intent imageIntent = new Intent();
    imageIntent.setAction(Intent.ACTION_SEND);
    imageIntent.setType("image/jpeg");
    imageIntent.putExtra(Intent.EXTRA_STREAM,
            getImageUri(getActivity(), curBitmap));

    final Dialog dialog = new Dialog(getActivity());
    dialog.setTitle("Choose application:");
    dialog.getWindow().setBackgroundDrawable(
            new ColorDrawable(R.color.black_overlay));
    dialog.setCanceledOnTouchOutside(true);
    ListView lv = new ListView(getActivity());
    dialog.setContentView(lv);
    dialog.show();

    PackageManager pm = getActivity().getPackageManager();
    List<ResolveInfo> launchables = pm
            .queryIntentActivities(imageIntent, 0);
    Collections
            .sort(launchables, new ResolveInfo.DisplayNameComparator(pm));

    final AppAdapter adapter = new AppAdapter(pm, launchables);
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            ResolveInfo launchable = adapter.getItem(position);
            ActivityInfo activity = launchable.activityInfo;
            ComponentName name = new ComponentName(
                    activity.applicationInfo.packageName, activity.name);
            imageIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            imageIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            imageIntent.setComponent(name);
            startActivity(imageIntent);
        }
    });

}

Aucun commentaire:

Enregistrer un commentaire