Quantcast
Channel: xda-developers - Android Q&A, Help & Troubleshooting
Viewing all articles
Browse latest Browse all 18891

Building app and need help!

$
0
0
Hello everyone,

I have a android app that is a gallery and when they choose the image you can press menu share and it will go to a text box and some quotes where they can select a quote or write their own text and then pick where they want to share to.

My problem is that when i try to share to Facebook or MMS it only shows the text and says "unable to attach. File not supported". But when i choose to share with gmail it has the text and image and everything is fine.

**OK I did some testing the only apps that I know of that are not working are ---> Facebook ( nothing shows up no wording or picture), Google + (only wording), fancy (nothing shows up) , and stock text app (only the text shows up).... if someone could help me that would be great! Thanks**

I have tried to find the solution but cant find it and im not sure where im going wrong.

I was just wondering if someone has any idea how to fix this, and if so can someone tell me how.


Here is the code snippet of what I have:


Code:

public class TextActivity extends Activity {

        public static final String SELECTED_IMAGE = "selected_image";
       
        private ListView lv;
        private QuotationAdapter qa;
        private EditText et;
        private Button btShare;
        private int selectedImage = -1;
       
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text);
       
            Bundle params = getIntent().getExtras();
            if(params != null) {
                    selectedImage = params.getInt(SELECTED_IMAGE, -1);
            }
       
        lv = (ListView) findViewById(R.id.list);
        qa = new QuotationAdapter(this);
        lv.setAdapter(qa);
        et = (EditText) findViewById(R.id.et);
        btShare = (Button) findViewById(R.id.btn_share);
       
        lv.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
                        et.setText((String) qa.getItem(pos));
                }
                });
        btShare.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                                share(TextActivity.this);
                        }
                });
    }
   
        public void share(Activity context) {
                if (selectedImage > -1) {
                        String message = et.getText().toString();
                       
                        Bitmap resourceImage = BitmapFactory.decodeResource(this.getResources(), selectedImage);
                        File externalStorageFile = new File(Environment.getExternalStorageDirectory(), "image.jpg");
                        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                        resourceImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
                        byte b[] = bytes.toByteArray();
                        try {
                            externalStorageFile.createNewFile();
                            OutputStream filoutputStream = new FileOutputStream(externalStorageFile);
                            filoutputStream.write(b);
                            filoutputStream.flush();
                            filoutputStream.close();
                        } catch (IOException e) {
                                e.printStackTrace();
                        }
                        Intent sendIntent = new Intent(Intent.ACTION_SEND);
                        sendIntent.setType("text/plain");
                        sendIntent.putExtra(Intent.EXTRA_TEXT, message);
                        sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + externalStorageFile.getAbsolutePath()));
                        context.startActivity(Intent.createChooser(sendIntent,
                                        context.getResources().getString(R.string.text_share_title)));
                TextActivity.this.finish();
                }
        }
   
    public class QuotationAdapter extends BaseAdapter {
       
        public QuotationAdapter(Context c) {
            mContext = c;
        }

        public int getCount() {
            return mQuotations.length;
        }

        public Object getItem(int position) {
            return mQuotations[position];
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            TextView i = new TextView(mContext);
            i.setPadding(10, 10, 10, 10);
            i.setText(mQuotations[position]);
            i.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.FILL_PARENT,
                            ListView.LayoutParams.WRAP_CONTENT));
            return i;
        }

        private Context mContext;



Thanks for look i hope someone knows what im doing wrong :laugh:.

-LivLogik

Viewing all articles
Browse latest Browse all 18891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>