3

i am getting null pointer in share action provider because it's expecting an image at start of app. i can provide it only later.

Here is my code

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate menu resource file.
    getMenuInflater().inflate(R.menu.menu, menu);

    // Locate MenuItem with ShareActionProvider
    MenuItem item = menu.findItem(R.id.menu_item_share);

    // Fetch and store ShareActionProvider
    mShareActionProvider = (ShareActionProvider) item.getActionProvider();

    return true;
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    Uri uri = Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
            getBitmapName()));
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.mailSubject));
    setShareIntent(shareIntent);

    return true;
}



// Call to update the share intent
private void setShareIntent(Intent shareIntent) {
    if (mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(shareIntent);
    }
}
Michael Alan Huff
  • 3,462
  • 3
  • 28
  • 44
vineet
  • 269
  • 1
  • 4
  • 18

1 Answers1

0

Hey vineet I think you may need to initialize your image in your app before sending it to the share intent. So instead of sending the share intent a URI pull the image from the uri in on create then set it up using bm=BitmapFactory.decodeResource(getResources(),R.drawable.image);.

Not sure if this will work or not but the only reason the sharing intent would be getting a null pointer exception would be from an image that doesn't exist or is not initialized.

Hope this helps

Doug

Doug Ray
  • 165
  • 1
  • 1
  • 12