Skip to content

Commit

Permalink
intent for send feedback email
Browse files Browse the repository at this point in the history
  • Loading branch information
pocho23 committed Feb 23, 2015
1 parent 294b0bf commit 7830088
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions LibraryRateMe/src/com/androidsx/rateme/DialogFeedback.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
Expand Down Expand Up @@ -128,20 +129,21 @@ private void initializeUiFieldsDialogGoToMail(){

private void goToMail() {
final String subject = getResources().getString(R.string.rateme_subject_email, getResources().getString(R.string.app_name));
String packageNameGmail = "com.google.android.gm";

try {
Intent sendMailtoGmail = new Intent(Intent.ACTION_SEND);
sendMailtoGmail.setType("plain/text");
sendMailtoGmail.putExtra(Intent.EXTRA_EMAIL, new String[] { getArguments().getString(EXTRA_EMAIL) });
sendMailtoGmail.putExtra(Intent.EXTRA_SUBJECT, subject);
sendMailtoGmail.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
startActivity(Intent.createChooser(sendMailtoGmail, ""));
if (isPackageInstalled(packageNameGmail)) {
Intent sendMailWithGmail = new Intent(Intent.ACTION_SEND);
sendMailWithGmail.setType("plain/text");
sendMailWithGmail.putExtra(Intent.EXTRA_EMAIL, new String[]{getArguments().getString(EXTRA_EMAIL)});
sendMailWithGmail.putExtra(Intent.EXTRA_SUBJECT, subject);
sendMailWithGmail.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
startActivity(Intent.createChooser(sendMailWithGmail, ""));
} else {
sendGenericMail(subject);
}
} catch (android.content.ActivityNotFoundException ex) {
Log.w(TAG, "Cannot send email with Gmail, use the generic chooser");
Intent sendGeneric = new Intent(Intent.ACTION_SEND);
sendGeneric.setType("plain/text");
sendGeneric.putExtra(Intent.EXTRA_EMAIL, new String[] { getArguments().getString(EXTRA_EMAIL) });
sendGeneric.putExtra(Intent.EXTRA_SUBJECT, subject);
startActivity(Intent.createChooser(sendGeneric, ""));
sendGenericMail(subject);
}
}

Expand All @@ -167,4 +169,13 @@ private boolean isPackageInstalled(String packageName) {
}
}

private void sendGenericMail(String subject) {
Log.w(TAG, "Cannot send email with Gmail, use the generic chooser");
Intent sendGeneric = new Intent(Intent.ACTION_SEND);
sendGeneric.setType("plain/text");
sendGeneric.putExtra(Intent.EXTRA_EMAIL, new String[] { getArguments().getString(EXTRA_EMAIL) });
sendGeneric.putExtra(Intent.EXTRA_SUBJECT, subject);
startActivity(Intent.createChooser(sendGeneric, ""));
}

}

0 comments on commit 7830088

Please sign in to comment.