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

时间:2014-08-04 11:47:13

标签: android android-intent

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

如果我使用: -

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

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

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

我如何具有与ShareActionProvider相同的功能,但不能在Action Bar中使用。

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

最后我得到了解决方案。

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中填充。

由于

相关问题