gpt4 book ai didi

Android,如何过滤只有 Facebook 和 Twitter 的社交分享?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:02:48 24 4
gpt4 key购买 nike

在我的项目中,我需要将一些信息分享到 Just Facebook 和 Twitter。当前,当您使用以下代码时,android 会提供您手机中所有社交网络的列表。

public void share(String subject,String text) {
final Intent intent = new Intent(Intent.ACTION_SEND);

intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(intent, "Share with:"));
}

要求仅在此列表中显示 Facebook 和 Twitter。是否可以过滤此列表以获得这两个?

enter image description here

最佳答案

    Button btnshare=(Button)rootView.findViewById(R.id.btnshare);
btnshare.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Share(getShareApplication(),"Hello Text Share");
}
});

private List<String> getShareApplication(){
List<String> mList=new ArrayList<String>();
mList.add("com.facebook.katana");
mList.add("com.twitter.android");
mList.add("com.google.android.gm");
return mList;

}
private void Share(List<String> PackageName,String Text) {
try
{
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
targetedShare.setType("text/plain"); // put here your mime type
if (PackageName.contains(info.activityInfo.packageName.toLowerCase())) {
targetedShare.putExtra(Intent.EXTRA_TEXT,Text);
targetedShare.setPackage(info.activityInfo.packageName.toLowerCase());
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
}
catch(Exception e){
e.printStackTrace();
}
}

关于Android,如何过滤只有 Facebook 和 Twitter 的社交分享?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9527698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com