2

I have used following code for sharing image and text both on twitter wall. Please help me why following code is not working in my application? Launcher activity opens but it display only text and not showing image. And also share text only instead of both image and text.

        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("image/*");
        final PackageManager pm = mainActivity.getPackageManager();
        @SuppressWarnings("rawtypes")
        final List activityList = pm.queryIntentActivities(share, 0);
        int len = activityList.size();
        for (int i = 0; i < len; i++)
        {
            final ResolveInfo app = (ResolveInfo) activityList.get(i);
            Log.print("Packages", app.activityInfo.name);

            if (app.activityInfo.packageName.startsWith("com.twitter.android"))
            {
                Log.print(":::: Twitter Share Name Activity ::: " + (app.activityInfo.name).toString());

                try
                {
                    final ActivityInfo activity = app.activityInfo;
                    final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);                          
                    share.addCategory(Intent.CATEGORY_LAUNCHER);
                    share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                    share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    share.setComponent(name);
                    share.putExtra(Intent.EXTRA_TEXT, Pref.getValue(mainActivity, Labels.TITLE, ""));
                    share.putExtra(Intent.EXTRA_STREAM, new URI(new URL(imgUrl).toString()));
                    startActivity(share);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                    Log.error(":::: Twitter image path Exception::::", e.toString());
                }

                break;
            }
        }
Yasmik
  • 57
  • 2
  • 10

0 Answers0