Android ShareActionProvider with popup menu - undesired duplicate list

孤人 提交于 2019-12-06 03:34:50

Here is the code I eventually went with (I'm not even sure how I figured it out as it was a long time ago), but it might help someone.

The solution was not ideal, it removes the duplicate list, but leaves behind the boring list (without icons), and I kind of wanted the other one. If I recall this method of sharing is outdated and it would be excellent if someone could shed more light on the issue.

private void share(MenuItem item) {
        mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, "Here's a message originally posted by " + mClickedMessage.getFirstName()
                + " " + mClickedMessage.getLastName() + ": " + mClickedMessage.getTheMessage() + "\n\n Sent via Loylap");
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_post_to)));
    }

So I came up with my own solution that basically replaces ShareActionProvider with a new class that gets the same Activites with the same intent filter, called ShareActionAdapter. The relevant snippet is as follows though:

 Intent intent = new Intent(Intent.ACTION_SEND);
 intent.setType("text/plain");
 PackageManager pm = context.getPackageManager();
 m_list = new ArrayList<>(pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER));

The full gist that mimics a the popup experience can be found here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!