Example usage for android.content Intent setAction

List of usage examples for android.content Intent setAction

Introduction

In this page you can find the example usage for android.content Intent setAction.

Prototype

public @NonNull Intent setAction(@Nullable String action) 

Source Link

Document

Set the general action to be performed.

Usage

From source file:Main.java

public static void mail(Activity activity, String subject, String text, String mail) {

    Intent intent = new Intent();

    intent.setAction(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:" + mail));
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, text);

    activity.startActivity(intent);//from   w w w .ja v a2s  .  c  o m

}

From source file:Main.java

/**
 * call system to install the APK file/*from   w w w  .j  ava2 s.  c o  m*/
 * */
public static void installAPKFile(Context context, File file) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static Intent getGalleryIntent() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_PICK);
    intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
    return intent;
}

From source file:Main.java

public static void startInstallAPK(Context context, String path) {
    try {//from  w ww .  j a  v a 2 s . co  m
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive");
        context.startActivity(intent);
    } catch (Exception e) {

    }
}

From source file:Main.java

public static boolean openApp(Activity activity, String action) {
    try {/* w w w.ja va2  s .co m*/

        Intent intent = new Intent();
        intent.setAction(action);
        activity.startActivity(intent);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static void startBrowser(Context context, String url) {
    try {//from w  ww  .j a  v a  2 s .co m
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri content_url = Uri.parse(url);
        intent.setData(content_url);
        context.startActivity(intent);
    } catch (Exception e) {

    }
}

From source file:Main.java

public static Intent getOpenFileIntent(Uri uri, String mimeType) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, mimeType);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    return intent;
}

From source file:Main.java

public static void closeService(Context context, Class<?> cls, String action) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, cls);
    intent.setAction(action);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.cancel(pendingIntent);/*from w w  w .j av a2s  .  c  om*/
}

From source file:Main.java

/**
 * @param activity/*from w  ww .  j  a v  a  2s.  c  om*/
 * @param phone
 */
public static void phone(Activity activity, String phone) {

    phone = "tel:" + phone.trim();

    Intent intent = new Intent();

    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(phone));

    activity.startActivity(intent);

}

From source file:Main.java

public static void startDialer(Context context, String phoneNumber) {
    try {//from w  w  w .  ja v a  2  s .co  m
        Intent dial = new Intent();
        dial.setAction(Intent.ACTION_DIAL);
        dial.setData(Uri.parse("tel:" + phoneNumber));
        context.startActivity(dial);
    } catch (Exception ex) {
        Log.e(TAG, "Error starting phone dialer intent.", ex);
        Toast.makeText(context, "Sorry, we couldn't find any app to place a phone call!", Toast.LENGTH_SHORT)
                .show();
    }
}