0

I share a image from social network and catch it with my app (following this link), but it catch a plain text instead of image, i try to parse to uri and url but it didn't work

void handleSendText(Intent intent) {
    String sharedText2 = intent.getStringExtra(Intent.EXTRA_TEXT);
    //Bn1.setText("Descargar Texto plano");
    if (sharedText2 != null) { // check if is null or not
        File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Imgs/");
        if(!folder.exists()){folder.mkdir();}// create folder
        int diagonal = sharedText2.indexOf(":");
        String sharedText = sharedText2.substring(diagonal + 1, sharedText2.length());
        sharedText = sharedText.replace(" ", "");
        if (!sharedText.startsWith("htt")) {// check if it's starts with http or not
            sharedText = "https" + sharedText.substring(0, sharedText.indexOf("?"));
        }
        c = 1;
        Bitmap bitmap = null;
        Uri imageUri = Uri.parse(sharedText); // parse to uri
        Time now = new Time(); // time
        now.setToNow();
        String nombre = "Imagen-" + now.weekDay + "-" + now.month + "-" + now.year + "-" + now.minute + "_" + now.second;// name of the image
        if (imageUri != null) {
            try {
                bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
            } catch (IOException e) {
                e.printStackTrace();
            }
            File file = null;
            file = new File(folder.getAbsoluteFile(), nombre + ".jpg");
            try {
                FileOutputStream out = new FileOutputStream(file);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
                //bitmap.compress(Bitmap.CompressFormat.WEBP, 90, out);
                out.flush();
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            Tv1.setMovementMethod(new ScrollingMovementMethod());
            Tv1.setText("Es una imagen\n" + imageUri + "\n" + file + "\nnombre:\n" + nombre); // show the name of the variables
            if (bitmap == null) {
                Tv1.setText(sharedText2 + "\n\nsharedtext\n" + sharedText);
            } else {
                Tv1.setText("SI quedo\n" + sharedText);
            }
        }
    }
}
Carlos Carrizales
  • 2,340
  • 3
  • 18
  • 24

1 Answers1

1

EXTRA_TEXT is supposed to be plain text. EXTRA_STREAM, on the other hand, is supposed to be a content: Uri (though often you will get a file: Uri instead). Presumably, the information you seek will be in EXTRA_STREAM, not EXTRA_TEXT.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I've changed it to EXTRA_STREAM instead EXTRA_TEXT and it return me null – Carlos Carrizales Mar 09 '16 at 16:21
  • @CarlosCarrizales: Dump the full contents of the `Intent` and see what the other app is doing. – CommonsWare Mar 09 '16 at 19:00
  • @CarlosCarrizales: Sure you can dump the `Intent` contents. It's in your app. It's what you are calling `getStringExtra()` on. – CommonsWare Mar 09 '16 at 21:47
  • yeah, now, i know what i got, but not to deal with it, anyway, I got another way to use the intent, i guess, i'll try to get the id from the "url" given in the intent and got the image from it based on the link's correct pattern. – Carlos Carrizales Mar 10 '16 at 03:52