1

I am using a solution from https://stackoverflow.com/a/2459624/563306

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);
sendBroadcast(intent);

I also tried from https://stackoverflow.com/a/11010565/563306

 //Convert to byte array
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

Intent in1 = new Intent(this, Activity2.class);
in1.putExtra("image",byteArray);
sendBroadcast(in1);

My receiver doesn't receive the broadcast when I put in extra using any of the above method and no log statements. But I receive if I pass simple string extra instead of bitmap or byte array.

Community
  • 1
  • 1
dcanh121
  • 4,665
  • 11
  • 37
  • 84
  • 2
    Check LogCat for messages. It may be that the bitmap is too big, as there is a 1MB "binder transaction" limit. – CommonsWare Apr 25 '14 at 22:03
  • Surprisingly, I don't see any logs related to this. – dcanh121 Apr 25 '14 at 22:07
  • Even at warning level? IIRC, this will not result in an error message, but a warning. Beyond that, how big is the resulting `byte[]`? – CommonsWare Apr 25 '14 at 22:09
  • I see "!!! FAILED BINDER TRANSACTION !!!" when I put the bitmap itself. but no warning/error/verbose logs if I add byteArray – dcanh121 Apr 25 '14 at 22:10
  • 1
    Are you sure that `Activity2` is a `BroadcastReceiver`? That's a strange name for a `BroadcastReceiver`, as is `NewActivity`. – CommonsWare Apr 25 '14 at 22:11
  • Yes it is. I mentioned the source of the sample code. – dcanh121 Apr 25 '14 at 22:15
  • Neither of the linked-to answers show that the `Intent` is being used for `sendBroadcast()`, or that `Activity2` or `NewActivity` are `BroadcastReceivers`. You might wish to edit the question to show your own code. – CommonsWare Apr 25 '14 at 22:18

3 Answers3

2

There is a change since Android 3.1 to prevent malware.

This solved my problem, https://stackoverflow.com/a/9784004/563306

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent. FLAG_INCLUDE_STOPPED_PACKAGES);
Community
  • 1
  • 1
dcanh121
  • 4,665
  • 11
  • 37
  • 84
0

If you use startActivity() instead of BroadcastReceivers and then simply receive the intent in the second activity then I believe it will work.

As stated here, you really shouldn't be using BroadcastReceivers to work with bitmaps. Im not sure if this will work, but try using the second method you mentioned and doing Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); outside of onReceive().

Community
  • 1
  • 1
user3261344
  • 105
  • 1
  • 8
0

The following example method demonstrates how to invoke the system's media scanner to add your photo to the Media Provider's database, making it available in the Android Gallery application and to other apps.

Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        File f = new File(mCurrentPhotoPath);
        Uri contentUri = Uri.fromFile(f);
        mediaScanIntent.setData(contentUri);
        this.sendBroadcast(mediaScanIntent);

Try This !! May be It Will Solve Your Problem......
Where mCurrentPhotoPath is the Path Of Your ImageFile.