2015-10-19 50 views
0

我想從我的應用程序啓動whatsapp應用程序,並傳遞一些文本到特定的數字。 WhatsApp App正在啓動,但文本無法通過。文本沒有傳遞到WhatsApp應用程序使用意圖

String smsNumber = "98*******3"; 
Uri uri = Uri.parse("smsto:" + smsNumber); 
Intent i = new Intent(Intent.ACTION_SENDTO, uri); 
i.putExtra(Intent.EXTRA_TEXT, textWithClickableLink); 
i.setPackage("com.whatsapp"); 
mContext.startActivity(i); 

在我的代碼中是否有缺失? 請幫助我。

在此先感謝!

+1

看看http://stackoverflow.com/questions/24774595/android-how-to-send-message-programatically-by-using-whats-app-we-chat – warlock

+0

這裏的信息會幫助你http://stackoverflow.com/questions/19081654/send-text-to-specific-contact-whatsapp – Pavan

+0

我認爲wahtsapp沒有提供直接分享文本的功能 – Pavan

回答

0

試試這個:

Uri uri = Uri.parse("smsto:" + mobileno); 
Intent whatsappIntent = new Intent(Intent.ACTION_SENDTO, uri); 
whatsappIntent.setPackage("com.whatsapp"); 

String str = "https://play.google.com/store/apps/details?id=com.example.activity&hl=en"; 
whatsappIntent.putExtra("sms_body", str); 
     try { 
      activity.startActivity(whatsappIntent); 
      } catch (android.content.ActivityNotFoundException ex) { 
       // Whatsapp have not been installed 
     } 
+0

感謝您的回覆,我試過這個但不工作。它和以前一樣。 –

0

你可以試試這個方法,它應該工作。我已經測試過

private void shareWhatsApp() { 
     Intent shareIntent = new Intent(Intent.ACTION_SEND); 
     shareIntent.putExtra(Intent.EXTRA_TEXT, "text to share"); 
     //if you have any images to share sue this, uri is the uri of image 
     //shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 
     //shareIntent.setType("image/*"); for image sharing 
     shareIntent.setType("text/plain"); 
     shareIntent.setPackage("com.whatsapp"); 
     startActivity(shareIntent); 
    } 

這將啓動WhatsApp應用程序,您必須手動選擇聯繫人併發送。因爲他們不提供任何SDK我們不能自動發送。

0

我試過這段代碼。它使我的應用程序打開我可以發送消息的所有應用程序的列表。現在選擇任何應用程序後,我可以發送我附帶的意圖消息。

Intent intent = new Intent(Intent.ACTION_SEND); 
        intent.setType("text/plain"); 
        intent.putExtra(Intent.EXTRA_SUBJECT, "From Stockal App"); 
        intent.putExtra(Intent.EXTRA_TEXT, text); 
        mContext.startActivity(intent); 

謝謝大家的回覆。

相關問題