Skip to content

Instantly share code, notes, and snippets.

@cliffgr
Last active July 9, 2018 13:41
Show Gist options
  • Save cliffgr/2bf201d73e5bc168a8f668521b31c0f3 to your computer and use it in GitHub Desktop.
Save cliffgr/2bf201d73e5bc168a8f668521b31c0f3 to your computer and use it in GitHub Desktop.
private void openWhatsAppForFeedback() {
boolean isWhatsAppInstalled = whatsappInstalled("com.whatsapp");
if (isWhatsAppInstalled) {
String smsNumber = "966535550107"; //without '+'
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("User ID: " + mCipherUserId);
stringBuffer.append("User account: " + mSessionManager.getStringPreference(SessionManager.USER_EMAIL));
try {
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, stringBuffer.toString());
sendIntent.putExtra("jid", smsNumber + "@s.whatsapp.net"); //phone number without "+" prefix
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
} catch (Exception e) {
Toast.makeText(getActivity(), "Error/n" + e.toString(), Toast.LENGTH_SHORT).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment