title: How to send pdf or image to a specific whatsapp contact?
body: <p>Tried out these following code snippets to send pdf, image and text. When used ACTION_VIEW the particular whatsapp chat is opening, text is getting sent but can't able to send the pdf or image. Please help with appropriate code snippet for the following problem I am facing.</p>
  <p>The methods which I tried are as follows:</p>
  <pre><code>PackageManager pm = bill_layout.this.getPackageManager();
   try {
       Intent waIntent = new Intent(Intent.ACTION_SEND);
       waIntent.setType(&quot;application/pdf&quot;);
       String text = &quot;YOUR TEXT HERE&quot;;
       PackageInfo info = pm.getPackageInfo(&quot;com.whatsapp&quot;, PackageManager.GET_META_DATA);
       waIntent.setPackage(&quot;com.whatsapp&quot;);
       waIntent.putExtra(Intent.EXTRA_TEXT, text);
       startActivity(Intent.createChooser(waIntent, &quot;Share with&quot;));
   } catch (PackageManager.NameNotFoundException e) {
       Toast.makeText(bill_layout.this, &quot;WhatsApp not Installed&quot;, Toast.LENGTH_SHORT)
               .show();
   }
  
  
  try {
     String longUrl=&quot;https://firebasestorage.googleapis.com/v0/b/glossy-radio-280106.appspot.com/o/19c48c9d-3f83-4a8f-a296-fe0ea
       Bitly bitly= Bit.ly(&quot;o_1gduh4caf3&quot;);
       shorturl=bitly.shorten(longUrl);
     String text= &quot;shorturl&quot;;// Replace with your message.
     String toNumber = &quot;91xxxxxxxxxx&quot;; // Replace with mobile phone number without +Sign or leading zeros, but with country code
     //Suppose your country is India and your phone number is “xxxxxxxxxx”, then you need to send “91xxxxxxxxxx”.
     Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setDataAndType(Uri.parse(&quot;http://api.whatsapp.com/send?phone=&quot;+toNumber +&quot;&amp;text=&quot;+ URLEncoder.encode(text, &quot;UTF-8&quot;))
             &quot;text/plain&quot;);
     intent.setAction(Intent.ACTION_SEND);
     intent.putExtra(Intent.EXTRA_TEXT,&quot;okay&quot;);
     intent.setPackage(&quot;com.whatsapp&quot;);
     startActivity(intent); }
  catch (Exception e){
     e.printStackTrace();}
  
  
  PackageManager pm1=getPackageManager();
   try {
       String toNumber = &quot;91xxxxxxxxxx&quot;; // Replace with mobile phone number without +Sign or leading zeros, but with country co
       //Suppose your country is India and your phone number is “xxxxxxxxxx”, then you need to send “91xxxxxxxxxx”.
       Intent sendIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse(&quot;smsto:&quot;+ toNumber));
       sendIntent.setPackage(&quot;com.whatsapp&quot;);
       sendIntent.putExtra(Intent.EXTRA_TEXT,&quot;test1&quot;);
       sendIntent.putExtra(&quot;chat&quot;,true);
       startActivity(sendIntent);}
  
  
  catch (Exception e){
       e.printStackTrace();
       Toast.makeText(bill_layout.this,&quot;it may be you dont have whats app&quot;,Toast.LENGTH_LONG).show();
   }
  
  Intent sendIntent = new Intent(&quot;android.intent.action.SEND&quot;);
   File f=new File(&quot;path to the file&quot;);
   Uri uri = Uri.parse(&quot;gs://glossy-radio-280106.appspot.com/19c48c9d-3f83-4a8f-a296-fe0eaf4488c4.pdf&quot;);
   sendIntent.setComponent(new ComponentName(&quot;com.whatsapp&quot;,&quot;com.whatsapp.ContactPicker&quot;));
   sendIntent.setType(&quot;application/pdf&quot;);
   sendIntent.putExtra(Intent.EXTRA_STREAM,uri);
   sendIntent.putExtra(&quot;jid&quot;,&quot;918824525121&quot;+&quot;@s.whatsapp.net&quot;);
   sendIntent.putExtra(Intent.EXTRA_TEXT,&quot;sample text you want to send along with the image&quot;);
   startActivity(sendIntent);
   PackageManager pm = bill_layout.this.getPackageManager();
       String formattedNumber =&quot;91xxxxxxxxxx&quot;;
       try{
           Intent sendIntent =new Intent(&quot;android.intent.action.MAIN&quot;);
           sendIntent.setComponent(new ComponentName(&quot;com.whatsapp&quot;, &quot;com.whatsapp.Conversation&quot;));
           sendIntent.setAction(Intent.ACTION_SEND);
           sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           PackageInfo info = pm.getPackageInfo(&quot;com.whatsapp&quot;, PackageManager.GET_META_DATA);
           sendIntent.putExtra(Intent.EXTRA_SUBJECT, &quot;Card Set &quot;);
           sendIntent.putExtra(Intent.EXTRA_TEXT,formattedNumber);
           sendIntent.setType(&quot;text/plain&quot;);
           sendIntent.putExtra(&quot;jid&quot;, formattedNumber +&quot;@s.whatsapp.net&quot;);
           sendIntent.setPackage(&quot;com.whatsapp&quot;);
           bill_layout.this.startActivity(sendIntent);
       }
       catch(Exception e)
       {
           Toast.makeText(bill_layout.this,&quot;Error/n&quot;+ e.toString(),Toast.LENGTH_SHORT).show();
  </code></pre>