如何在Android的Intent帮助下通过Whatsapp从自己的应用程序发送文本消息和图像?
我无法通过whatsapp发送短信和图片。要么,我能够
启动那个特定的联系人聊天帖子而没有任何消息,或者我只能发送消息但不能打开那个特定的联系人聊天帖子。
I am not able to send both text message and image through whatsapp . Either , I am able to start that particular contact chat thread without any message or I am only able to send message but not opening that particular contact chat thread.
我已按照以下链接:
http://www.whatsapp.com / faq / en / android / 28000012
但未获得成功:(
任何人都可以帮我这个。
如何在Android的Intent帮助下通过自己应用程序的whatsapp发送短信和图像?
Can anybody help me with this. How to Send a Text message and Image through whatsapp from Own Application with help of Intent in Android ?
尝试使用以下解决方案,
Try using the following solution,
Intent sendIntent = new Intent("android.intent.action.SEND");
File f=new File("path to the file");
Uri uri = Uri.fromFile(f);
sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.ContactPicker"));
sendIntent.setType("image");
sendIntent.putExtra(Intent.EXTRA_STREAM,uri);
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("919xxxxxxxxx")+"@s.whatsapp.net");
sendIntent.putExtra(Intent.EXTRA_TEXT,"sample text you want to send along with the image");
startActivity(sendIntent);
关于寻找解决方案的过程的额外信息:
在对WhatsApp进行逆向工程后,我遇到了以下Android清单片段,
After reverse engineering WhatsApp, I came across the following snippet of Android manifest,
正常分享意图,使用发送,它不允许您发送给特定联系人并需要联系人选择器。
Normal Share intent, uses "SEND" which does not allow you to send to a specific contact and requires a contact picker.
特定联系人由对话类选取并使用 SEND_TO 操作,但它使用sms正文,无法占用图片和其他附件。
The specific contact is picked up by Conversation class and uses "SEND_TO" action, but it uses sms body and can not take up image and other attachments.
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:name="com.whatsapp.Conversation" android:theme="@style/Theme.App.CondensedActionBar" android:windowSoftInputMode="stateUnchanged">
<intent-filter>
<action android:name="android.intent.action.SENDTO"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
</intent-filter>
</activity>
进一步挖掘,我遇到了这个,
Digging further, I came across this,
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:name="com.whatsapp.ContactPicker" android:theme="@style/Theme.App.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="com.whatsapp"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="audio/*"/>
<data android:mimeType="video/*"/>
<data android:mimeType="image/*"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="text/x-vcard"/>
<data android:mimeType="application/pdf"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
<data android:mimeType="application/msword"/>
<data android:mimeType="application/vnd.ms-excel"/>
<data android:mimeType="application/vnd.ms-powerpoint"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="audio/*"/>
<data android:mimeType="video/*"/>
<data android:mimeType="image/*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="send" android:scheme="whatsapp"/>
</intent-filter>
<meta-data android:name="android.service.chooser.chooser_target_service" android:value=".ContactChooserTargetService"/>
</activity>
最后使用针对ContactPicker和Conversation类的反编译器,找到了电话号码的额外键值是 jid 。
Finally using a decompiler for ContactPicker and Conversation class,the extra key-value for phone number was found to be "jid".