Balkyto
Balkyto

Reputation: 1510

Android share intent on specific application and from Bitmap resource

I'm trying to share from my app to Hyves using share intent. If I have hyves app installed and share from gallery it switch to hyves app, and upload image correctly to hyves, so it should work.

Problem is, I can't find it documented how should proper intent for hyves work, but I assume that gallery uploads images only, so I have this:

Bitmap image = BitmapFactory.decodeFile(MyGlobals.INSTANCE.activeSetting.f_image_path);

It's line of code where I pull my "active" or "selected" image within my app. At this point image is saved to SD Card, so I might read uri instead of decoding file, but I want it this way to have same approach for both hyves and facebook.

Then I call:

Intent hyvesIntent = new Intent(Intent.ACTION_SEND);
 hyvesIntent.setPackage("com.hyves.android.application");
 hyvesIntent.setType("image/jpeg");
 hyvesIntent.putExtra("image", image);
 startActivityForResult(hyvesIntent, 666);

First of all, I'm not sure if setPackage is OK to be used here, but I'm checking if this package exist to enable / disable share, and this is package name that is visible.

I need Activity result to then notify that Image is shared or not.

What happens here it starts the Hyves app, but I get full white screen, and then the Hyves app times out.

So, Can I use Bitmap in intent, and is it OK to setPackage or should I setClass?

Tnx

Upvotes: 0

Views: 1809

Answers (1)

urveshpatel50
urveshpatel50

Reputation: 1685

Maybe you can not put the bitmap directly in the intent. First convert the bitmap into a byte array than send another side and convert into bitmap

    //convert bitmap to bytearray
    public static byte[] getBitmapAsByteArray(Bitmap bitmap, boolean type) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    if (type) {
        bitmap.compress(CompressFormat.PNG, 0, outputStream);
    } else {
        bitmap.compress(CompressFormat.JPEG, 0, outputStream);
    }
    return outputStream.toByteArray();
 }
     //convert bitmap to bytearray
    public static Bitmap getBitmap(byte[] imgByte){
      Bitmap bm = BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length);
       return bm;
    }
   //than intent

          Intent hyvesIntent = new Intent(Intent.ACTION_SEND);
          hyvesIntent.setPackage("com.hyves.android.application");
           hyvesIntent.setType("image/jpeg");
           hyvesIntent.putExtra("image", getBitmapAsByteArray(image,true));
           startActivityForResult(hyvesIntent, 666);

I hope that is right way to put image

Upvotes: 1

Related Questions