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.