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:de.Maxr1998.maxlock.thememanager.ThemeListFragment.java

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.button_install:
        if (position != -1) {
            hideBottomBar(true);/*  ww  w. java2s .  co  m*/
            Intent intent = new Intent();
            intent.setComponent(new ComponentName("de.Maxr1998.xposed.maxlock",
                    "de.Maxr1998.xposed.maxlock.ui.ThemeService"));
            intent.putExtra("extra", 1);
            intent.putExtra("package", mAdapter.getItem(position).get("packageName"));
            getActivity().startService(intent);
            SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.theme_installed)
                    .actionLabel(R.string.undo).actionListener(new ActionClickListener() {
                        @Override
                        public void onActionClicked(Snackbar snackbar) {
                            Intent intent = new Intent();
                            intent.setComponent(new ComponentName("de.Maxr1998.xposed.maxlock",
                                    "de.Maxr1998.xposed.maxlock.ui.ThemeService"));
                            intent.putExtra("extra", 2);
                            getActivity().startService(intent);
                            SnackbarManager.show(Snackbar.with(getActivity()).text(R.string.theme_uninstalled)
                                    .duration(Snackbar.SnackbarDuration.LENGTH_SHORT));
                        }
                    }).actionColorResource(R.color.accent));
            hideBottomBar(false);
        }
        break;
    }
}

From source file:com.kccomy.orgar.ui.note.NotePresenter.java

@Override
public void shareToOther(@NonNull String packageName, @NonNull String name) {
    Intent it = new Intent(Intent.ACTION_SEND);
    it.setComponent(new ComponentName(packageName, name));
    it.putExtra(Intent.EXTRA_TEXT, "TBD");
    it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    it.setType("text/plain");
    context.startActivity(it);/*from  w  w w  .  java2 s .c om*/
}

From source file:org.telegram.messenger.GcmBroadcastReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    FileLog.d("tmessages", "GCM received intent: " + intent);
    ComponentName comp = new ComponentName(context.getPackageName(), GcmService.class.getName());
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);//from   ww  w  . j av a2s  .c  o m
}

From source file:org.mozilla.gecko.sync.bridge.GCMBridgeBroadcastReceiver.java

@Override
/** On GCM.receive events...
 * This is called by the android framework
 *
 *//*  ww w  .  j  av  a  2 s .c o  m*/
public void onReceive(Context context, Intent intent) {
    Logger.info("GCMBridgeBroadcastReceiver", "Received GCM message");
    ComponentName comp = new ComponentName(context.getPackageName(), GCM.class.getName());
    startWakefulService(context, intent.setComponent(comp));
    setResultCode(Activity.RESULT_OK);
}

From source file:org.chromium.GcmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);//  w  w  w  . ja v a2  s  .  com
}

From source file:com.secbro.qark.tapjacking.TapJackingExploitFragment.java

private void launchExportedActivity(final String exportedActivityName) {

    Thread t = new Thread() {
        public void run() {
            /*/*from  www .ja  v  a  2  s  .  c o m*/
             * We sleep first in order for the toasts to consume the screen
             * before the activity launches
             */
            try {
                sleep(1800);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(getString(R.string.packageName), exportedActivityName));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    };
    t.start();
}

From source file:com.secbro.qark.exportedcomponent.exportedactivity.IntentParamsFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null) {
        keys = savedInstanceState.getStringArrayList(IntentSenderActivity.INTENT_KEYS);
        exportedActivityName = savedInstanceState
                .getString(ExportedActivityListFragment.EXPORTED_ACTIVITY_NAME);
        exportedActivityId = savedInstanceState.getString(ExportedActivityListFragment.EXPORTED_ACTIVITY_ID);
    } else {/*www.java2  s  . c om*/
        Bundle bundle = getArguments();
        if (bundle != null) {
            keys = bundle.getStringArrayList(IntentSenderActivity.INTENT_KEYS);
            exportedActivityName = bundle.getString(ExportedActivityListFragment.EXPORTED_ACTIVITY_NAME);
            exportedActivityId = bundle.getString(ExportedActivityListFragment.EXPORTED_ACTIVITY_ID);
        }
    }

    if (keys == null || keys.isEmpty()) {
        throw new IllegalArgumentException("Keys null");
    }

    LinearLayout paramsLayout = (LinearLayout) getView().findViewById(R.id.paramsLayout);

    for (String key : keys) {
        createKeyValuePairLayout(key, paramsLayout);
    }

    Button button = (Button) getView().findViewById(R.id.submitButton);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent();
            intent.setComponent(
                    new ComponentName(getResources().getString(R.string.packageName), exportedActivityName));
            for (String key : keys) {
                intent.putExtra(((TextView) getView().findViewWithTag("key" + key)).getText().toString(),
                        ((EditText) getView().findViewWithTag("value" + key)).getText().toString());

            }
            startActivityForResult(intent, REQUEST_CODE);
            Toast.makeText(getActivity(), "Intent sent", Toast.LENGTH_LONG).show();
        }
    });
}

