Example usage for android.content Intent setComponent

List of usage examples for android.content Intent setComponent

Introduction

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

Prototype

public @NonNull Intent setComponent(@Nullable ComponentName component) 

Source Link

Document

(Usually optional) Explicitly set the component to handle the intent.

Usage

From source file:com.hsr.hemant.ppp.MainActivity.java

public static void openAppRating(Context context) {
    Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://dev?id=6565132919084735503"));
    boolean marketFound = false;

    // find all applications able to handle our rateIntent
    final List<ResolveInfo> otherApps = context.getPackageManager().queryIntentActivities(rateIntent, 0);
    for (ResolveInfo otherApp : otherApps) {
        // look for Google Play application
        if (otherApp.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {

            ActivityInfo otherAppActivity = otherApp.activityInfo;
            ComponentName componentName = new ComponentName(otherAppActivity.applicationInfo.packageName,
                    otherAppActivity.name);
            rateIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            rateIntent.setComponent(componentName);
            context.startActivity(rateIntent);
            marketFound = true;// w  w w .ja  va 2s.  c om
            break;

        }
    }

    // if GP not present on device, open web browser
    if (!marketFound) {
        Intent webIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/dev?id=6565132919084735503"));
        context.startActivity(webIntent);
    }
}

From source file:com.google.android.apps.dashclock.ExtensionSettingActivityProxy.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(android.R.style.Theme_Translucent_NoTitleBar);

    mExtension = getIntent().getStringExtra(DashClockService.EXTRA_COMPONENT_NAME);
    String activity = getIntent().getStringExtra(EXTRA_SETTINGS_ACTIVITY);
    if (mExtension == null || activity == null) {
        finish();//from w  w w .  j ava2  s  .c  om
        return;
    }

    try {
        Intent i = new Intent();
        i.setComponent(ComponentName.unflattenFromString(activity));
        startActivityForResult(i, RESULT_EXTENSION_SETTINGS);
    } catch (ActivityNotFoundException ex) {
        finish();
    }
}

From source file:com.noshufou.android.su.util.Util.java

public static void goHome(Context context) {
    // Be clever here, otherwise the home button doesn't work as advertised.
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Intent intent;
    if (prefs.getBoolean(Preferences.GHOST_MODE, false)) {
        intent = new Intent(context, HomeActivity.class);
    } else {/*from   w  ww  .j a  va 2s .c  om*/
        intent = new Intent();
        intent.setComponent(new ComponentName("com.noshufou.android.su", "com.noshufou.android.su.Su"));
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);
}

From source file:com.jieehd.villain.toolkit.stats.ReportingService.java

private void promptUser() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Intent nI = new Intent();
    nI.setComponent(new ComponentName(getPackageName(), AnonymousStats.class.getName()));
    PendingIntent pI = PendingIntent.getActivity(this, 0, nI, 0);
    Notification.Builder builder = new Notification.Builder(this).setAutoCancel(true)
            .setTicker("Annonymous Statistics").setContentIntent(pI).setWhen(0)
            .setContentTitle("Annonymous Statistics").setContentText("Enable Reporting");
    nm.notify(1, builder.getNotification());
}

From source file:com.android.settings.aokpstats.ReportingService.java

private void promptUser() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Intent nI = new Intent();
    nI.setComponent(new ComponentName(getPackageName(), Settings.AnonymousStatsActivity.class.getName()));
    PendingIntent pI = PendingIntent.getActivity(this, 0, nI, 0);
    Notification.Builder builder = new Notification.Builder(this).setSmallIcon(R.drawable.ic_aokp_stats_notif)
            .setAutoCancel(true).setTicker(getString(R.string.anonymous_statistics_title)).setContentIntent(pI)
            .setWhen(0).setContentTitle(getString(R.string.anonymous_statistics_title))
            .setContentText(getString(R.string.anonymous_notification_desc));
    nm.notify(1, builder.getNotification());
}

From source file:com.dolphin.push.GoogleCloudMessagingBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    ComponentName comp = new ComponentName(context.getPackageName(), serviceName());
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);/*from  ww w . j a  va 2 s.  c  o  m*/
}

From source file:jp.co.ipublishing.aeskit.notification.gcm.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final ComponentName componentName = getComponentName(context);
    startWakefulService(context, (intent.setComponent(componentName)));
    setResultCode(Activity.RESULT_OK);//from   www  .  ja  v  a  2s .  c  o  m
}

From source file:com.byhook.cordova.chromelauncher.ChromeLauncher.java

/**
 * Executes the request and returns PluginResult.
 * @param action                 The action to execute.
 * @param args                         JSONArry of arguments for the plugin.
 * @param callbackContext                The callback context used when calling back into JavaScript.
 * @return                                 A PluginResult object with a status and message.
 *///from   w  ww  . jav  a2  s. co  m
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    if (action.equals("open")) {
        String url = args.getString(0);

        Intent i = new Intent("android.intent.action.MAIN");
        i.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
        i.addCategory("android.intent.category.LAUNCHER");
        i.setData(Uri.parse(url));
        ((Activity) cordova).startActivity(i);
    } else if (action.equals("checkInstall")) {
        if (isInstalled("com.android.chrome")) {
            callbackContext.sendPluginResult(new PluginResult(status, true));
            return true;
        } else {
            status = PluginResult.Status.ERROR;
            callbackContext.sendPluginResult(new PluginResult(status, false));
            return true;
        }
    } else if (action.equals("openStore")) {
        Uri marketUri = Uri.parse("market://details?id=com.android.chrome");
        Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
        ((Activity) cordova).startActivity(marketIntent);
    }

    callbackContext.sendPluginResult(new PluginResult(status, result));
    return true;
}

From source file:cm.aptoide.ptdev.preferences.ManagerPreferences.java

private void removeLauncherShortcut(Context context) {
    final Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setComponent(new ComponentName(context.getPackageName(), "cm.aptoide.ptdev.Start"));

    final Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, Aptoide.getConfiguration().getMarketName());
    shortcutIntent.setComponent(new ComponentName(context.getPackageName(), "cm.aptoide.ptdev.Start"));
    intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");

    context.sendBroadcast(intent, null);
}

From source file:com.phonegap.plugins.startapp.StartApp.java

/**
 * Starts an activity./*  w  w  w  .  j  a v a  2s .  c  om*/
 *
 * @param component
 *            Activity ComponentName.
 *            E.g.: com.mycompany.myapp/com.mycompany.myapp.MyActivity
 */
void startActivity(String component) {
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.setComponent(ComponentName.unflattenFromString(component));
    this.ctx.startActivity(intent);
}