En el post anterior pudimos compartir en redes sociales, en esta ocación vamos a compartir en redes especificas, como "sólo en facebook" o "sólo por correo", para esto creamos en nuestro Activity el siguiente método:
void shareSpecificSocialNetwork(String nameApp, String title,
String extraTitle, String filename) {
try {
List targetedShareIntents = new ArrayList();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
List resInfo = getPackageManager()
.queryIntentActivities(share, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
Intent targetedShare = new Intent(
android.content.Intent.ACTION_SEND);
targetedShare.setType("image/jpeg");
if (info.activityInfo.packageName.toLowerCase().contains(
nameApp)
|| info.activityInfo.name.toLowerCase().contains(
nameApp)) {
targetedShare.putExtra(Intent.EXTRA_SUBJECT,
"Sample Photo");
targetedShare.putExtra(Intent.EXTRA_TEXT, extraTitle);
targetedShare.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(new File(filename)));
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(
targetedShareIntents.remove(0), title);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[] {}));
startActivity(chooserIntent);
}
} catch (Exception e) {
Log.v("PensandoEnBinario", e.getMessage());
}
}
Igual que el anterior blog deberíamos crear un botón que ejecute el evento de compartir en facebook:
Button btnFacebook = (Button) dialog
.findViewById(R.id.dialogButtonFacebook);
btnFacebook.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
shareSpecificSocialNetwork("facebook","PensandoEnBinario",
"Powered by PensandoEnBinario",inputFilename);
}
});
Listo podemos probar con: facebook, twitter, mail, instagram, etc.
void shareSpecificSocialNetwork(String nameApp, String title,
String extraTitle, String filename) {
try {
List
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
List
.queryIntentActivities(share, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
Intent targetedShare = new Intent(
android.content.Intent.ACTION_SEND);
targetedShare.setType("image/jpeg");
if (info.activityInfo.packageName.toLowerCase().contains(
nameApp)
|| info.activityInfo.name.toLowerCase().contains(
nameApp)) {
targetedShare.putExtra(Intent.EXTRA_SUBJECT,
"Sample Photo");
targetedShare.putExtra(Intent.EXTRA_TEXT, extraTitle);
targetedShare.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(new File(filename)));
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(
targetedShareIntents.remove(0), title);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[] {}));
startActivity(chooserIntent);
}
} catch (Exception e) {
Log.v("PensandoEnBinario", e.getMessage());
}
}
Igual que el anterior blog deberíamos crear un botón que ejecute el evento de compartir en facebook:
Button btnFacebook = (Button) dialog
.findViewById(R.id.dialogButtonFacebook);
btnFacebook.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
shareSpecificSocialNetwork("facebook","PensandoEnBinario",
"Powered by PensandoEnBinario",inputFilename);
}
});
Listo podemos probar con: facebook, twitter, mail, instagram, etc.
No hay comentarios:
Publicar un comentario