This sample code to share String to facebook,zalo, twiter. you can custom as desired
public void share(String message) {
try {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
List<ResolveInfo> resInfo = 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 (info.activityInfo.packageName.toLowerCase().contains(
"facebook") || info.activityInfo.name.toLowerCase().contains(
"facebook") || info.activityInfo.packageName.toLowerCase().contains(
"zalo") || info.activityInfo.name.toLowerCase().contains(
"zalo") || info.activityInfo.packageName.toLowerCase().contains(
"twitter") || info.activityInfo.name.toLowerCase().contains(
"twitter")) {
targetedShare.putExtra(Intent.EXTRA_SUBJECT,
getString(R.string.app_name));
targetedShare.putExtra(Intent.EXTRA_TEXT, message);
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(
targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
} catch (Exception e) {
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…