Example usage for android.content Intent setData

List of usage examples for android.content Intent setData

Introduction

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

Prototype

public @NonNull Intent setData(@Nullable Uri data) 

Source Link

Document

Set the data this intent is operating on.

Usage

From source file:Main.java

public static void showUCBrowser(Context context, String visitUrl) {
    Intent intent = new Intent();
    intent.setClassName("com.uc.browser", "com.uc.browser.ActivityUpdate");
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(Uri.parse(visitUrl));
    context.startActivity(intent);//from   www  .  ja va2 s.  co  m
}

From source file:Main.java

public static void showQQBrowser(Context context, String visitUrl) {
    Intent intent = new Intent();
    intent.setClassName("com.tencent.mtt", "com.tencent.mtt.MainActivity");
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(Uri.parse(visitUrl));
    context.startActivity(intent);//w  ww. java  2 s . c o m
}

From source file:com.doplgangr.secrecy.Util.java

public static void openURI(String uri) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(uri));
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    CustomApp.context.startActivity(i);//from   www . j a va 2  s.  c  o  m

}

From source file:Main.java

public static void showOperaBrowser(Context context, String visitUrl) {
    Intent intent = new Intent();
    intent.setClassName("com.opera.mini.android", "com.opera.mini.android.Browser");
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(Uri.parse(visitUrl));
    context.startActivity(intent);/* ww w . j a v  a  2 s .com*/
}

From source file:Main.java

public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setType("application/vnd.android.package-archive");
    intent.setData(Uri.fromFile(file));
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);//w w w  .  j  a  v  a2 s . co m

}

From source file:Main.java

@SuppressLint("InlinedApi")
public static void openSys(Context context, String packageName) {
    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 9) {
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.fromParts("package", packageName, null));
    } else {//from  w ww .j a  v a2 s. co  m
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
        String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName");
        intent.putExtra(appPkgName, packageName);
    }
    context.startActivity(intent);
}

From source file:Main.java

/**
 * Converts a fragment arguments bundle into an intent.
 */// w  w w. ja  v  a  2s.c  o  m
public static Intent fragmentArgumentsToIntent(Bundle arguments) {
    Intent intent = new Intent();
    if (arguments == null) {
        return intent;
    }

    final Uri data = arguments.getParcelable("_uri");
    if (data != null) {
        intent.setData(data);
    }

    intent.putExtras(arguments);
    intent.removeExtra("_uri");
    return intent;
}

From source file:Main.java

public static final void openGPS(Context context) {
    Intent GPSIntent = new Intent();
    GPSIntent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
    GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
    GPSIntent.setData(Uri.parse("custom:3"));
    try {// www. j a va2s. c o  m
        PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static final void openGPS(Context context) {
    Intent intent = new Intent("com.nd.android.starapp.ui.jay.weibo.activity.GPS");
    intent.putExtra("enabled", true);
    context.sendBroadcast(intent);/* w w w  . j a  va2 s.co  m*/

    String provider = Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    if (!provider.contains("gps")) { //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3"));
        context.sendBroadcast(poke);
    }
}

From source file:Main.java

/**
 * Convert a fragment arguments bundle into an intent.
 *//*from ww w .  j a va  2  s. c o m*/
public static Intent fragmentArgumentsToIntent(Bundle arguments) {
    Intent intent = new Intent();
    if (arguments == null) {
        return intent;
    }

    final Uri data = arguments.getParcelable(URI_KEY);
    if (data != null) {
        intent.setData(data);
    }

    intent.putExtras(arguments);
    intent.removeExtra(URI_KEY);
    return intent;
}