facebook - android ACTION_SEND to share with specific application only -
in android application have 4 buttons facebook, viber, telegram , whatsapp , want share different content based on each button.
for example if user clicks on viber button want user action_send share content viber only.
i found this explains how facebook , twitter seems it's calling specific class name of application don't know applications wanna use except facebook.
all android apps have unique id, first have check if these apps installed in user's device , can pass unique id via intent sharing. according below:
unique ids different apps :
viber : com.viber.voip
telegram : org.telegram.messenger
whatsapp : com.whatsapp
check if these apps installed , if installed send messages through intent.
private void sendmessage(context context,string message, string appids) { final boolean isappinstalled =isappavailable(context, appids); if (isappinstalled) { intent myintent = new intent(intent.action_send); myintent.settype("text/plain"); myintent.setpackage(appids); myintent.putextra(intent.extra_text, message); muiactivity.startactivity(intent.createchooser(myintent, "share with")); } else { toast.maketext(context, "app not installed", toast.length_short).show(); } }
indicates whether specified app installed , can used intent. method checks package manager installed packages can respond intent specified app. if no suitable package found, method returns false.
private boolean isappavailable(context context, string appname) { packagemanager pm = context.getpackagemanager(); try { pm.getpackageinfo(appname, packagemanager.get_activities); return true; } catch (namenotfoundexception e) { return false; } }
Comments
Post a Comment