0

Newbie here. I have an app I'm working on that is all image views and everything is running fine but the problem I have is that I can't seem to open an image in email or attach an email in text msg as they both state, using the share intent method. It will show the text I attach and it sends just fine but with the images I can't open or attach them. I have added the write_external method as well in manifest. Hope someone can help me fix this. Code is below, but the share intent section is a little messy as I have 2 diff codes in there for running share intent with image..both work fine..no errors...but neither open or attach image via text or email.

 package com.app.appname;

 import android.app.ActionBar;
 import android.content.Intent;
 import android.graphics.Typeface;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.v7.app.AppCompatActivity;
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;

 import com.google.android.gms.ads.AdListener;
 import com.google.android.gms.ads.AdRequest;
 import com.google.android.gms.ads.AdRequest.Builder;

 import com.google.android.gms.ads.AdSize;
 import com.google.android.gms.ads.AdView;
 import com.google.android.gms.ads.InterstitialAd;

 import java.io.File;

 import static com.app.appname.R.id.adView;



public class imageView1 extends AppCompatActivity {

private ImageView imgview;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.imageview1);

    SpannableString s = new SpannableString("Action Bar Title");
    s.setSpan(new TypefaceSpan(this, "Sui.ttf"), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    // Update the action bar title with the TypefaceSpan instance
    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle(s);


    AdView mAdView = (AdView) findViewById(adView);
    AdRequest adRequest = new AdRequest.Builder()
            .build();
    mAdView.loadAd(adRequest);   }


public void shareText(View view) {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.setType("image/jpeg");
    String shareBodyText = "Sharing message goes here";
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject/Title");
    intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
    startActivity(Intent.createChooser(intent, "Choose sharing method"));
 }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.action_menu, menu);
    return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.share:

            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");

            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("image/jpeg");


            Uri imageUri = Uri.parse("android.resource://com.app.appname/pic1.jpg");
            Log.i("imageUri",""+imageUri);
            share.putExtra(Intent.EXTRA_STREAM,imageUri);
            startActivity(Intent.createChooser(share, "Share Image"));


            Uri u = Uri.parse("android.resource://com.app.appname/pic1.jpg");
            File f = new File("" + u);
            f.getName();


            sharingIntent.setType("image/jpeg");
            Uri uri = Uri.parse("android.resource://com.app.appname/"+R.drawable.pic1);
            sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);



            String shareBodyText = "Download app from ";
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "App Name");
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
            startActivity(Intent.createChooser(sharingIntent, "Share via"));
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }


    }

}
Essentialz
  • 45
  • 3
  • 13
  • Not every app is going to know how to use the `android.resource` scheme. – CommonsWare Jun 14 '17 at 19:05
  • hey thanks for the reply but i am not sure what you mean by that. using the code above, it sends the image which i can see as an attachment but i cant open it and it won't attach to a text msg. what would you suggest to fix this? – Essentialz Jun 14 '17 at 23:12
  • "i am not sure what you mean by that" -- the `Uri` that you are sharing is from `Uri.parse("android.resource://com.app.appname/"+R.drawable.pic1);`. Few apps that support `ACTION_SEND` will know what to do with a `Uri` with the `android.resource` scheme. "what would you suggest to fix this?" -- stop using the `android.resource` scheme. Use a `FileProvider` and share a file, not a resource. – CommonsWare Jun 14 '17 at 23:20
  • i don't know where to really start with that as Im a newbie with java but I will take a look around for some examples. im still lost on the few app that support uri.parse part though because if my app didn't support it, it shouldn't send anything? or is that just for the file name extension part? either way ill dig around. thanks for the suggestion. – Essentialz Jun 15 '17 at 14:09

0 Answers0