繁体   English   中英

没有操作栏的自定义共享图标

[英]Custom share icon without Action bar

我不想在应用程序中使用操作栏。 我的活动中有自定义共享图标。 现在单击该图标,我应该打开一个应用程序列表,与我们在ShareActionProvider中获得的一样。

如果我使用:-

context.startActivity(Intent.createChooser(myIntent, "Share Image!"));

它将打开默认选择器活动,暂停我的活动,而选择器活动排在最前面。

如果我使用ShareActionProvider ,它可以正常工作,但这仅适用于ActionBar。

我如何具有与ShareActionProvider相同的功能,但在Action Bar中却没有。

如果您正在寻找将图像共享到设备上所有可用共享应用程序的代码,则可能是这样的:

    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);

终于我得到了解决方案。

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); 

在这里,启动项列表将包含所有可用的共享应用程序。 我们可以使用适配器将其填充到listView中。

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM