我无法通过 whatsapp 发送短信和图片。或者,我能够
在没有任何消息的情况下启动该特定联系人聊天线程,或者我只能发送消息但无法打开该特定联系人聊天线程。
我遵循了以下链接:
http://www.whatsapp.com/faq/en/android/28000012
Sending message through WhatsApp
Send Whatsapp message to specific contact
但没有成功:(
任何人都可以帮我解决这个问题。
如何在 Android 中的 Intent 的帮助下通过自己的应用程序通过 whatsapp 发送文本消息和图像?
最佳答案
尝试使用以下解决方案,
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 list fragment ,
普通共享 Intent ,使用“ SEND ”,它不允许您发送给特定联系人并需要联系人选择器。
具体联系人由Conversation类拾取,使用“ SEND_TO ” Action ,但使用短信正文,无法获取图片等附件。
<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>
进一步挖掘,我遇到了这个,
<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 ”。
关于java - 如何借助 Android 中的 Intent 从自己的应用程序通过 Whatsapp 发送文本消息和图像?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26627699/