Reputation: 1597
i want to send photo using intent i have try this code but my problem is if i use this code for sharing than it open all the applciation related to sharing i want to open only FACEBOOK AND TWITTER APP for sharing
Intent sharefacebook = new Intent(Intent.ACTION_SEND);
sharefacebook.setType("image/*");
sharefacebook.putExtra(Intent.EXTRA_TEXT, "From Android");
sharefacebook.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filepath.toString()));
startActivity(Intent.createChooser(sharefacebook, "Sharing"));
it open email,skype,gmail everthing i want to open only facebook and twitter it is possible
Upvotes: 0
Views: 437
Reputation: 7927
You can query the client apps(activities) and start the activity only if it's a fb/twitter client like this:
final PackageManager pm = getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo info : matches){
if (info.activityInfo.name.toLowerCase().contains("facebook") || info.activityInfo.name.toLowerCase().contains("twitter")){
Intent sharefacebook = new Intent(Intent.ACTION_SEND);
sharefacebook.setType("image/*");
sharefacebook.putExtra(Intent.EXTRA_TEXT, "From Android");
sharefacebook.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filepath.toString()));
startActivity(Intent.createChooser(sharefacebook, "Sharing"));
}else{
Toast.makeText(getApplicationContext(), "FB or twitter client not installed", Toast.LENGTH_SHORT).show();
}
}
Upvotes: 1