1

So i've been stucked for 2 days trying to figure out how to do the sharing function through android app using ShareActionProvider.

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_analyze, menu);
    MenuItem item = menu.findItem(R.id.action_share);
    // Fetch and store ShareActionProvider
    myShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
    // Set share Intent.
    // Note: You can set the share Intent afterwords if you don't want to set it right now.
    myShareActionProvider.setShareIntent(getDefaultShareIntent());
    return true;
}

Let me say I want to share an image with a file format ending with png, as below is the following code I should approach

private Intent getDefaultShareIntent(){
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);

sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
}

where the path in Uri.parse(path) is the image filename.

But then here comes the problem, I have a seperate picture gallery full of pictures, and the folder name is as below

String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/FolderName/" 

Here is where the problem is, I want to let the user pick a single image inside /foldername/ and get the file name out so I am able to parse it inside the Uri.parse(path) for sharing.

Any help will be greatly appreciated, thank you. :)

Cheers.

Newbie
  • 21
  • 1
  • So you need a file picker activity to pick images from your custom location? – Prerak Sola Jun 20 '16 at 08:16
  • Hi @Prerak Sola , I need the user to only enable the file picker activity when it clicks the share action button, not when it is enabled by default if I was to create an activity in onCreateOptionsMenu. – Newbie Jun 20 '16 at 09:40

0 Answers0