image - Sending message to whatsapp from Android app -


how can send image directly whatsapp android app? tried using

bitmap b = bitmapfactory.decoderesource(getresources(), r.drawable.ic_launcher);  uri imageuri = getimageuri(getapplicationcontext(), b);                  intent sendintent = new intent();                  sendintent.setaction(intent.action_send);                  sendintent.setpackage("com.whatsapp");                  sendintent.putextra(intent.extra_text, "this text send.");                  sendintent.putextra(intent.extra_stream, imageuri);                    sendintent.settype("image/*");                  startactivity(sendintent);

the above code opens send window of whatsapp. there other way image directly sent without opening whats app window?

android intent system

like social apps on android, whatsapp listens intents share media , text. create intent share text, example, , whatsapp displayed system picker:

intent sendintent = new intent(); sendintent.setaction(intent.action_send); sendintent.putextra(intent.extra_text, "this text send."); sendintent.settype("text/plain"); startactivity(sendintent); 

however, if prefer share directly whatsapp , bypass system picker, can using setpackage in intent:

sendintent.setpackage("com.whatsapp"); set right before call startactivity(sendintent); 

similarly can use android's intent system send media through whatsapp, once again, using setpackage restrict package whatsapp if want send whatsapp. check developer page more information.

custom url scheme

whatsapp provides custom url scheme interact whatsapp:

if have website , want open whatsapp chat pre-filled message, can use our custom url scheme so. opening whatsapp://send?text= followed text send, open whatsapp, allow user choose contact, , pre-fill input field specified text.

here example of how write on website:

<a href="whatsapp://send?text=hello%20world!">hello, world!</a> 

// not original text: can call endpoint through java code too

found in: https://www.whatsapp.com/faq/es/android/28000012


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -