![](/img/trans.png)
[英]How can I send message to specific contact through WhatsApp from my android app?
[英]How can I send audio files from my app to Whatsapp?
我正在開發一個應用程序,您可以從中將音頻發送到 whatsapp。 但是,我使用的代碼不起作用。
//This code returns an error and asks to try again to send the audio file
String sharePath = Environment.getExternalStorageDirectory().getPath()
+ "android.resource://"
+ wspActivity.this.getPackageName() + "/raw/" + "increible";
Uri uri = Uri.parse(sharePath);
Intent share = new Intent(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Sound File"));
//This code indicates that the file is of an incompatible type.
final Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/mp3");
final String path = copyFiletoExternalStorage(R.raw.increible, "increible.mp3");
final Uri soundUri = Uri.parse(path);
share.putExtra(Intent.EXTRA_STREAM, soundUri);
startActivity(Intent.createChooser(share, "Compartiendo..."));
If anyone has any idea why this behaviour, I would appreciate it if you could share it :)
我需要改進其中一些代碼,以便能夠通過 whatsapp 從我的應用程序發送音頻文件
https://faq.whatsapp.com/511210730860677/?cms_platform=android
Android 意圖系統 與 Android 上的大多數社交應用程序一樣,WhatsApp 聽取意圖以共享媒體和文本。 例如,只需創建一個共享文本的意圖,系統選擇器就會顯示 WhatsApp: Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "這是我要發送的文本。"); sendIntent.setType("文本/純文本"); 啟動活動(發送意圖); 但是,如果您更喜歡直接分享到 WhatsApp 並繞過系統選擇器,您可以通過在您的意圖中使用 setPackage 來實現:sendIntent.setPackage("com.whatsapp"); 這將在您調用 startActivity(sendIntent) 之前簡單地設置; 同樣,您可以使用 Android 的意圖系統通過 WhatsApp 發送媒體,如果您只想發送到 WhatsApp,則再次使用 setPackage 將 package 限制為 WhatsApp。 查看此開發者頁面以獲取更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.