Domanda

I have this code which I found on another SO

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

  ContentValues values = new ContentValues();
  values.put(Images.Media.TITLE, "title");
  values.put(Images.Media.MIME_TYPE, "image/jpeg");

  ContentResolver contentResolver = getContentResolver();
  Uri uri = contentResolver.insert(Media.EXTERNAL_CONTENT_URI, values);

  OutputStream outstream = null;
  try {
      outstream = getContentResolver().openOutputStream(uri);
      icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
      outstream.close();
  } catch (Exception e) {
      System.err.println(e.toString());
  }

  share.putExtra(Intent.EXTRA_STREAM, uri);
  startActivity(Intent.createChooser(share, "Share Image"));

However, it creates an exception in the call to insert - maybe because I do not have a SD card in my phone. I can not say for sure since no log seems to be generated. And when I step through code, it seems I am stepping through comments, so it would appear something is wrong in my Eclipse installation. (Normally logs are generated and stepping works fine.)

Ideally, I would like to have code that is not dependent on external storage (I believe Instagram and Google+ image sharing requires this from what I can read), but which would fallback to local app storage if SD card not available. I know that wouldy limit share options, but sthat is till better than nothing.

Later-on, I need to merge this with camera functionality which is why the input currently is myBitmap.

È stato utile?

Soluzione

You need to follow this guide provided by Google. As this feature is included as standard by Android 4.0 it should not be difficult to implement.

http://developer.android.com/training/sharing/shareaction.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top