Issue
I'm building an app that will ask the user to export a chat from WhatsApp into my app. How can I show my app in the "Send chat via.." intent window?
Solution
The correct way to do this is to add the following intent-filter:
<intent-filter>
<action android:name="android.intent.action.SENDTO"/>
<data android:scheme="mailto"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="*/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<data android:mimeType="*/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
Then you can read the content of the chat using this:
Uri uri = intent.getClipData().getItemAt(i).getUri();
InputStream inputstream = getContentResolver().openInputStream(uri);
byte[] data = new byte[1024];
int bytesRead = inputstream.read(data);
while (bytesRead != -1) {
chatContent.append(new String(data));
bytesRead = inputstream.read(data);
}
// TODO - Here we can do whatever we want with the chat content chatContent.toString()
if (mainTextView != null){
mainTextView.setText(chatContent.toString());
}
Answered By - Javi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.