Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nguyenlinhnttu/c14fa16d85097db6a7b49f7402811e65 to your computer and use it in GitHub Desktop.
Save nguyenlinhnttu/c14fa16d85097db6a7b49f7402811e65 to your computer and use it in GitHub Desktop.
public class Var {
public static void yKien(Context context,String email) {
try {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
String[] recipients = new String[]{email};
emailIntent.putExtra(Intent.EXTRA_EMAIL, recipients);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Góp ý về ứng dụng ");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Ý kiến:");
emailIntent.setType("plain/text");
final PackageManager pm = context.getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm") ||
info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
if (best != null)
emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
context.startActivity(emailIntent);
} catch (Exception e) {
Toast.makeText(context, "Application not found", Toast.LENGTH_SHORT).show();
}
}
public static void shareFB(Context context,String url) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, url);
intent.setType("text/plain");
List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.toLowerCase().contains("facebook")) {
intent.setPackage(info.activityInfo.packageName);
}
}
context.startActivity(intent);
}
public static void rateApp(Context context) {
Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try {
context.startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment