Example usage for android.content Intent setClassName

List of usage examples for android.content Intent setClassName

Introduction

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

Prototype

public @NonNull Intent setClassName(@NonNull String packageName, @NonNull String className) 

Source Link

Document

Convenience for calling #setComponent with an explicit application package name and class name.

Usage

From source file:com.bangalore.barcamp.BCBUtils.java

public static void addNavigationActions(final BCBActivityBaseClass homeActivity) {
    homeActivity.setBehindContentView(R.layout.navigation_menu);
    int offset = 100;
    DisplayMetrics metrics = new DisplayMetrics();
    homeActivity.getWindow().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    offset = ((metrics.widthPixels * 130)) / 480;

    homeActivity.setBehindOffset(offset);
    homeActivity.setBehindScrollScale(0.5f);

    View view = homeActivity.findViewById(R.id.nav_agenda);
    view.setOnClickListener(new OnClickListener() {

        @Override// www  . j  a v a  2 s. c om
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, ScheduleActivity.class);
            homeActivity.startActivityForResult(intent, START_SCHEDULE);

        }
    });

    view = homeActivity.findViewById(R.id.nav_about);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, AboutActivity.class);
            homeActivity.startActivityForResult(intent, START_ABOUT);
        }
    });
    view = homeActivity.findViewById(R.id.nav_internal_venue_map);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, InternalVenueMapActivity.class);
            homeActivity.startActivityForResult(intent, START_INTERNAL_VENUE);
        }
    });

    view = homeActivity.findViewById(R.id.nav_settings);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, SettingsActivity.class);
            homeActivity.startActivityForResult(intent, START_SETTINGS);
        }
    });
    view.setVisibility(View.GONE);
    view = homeActivity.findViewById(R.id.nav_share);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, ShareActivity.class);
            homeActivity.startActivityForResult(intent, START_SHARE);
        }
    });
    view = homeActivity.findViewById(R.id.nav_tweets);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, WebViewActivity.class);
            intent.putExtra(WebViewActivity.URL, "file:///android_asset/bcb11_updates.html");
            homeActivity.startActivityForResult(intent, START_BCB12_TWEETS);
        }
    });
    view = homeActivity.findViewById(R.id.nav_update);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(homeActivity, UpdateMessagesActivity.class);
            homeActivity.startActivityForResult(intent, START_BCB_UPDATES);
        }
    });
    view = homeActivity.findViewById(R.id.nav_venue);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final PackageManager pm = homeActivity.getPackageManager();

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(BCB_LOCATION_MAPS_URL));
            final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
            for (ResolveInfo info : matches) {
                Log.e("MapPackage", info.loadLabel(pm) + " " + info.activityInfo.packageName + " "
                        + info.activityInfo.name);
                if (info.activityInfo.name.equals("com.google.android.maps.MapsActivity")) {
                    intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
                }
            }

            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            homeActivity.startActivity(intent);
        }
    });
    view = homeActivity.findViewById(R.id.nav_BCB);
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://barcampbangalore.org"));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            homeActivity.startActivity(intent);
        }
    });

}

From source file:com.android.mms.ui.MessageUtils.java

public static void replyMessage(int subId, Context context, String address) {
    Intent intent = new Intent();
    intent.putExtra("address", address);
    intent.putExtra("showinput", true);
    /// M: fix alps01858266. this put sub id here. @{
    intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
    /// @}/*  w ww. j a v a2  s  .  co  m*/
    intent.setClassName(context, "com.android.mms.ui.ComposeMessageActivity");
    context.startActivity(intent);
}

From source file:org.mozilla.gecko.GeckoApp.java

public void doRestart(String action) {
    Log.i(LOGTAG, "doRestart(\"" + action + "\")");
    try {//www  .j a  v a 2 s  .c om
        Intent intent = new Intent(action);
        intent.setClassName(getPackageName(), getPackageName() + ".Restarter");
        /* TODO: addEnvToIntent(intent); */
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        Log.i(LOGTAG, intent.toString());
        GeckoAppShell.killAnyZombies();
        startActivity(intent);
    } catch (Exception e) {
        Log.i(LOGTAG, "error doing restart", e);
    }
    finish();
    // Give the restart process time to start before we die
    GeckoAppShell.waitForAnotherGeckoProc();
}

From source file:com.nbplus.iotlib.IoTInterface.java

/**
 * Method used for binding with the service
 *///from   w ww.  ja v a 2 s.c  o  m
private boolean bindService() {
    /*
     * Note that this is an implicit Intent that must be defined in the
     * Android Manifest.
     */

    Intent i = null;
    if (IoTConstants.USE_ANOTHER_APP) {
        i = new Intent();
        i.setClassName(REMOTE_IOT_SERVICE_PACKAGE, REMOTE_IOT_SERVICE_CLASS);
        i.setAction(REMOTE_IOT_SERVICE_ACTION);
    } else {
        i = new Intent(mCtx, IoTService.class);
        i.setAction(REMOTE_IOT_SERVICE_ACTION);
    }

    try {
        if (mCtx.getApplicationContext().bindService(i, mConnection, Context.BIND_AUTO_CREATE)) {
            return true;
        }
    } catch (SecurityException e) {
        e.printStackTrace();
        Log.e(TAG, "Not allowed to bind to service Intent");
    }
    mServiceStatus = IoTServiceStatus.NONE;
    return false;
}

From source file:com.igniva.filemanager.activities.MainActivity.java

public void bindDrive() {
    Intent i = new Intent();
    i.setClassName("com.igniva.filemanager.driveplugin", "com.igniva.filemanager.driveplugin.MainService");
    try {/*ww  w . j  a v  a2  s.  co m*/
        bindService((i), mConnection, Context.BIND_AUTO_CREATE);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.amaze.filemanager.activities.MainActivity.java

public void bindDrive() {
    Intent i = new Intent();
    i.setClassName("com.amaze.filemanager.driveplugin", "com.amaze.filemanager.driveplugin.MainService");
    try {/*from   w  w w . j  av a 2s .  co m*/
        bindService((i), mConnection, Context.BIND_AUTO_CREATE);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.uguess.android.sysinfo.SiragonManager.java

private Intent getAboutSettingsIntent() {
    PackageManager pm = getActivity().getPackageManager();

    Intent it = new Intent(Intent.ACTION_VIEW);

    // try the htc specifc settings first to avoid some broken manifest
    // issue on certain htc models
    it.setClassName("com.android.settings", //$NON-NLS-1$
            "com.android.settings.framework.aboutphone.HtcAboutPhoneSettings"); //$NON-NLS-1$

    List<ResolveInfo> acts = pm.queryIntentActivities(it, 0);

    if (acts.size() > 0) {
        return it;
    } else {/*from  www  . j  av a 2s . c  o  m*/
        // try the standard settings
        it.setClassName("com.android.settings", //$NON-NLS-1$
                "com.android.settings.DeviceInfoSettings"); //$NON-NLS-1$

        acts = pm.queryIntentActivities(it, 0);

        if (acts.size() > 0) {
            return it;
        }
    }

    return null;
}

From source file:org.mozilla.gecko.GeckoAppShell.java

static boolean openUriExternal(String aUriSpec, String aMimeType, String aPackageName, String aClassName,
        String aAction, String aTitle) {
    Intent intent = getIntentForActionString(aAction);
    if (aAction.equalsIgnoreCase(Intent.ACTION_SEND)) {
        Intent shareIntent = getIntentForActionString(aAction);
        shareIntent.putExtra(Intent.EXTRA_TEXT, aUriSpec);
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, aTitle);
        if (aMimeType != null && aMimeType.length() > 0)
            shareIntent.setType(aMimeType);
        intent = Intent.createChooser(shareIntent,
                GeckoApp.mAppContext.getResources().getString(R.string.share_title));
    } else if (aMimeType.length() > 0) {
        intent.setDataAndType(Uri.parse(aUriSpec), aMimeType);
    } else {/*w  w w. ja  va  2s . co  m*/
        Uri uri = Uri.parse(aUriSpec);
        if ("sms".equals(uri.getScheme())) {
            // Have a apecial handling for the SMS, as the message body
            // is not extracted from the URI automatically
            final String query = uri.getEncodedQuery();
            if (query != null && query.length() > 0) {
                final String[] fields = query.split("&");
                boolean foundBody = false;
                String resultQuery = "";
                for (int i = 0; i < fields.length; i++) {
                    final String field = fields[i];
                    if (field.length() > 5 && "body=".equals(field.substring(0, 5))) {
                        final String body = Uri.decode(field.substring(5));
                        intent.putExtra("sms_body", body);
                        foundBody = true;
                    } else {
                        resultQuery = resultQuery.concat(resultQuery.length() > 0 ? "&" + field : field);
                    }
                }
                if (foundBody) {
                    // Put the query without the body field back into the URI
                    final String prefix = aUriSpec.substring(0, aUriSpec.indexOf('?'));
                    uri = Uri.parse(resultQuery.length() > 0 ? prefix + "?" + resultQuery : prefix);
                }
            }
        }
        intent.setData(uri);
    }
    if (aPackageName.length() > 0 && aClassName.length() > 0)
        intent.setClassName(aPackageName, aClassName);

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    try {
        GeckoApp.mAppContext.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        return false;
    }
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void addIntentToMenu(final Context context, final Menu menu, final Intent queryIntent,
        final int groupId) {
    if (context == null || menu == null || queryIntent == null)
        return;/*from  w w  w  .  j  a va 2  s  .com*/
    final PackageManager pm = context.getPackageManager();
    final Resources res = context.getResources();
    final float density = res.getDisplayMetrics().density;
    final int padding = Math.round(density * 4);
    final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, 0);
    for (final ResolveInfo info : activities) {
        final Intent intent = new Intent(queryIntent);
        final Drawable icon = info.loadIcon(pm);
        intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm));
        item.setIntent(intent);
        final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight();
        if (iw > 0 && ih > 0) {
            final Drawable iconWithPadding = new PaddingDrawable(icon, padding);
            iconWithPadding.setBounds(0, 0, iw, ih);
            item.setIcon(iconWithPadding);
        } else {
            item.setIcon(icon);
        }
    }
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void addIntentToMenuForExtension(final Context context, final Menu menu, final int groupId,
        final String action, final String parelableKey, final String parelableJSONKey,
        final FiretweetParcelable parcelable) {
    if (context == null || menu == null || action == null || parelableKey == null || parcelable == null)
        return;/*from  w w  w.  j a  v a2  s.  c  o  m*/
    final PackageManager pm = context.getPackageManager();
    final Resources res = context.getResources();
    final float density = res.getDisplayMetrics().density;
    final int padding = Math.round(density * 4);
    final Intent queryIntent = new Intent(action);
    queryIntent.setExtrasClassLoader(context.getClassLoader());
    final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA);
    for (final ResolveInfo info : activities) {
        final Intent intent = new Intent(queryIntent);
        if (isExtensionUseJSON(info)) {
            intent.putExtra(parelableJSONKey, JSONSerializer.toJSONObjectString(parcelable));
        } else {
            intent.putExtra(parelableKey, parcelable);
        }
        intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm));
        item.setIntent(intent);
        final Drawable metaDataDrawable = getMetadataDrawable(pm, info.activityInfo,
                METADATA_KEY_EXTENSION_ICON);
        final int actionIconColor = ThemeUtils.getThemeForegroundColor(context);
        if (metaDataDrawable != null) {
            metaDataDrawable.mutate();
            metaDataDrawable.setColorFilter(actionIconColor, Mode.SRC_ATOP);
            item.setIcon(metaDataDrawable);
        } else {
            final Drawable icon = info.loadIcon(pm);
            final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight();
            if (iw > 0 && ih > 0) {
                final Drawable iconWithPadding = new PaddingDrawable(icon, padding);
                iconWithPadding.setBounds(0, 0, iw, ih);
                item.setIcon(iconWithPadding);
            } else {
                item.setIcon(icon);
            }
        }

    }
}