From source file:com.ubikod.capptain.android.sdk.track.CapptainTrackReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    /* Once the application identifier is known */
    if ("com.ubikod.capptain.intent.action.APPID_GOT".equals(intent.getAction())) {
        /* Init the tracking agent */
        String appId = intent.getStringExtra("appId");
        CapptainTrackAgent.getInstance(context).onAppIdGot(appId);
    }//  ww  w.jav  a 2s. c om

    /* During installation, an install referrer may be triggered */
    else if ("com.android.vending.INSTALL_REFERRER".equals(intent.getAction())) {
        /* Forward this action to configured receivers */
        String forwardList = CapptainUtils.getMetaData(context)
                .getString("capptain:track:installReferrerForwardList");
        if (forwardList != null)
            for (String component : forwardList.split(","))
                if (!component.equals(getClass().getName())) {
                    Intent clonedIntent = new Intent(intent);
                    clonedIntent.setComponent(new ComponentName(context, component));
                    context.sendBroadcast(clonedIntent);
                }

        /* Guess store from referrer */
        String referrer = Uri.decode(intent.getStringExtra("referrer"));
        String store;

        /* GetJar uses an opaque string always starting with z= */
        if (referrer.startsWith("z="))
            store = "GetJar";

        /* Assume Android Market otherwise */
        else
            store = "Android Market";

        /* Look for a source parameter */
        Uri uri = Uri.parse("a://a?" + referrer);
        String source = uri.getQueryParameter("utm_source");

        /*
         * Skip "androidmarket" source, this is the default one when not set or installed via web
         * Android Market.
         */
        if ("androidmarket".equals(source))
            source = null;

        /* Send app info to register store/source */
        Bundle appInfo = new Bundle();
        appInfo.putString("store", store);
        if (source != null) {
            /* Parse source, if coming from capptain, it may be a JSON complex object */
            try {
                /* Convert JSON to bundle (just flat strings) */
                JSONObject jsonInfo = new JSONObject(source);
                Iterator<?> keyIt = jsonInfo.keys();
                while (keyIt.hasNext()) {
                    String key = keyIt.next().toString();
                    appInfo.putString(key, jsonInfo.getString(key));
                }
            } catch (JSONException jsone) {
                /* Not an object, process as a string */
                appInfo.putString("source", source);
            }
        }

        /* Send app info */
        CapptainAgent.getInstance(context).sendAppInfo(appInfo);
    }
}

From source file:no.android.proxime.FeaturesActivity.java

private void setupPluginsInDrawer(final ViewGroup container) {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final PackageManager pm = getPackageManager();

    // look for Master Control Panel
    final Intent mcpIntent = new Intent(Intent.ACTION_MAIN);
    mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS);
    final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0);

    // configure link to Master Control Panel
    final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp);
    if (mcpInfo == null) {
        mcpItem.setTextColor(Color.GRAY);
        ColorMatrix grayscale = new ColorMatrix();
        grayscale.setSaturation(0.0f);//from   w  ww . ja v  a 2s  .c o  m
        mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale));
    }
    mcpItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            Intent action = mcpIntent;
            if (mcpInfo == null)
                action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI));
            action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            startActivity(action);
            mDrawerLayout.closeDrawers();
        }
    });

    // look for other plug-ins
    final Intent utilsIntent = new Intent(Intent.ACTION_MAIN);
    utilsIntent.addCategory(UTILS_CATEGORY);

    final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0);
    for (final ResolveInfo info : appList) {
        final View item = inflater.inflate(R.layout.drawer_plugin, container, false);
        final ImageView icon = (ImageView) item.findViewById(android.R.id.icon);
        final TextView label = (TextView) item.findViewById(android.R.id.text1);

        label.setText(info.loadLabel(pm));
        icon.setImageDrawable(info.loadIcon(pm));
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final Intent intent = new Intent();
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
                mDrawerLayout.closeDrawers();
            }
        });
        container.addView(item);
    }
}

From source file:com.gnuroot.rsinstaller.RSLauncherMain.java

/**
 * GNURoot Debian expects the following extras from install intents:
 *    1. launchType: This can be either launchTerm or launchXTerm. The command that is to be run after installation
 *       dictates this selection./*from   w  w w  . ja v  a 2 s .co m*/
 *   2. command: This is the command that will be executed in proot after installation. Often, this will be a
 *      script stored in your custom tar file to install additional packages if needed or to execute the extension.
 *   3. customTar: This is the custom tar file you've created for your extension.
 * @return
  */
private Intent getLaunchIntent() {
    String command;
    Intent installIntent = new Intent("com.gnuroot.debian.LAUNCH");
    installIntent.setComponent(new ComponentName("com.gnuroot.debian", "com.gnuroot.debian.GNURootMain"));
    installIntent.addCategory(Intent.CATEGORY_DEFAULT);
    installIntent.putExtra("launchType", "launchXTerm");
    command = "#!/bin/bash\n"
            + "if [ ! -f /support/.rs_custom_passed ] || [ ! -f /support/.rs_updated ]; then\n"
            + "  /support/untargz rs_custom /support/rs_custom.tar.gz\n" + "fi\n"
            + "if [ -f /support/.rs_custom_passed ]; then\n"
            + "  if [ ! -f /support/.rs_script_passed ]; then\n"
            + "    sudo /support/blockingScript rs_script /support/oldschoolrs_install.sh\n" + "  fi\n"
            + "  if [ ! -f /support/.rs_script_updated ]; then\n"
            + "    sudo mv /support/rs_update /usr/bin/oldschoolrs\n" + "    if [ $? == 0 ]; then\n"
            + "      touch /support/.rs_script_updated\n" + "      sudo chmod 755 /usr/bin/oldschoolrs\n"
            + "    fi\n" + "  fi\n" + "  if [ -f /support/.rs_script_passed ]; then\n"
            + "    /usr/bin/oldschoolrs\n" + "  fi\n" + "fi\n";
    installIntent.putExtra("command", command);
    installIntent.putExtra("packageName", "com.gnuroot.rsinstaller");
    installIntent.putExtra("GNURootVersion", GNURootVersion);
    installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    installIntent.setData(getTarUri());
    return installIntent;
}