I don't want to use action bar in my application. I have custom share icon in my activity. Now on click of that icon i should open a list of applications, same as we get in ShareActionProvider.
If i use:-
context.startActivity(Intent.createChooser(myIntent, "Share Image!"));
It opens default chooser activity pausing my activity and chooser activity comes at top.
If i use ShareActionProvider
, it works fine but this is only for ActionBars.
How can i have same functionality as ShareActionProvider
, but not in Action Bar.
If you are looking for the code to share an image to all available share applications on the device it would be something like this:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri phototUri = Uri.parse(localAbsoluteFilePath);
File file = new File(phototUri.getPath());
Log.d(TAG, "file path: " +file.getPath());
if(file.exists()) {
// file create success
} else {
// file create fail
}
shareIntent.setData(phototUri);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
activity.startActivityForResult(Intent.createChooser(shareIntent, "Share Image!"), Navigator.REQUEST_SHARE_ACTION);
Finally i got the solution for this.
ListView lv;
Intent share = new Intent(Intent.ACTION_SEND);
lv=(ListView)findViewById(R.id.listView1);
PackageManager pm=getPackageManager();
share.setType("image/png");
List<ResolveInfo> launchables=pm.queryIntentActivities(share, 0);
Collections.sort(launchables, new ResolveInfo.DisplayNameComparator(pm));
adapter=new AppAdapter(pm, launchables);
lv.setAdapter(adapter);
Here, launchables list will contain all the available share applications. This we can populate in our listView using adapters.
Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.