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.airg.android.permission.sample.MainActivity.java

private void gotoSettings() {
    final Intent intent;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                Uri.fromParts("package", getPackageName(), null));
    } else {/*from   ww w  . j a  v  a  2s.c  o m*/
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
        intent.putExtra(Build.VERSION.SDK_INT == Build.VERSION_CODES.FROYO ? "pkg"
                : "com.android.settings.ApplicationPkgName", getPackageName());
    }

    startActivityForResult(intent, REQUEST_SETTINGS);
}

From source file:com.google.zxing.client.android.result.ResultHandler.java

final void searchBookContents(String isbnOrUrl) {
    Intent intent = new Intent(Intents.SearchBookContents.ACTION);
    intent.setClassName(activity, SearchBookContentsActivity.class.getName());
    putExtra(intent, Intents.SearchBookContents.ISBN, isbnOrUrl);
    launchIntent(intent);//from  ww  w  .j  a va 2s  .c  o  m
}

From source file:com.fastbootmobile.encore.app.MainActivity.java

private void notifyUnconfiguredProvider(final ProviderConnection conn) {
    showSnackBar(getString(R.string.plugin_not_configured_snackbar, conn.getProviderName()),
            getString(R.string.configure), new Snackbar.ActionClickListener() {
                @Override/*from   w  w  w.  j  a  v a 2s  .  c o  m*/
                public void onActionClicked() {
                    Intent i = new Intent();
                    i.setClassName(conn.getPackage(), conn.getConfigurationActivity());
                    try {
                        mConfiguringProvider = conn;
                        startActivity(i);
                    } catch (SecurityException e) {
                        Log.e(TAG, "Cannot start: Is your activity not exported?");
                        Toast.makeText(MainActivity.this,
                                "Cannot start: Make sure you set 'exported=true' flag on your settings activity.",
                                Toast.LENGTH_LONG).show();
                    } catch (ActivityNotFoundException e) {
                        Log.e(TAG, "Cannot start: Unknown activity");
                        Toast.makeText(MainActivity.this,
                                "Cannot start: The settings activity hasn't been found in the package.",
                                Toast.LENGTH_LONG).show();
                    }
                }
            });
}

From source file:com.google.zxing.client.android.result.ResultHandler.java

final void openGoogleShopper(String query) {

    // Construct Intent to launch Shopper
    Intent intent = new Intent(Intent.ACTION_SEARCH);
    intent.setClassName(GOOGLE_SHOPPER_PACKAGE, GOOGLE_SHOPPER_ACTIVITY);
    intent.putExtra(SearchManager.QUERY, query);

    // Is it available?
    PackageManager pm = activity.getPackageManager();
    Collection<?> availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

    if (availableApps != null && !availableApps.isEmpty()) {
        // If something can handle it, start it
        activity.startActivity(intent);//from w w w . ja v  a2 s .  c o  m
    } else {
        // Otherwise offer to install it from Market.
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(R.string.msg_google_shopper_missing);
        builder.setMessage(R.string.msg_install_google_shopper);
        builder.setIcon(R.drawable.shopper_icon);
        builder.setPositiveButton(R.string.button_ok, shopperMarketListener);
        builder.setNegativeButton(R.string.button_cancel, null);
        builder.show();
    }
}

From source file:com.seo.downloadproviders.downloads.DownloadNotification.java

void notificationForCompletedDownload(long id, String title, int status, int destination, long lastMod) {
    // Add the notifications
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    builder.setSmallIcon(android.R.drawable.stat_sys_download_done);
    if (title == null || title.length() == 0) {
        title = mContext.getResources().getString(R.string.download_unknown_title);
    }/*from  w ww.  j  a  v  a  2  s.c  om*/
    Uri contentUri = ContentUris.withAppendedId(Downloads.ALL_DOWNLOADS_CONTENT_URI, id);
    String caption;
    Intent intent;
    if (Downloads.isStatusError(status)) {
        caption = mContext.getResources().getString(R.string.notification_download_failed);
        intent = new Intent(Constants.ACTION_LIST);
    } else {
        caption = mContext.getResources().getString(R.string.notification_download_complete);
        intent = new Intent(Constants.ACTION_OPEN);
    }
    intent.setClassName(mContext.getPackageName(), DownloadReceiver.class.getName());
    intent.setData(contentUri);

    builder.setWhen(lastMod);
    builder.setContentTitle(title);
    builder.setContentText(caption);
    builder.setContentIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0));

    intent = new Intent(Constants.ACTION_HIDE);
    intent.setClassName(mContext.getPackageName(), DownloadReceiver.class.getName());
    intent.setData(contentUri);
    builder.setDeleteIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0));

    mNotifManager.notify((int) id, builder.build());
}

From source file:com.allmycode.flags.other.MyActivityOther.java

public void go(View view) {
    Intent intent = new Intent();
    String targetActivityName = "com.allmycode.flags";
    String fromEditText = targetActivity.getText().toString().trim();
    String other = (fromEditText.contains("Other")) ? ".other" : "";
    targetActivityName += other;/*from  w  ww  .j  ava2 s. c om*/
    targetActivityName += ".FlagsDemoActivity";
    targetActivityName += fromEditText;
    Log.i(CLASSNAME, "Target activity: >>" + targetActivityName + "<<");
    intent.setClassName("com.allmycode.flags" + other, targetActivityName);
    String allFlags = flags.getText().toString();
    int flagsValue = 0;
    if (allFlags != "" && allFlags != null) {

        TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter('|');
        splitter.setString(allFlags);
        boolean existErrors = false;
        for (String flagName : splitter) {

            Log.i(CLASSNAME, ">>" + flagName + "<<");

            flagName = flagName.trim();
            if (!flagName.equals("") && flagName != null) { // BARRY
                                                            // need
                                                            // both?
                if (isHex(flagName)) {
                    Log.i(CLASSNAME, flagName + " is hex");
                    flagsValue |= Integer.parseInt(flagName.substring(2), 16);
                } else if (isDec(flagName)) {
                    Log.i(CLASSNAME, flagName + " is decimal");
                    flagsValue |= Integer.parseInt(flagName);
                } else {
                    Field flagsField = null;
                    try {
                        Log.i(CLASSNAME, "About to do reflection>>" + flagName + "<<");
                        flagsField = Intent.class.getField(flagName);
                        Log.i(CLASSNAME, Integer.toString(flagsField.getInt(this)));
                        flagsValue |= flagsField.getInt(this);
                    } catch (SecurityException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    } catch (NoSuchFieldException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    } catch (IllegalAccessException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    }
                    try {
                        Log.i(CLASSNAME, Integer.toHexString(flagsValue));
                        if (flagsValue != 0) {
                            intent.addFlags(flagsValue);
                        }
                    } catch (IllegalArgumentException e) {
                        existErrors = true;
                        e.printStackTrace();
                    }
                }
            }
        }
        if (flagsValue != 0) {
            intent.addFlags(flagsValue);
        }
        intent.putExtra("existErrors", existErrors);

        Log.i(CLASSNAME, "About to start " + intent.toString());
        startActivity(intent);
    }
}

From source file:net.vivekiyer.GAL.CorporateAddressBook.java

@Override
public void onContactSelected(Contact contact) {
    // Create a parcel with the associated contact object
    // This parcel is used to send data to the activity

    this.selectedContact = contact;

    final FragmentManager fragmentManager = getSupportFragmentManager();

    CorporateContactRecordFragment details = (CorporateContactRecordFragment) fragmentManager
            .findFragmentById(R.id.contact_fragment);

    if (details == null || !details.isInLayout()) {
        final Bundle b = new Bundle();
        b.putParcelable("net.vivekiyer.GAL", selectedContact); //$NON-NLS-1$

        // Launch the activity
        final Intent myIntent = new Intent();
        myIntent.setClassName("net.vivekiyer.GAL", //$NON-NLS-1$
                "net.vivekiyer.GAL.CorporateContactRecord"); //$NON-NLS-1$

        myIntent.putExtras(b);//w  w  w.j  a va2 s.  co m
        startActivity(myIntent);
    } else {
        CorporateAddressBookFragment list = (CorporateAddressBookFragment) fragmentManager
                .findFragmentById(R.id.main_fragment);
        list.setViewBackground(true);

        details.setContact(selectedContact);

        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        //ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        // Below does not work since it resizes the result fragment before anim starts,
        // making it look rather weird. Better off w/o anims, unfortunately.
        //ft.setCustomAnimations(R.anim.slide_in, R.anim.slide_out);
        ft.show(details);
        ft.commit();
    }
}

From source file:com.aware.ui.Plugins_Manager.java

private void drawUI() {
    //Clear previous states
    store_grid.removeAllViews();/* w  w w  .j a v a  2s.c  o  m*/

    //Build UI
    Cursor installed_plugins = getContentResolver().query(Aware_Plugins.CONTENT_URI, null, null, null,
            Aware_Plugins.PLUGIN_NAME + " ASC");
    if (installed_plugins != null && installed_plugins.moveToFirst()) {
        do {
            final String package_name = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_PACKAGE_NAME));
            final String name = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME));
            final String description = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_DESCRIPTION));
            final String developer = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_AUTHOR));
            final String version = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_VERSION));
            final int status = installed_plugins
                    .getInt(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_STATUS));

            final View pkg_view = inflater.inflate(R.layout.plugins_store_pkg_list_item, null, false);
            pkg_view.setTag(package_name); //each view has the package name as a tag for easier references

            try {
                ImageView pkg_icon = (ImageView) pkg_view.findViewById(R.id.pkg_icon);
                if (status != PLUGIN_NOT_INSTALLED) {
                    ApplicationInfo appInfo = getPackageManager().getApplicationInfo(package_name,
                            PackageManager.GET_META_DATA);
                    pkg_icon.setImageDrawable(appInfo.loadIcon(getPackageManager()));
                } else {
                    byte[] img = installed_plugins
                            .getBlob(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_ICON));
                    if (img != null)
                        pkg_icon.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length));
                }

                TextView pkg_title = (TextView) pkg_view.findViewById(R.id.pkg_title);
                pkg_title.setText(installed_plugins
                        .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME)));

                ImageView pkg_state = (ImageView) pkg_view.findViewById(R.id.pkg_state);

                switch (status) {
                case PLUGIN_DISABLED:
                    pkg_state.setVisibility(View.INVISIBLE);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            if (isClassAvailable(package_name, "Settings")) {
                                builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        Intent open_settings = new Intent();
                                        open_settings.setClassName(package_name, package_name + ".Settings");
                                        startActivity(open_settings);
                                    }
                                });
                            }
                            builder.setPositiveButton("Activate", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.startPlugin(getApplicationContext(), package_name);
                                    drawUI();
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                case PLUGIN_ACTIVE:
                    pkg_state.setImageResource(R.drawable.ic_pkg_active);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            if (isClassAvailable(package_name, "Settings")) {
                                builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        Intent open_settings = new Intent();
                                        open_settings.setClassName(package_name, package_name + ".Settings");
                                        startActivity(open_settings);
                                    }
                                });
                            }
                            builder.setPositiveButton("Deactivate", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.stopPlugin(getApplicationContext(), package_name);
                                    drawUI();
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                case PLUGIN_UPDATED:
                    pkg_state.setImageResource(R.drawable.ic_pkg_updated);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            if (isClassAvailable(package_name, "Settings")) {
                                builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        Intent open_settings = new Intent();
                                        open_settings.setClassName(package_name, package_name + ".Settings");
                                        startActivity(open_settings);
                                    }
                                });
                            }
                            builder.setNeutralButton("Deactivate", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.stopPlugin(getApplicationContext(), package_name);
                                    drawUI();
                                }
                            });
                            builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.downloadPlugin(getApplicationContext(), package_name, true);
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                case PLUGIN_NOT_INSTALLED:
                    pkg_state.setImageResource(R.drawable.ic_pkg_download);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                            builder.setPositiveButton("Install", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.downloadPlugin(getApplicationContext(), package_name, false);
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                }
                store_grid.addView(pkg_view);
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        } while (installed_plugins.moveToNext());
    }
    if (installed_plugins != null && !installed_plugins.isClosed())
        installed_plugins.close();
}

From source file:com.allmycode.flags.MyActivity.java

public void go(View view) {
    Intent intent = null;
    String targetActivityName = "com.allmycode.flags";
    intent = new Intent();
    String fromEditText = targetActivity.getText().toString().trim();
    String other = (fromEditText.contains("Other")) ? ".other" : "";
    targetActivityName += other;/*from  www . j av  a2  s. c o m*/
    targetActivityName += ".FlagsDemoActivity";
    targetActivityName += fromEditText;
    Log.i(CLASSNAME, "Target activity: >>" + targetActivityName + "<<");
    intent.setClassName("com.allmycode.flags" + other, targetActivityName);
    String allFlags = flags.getText().toString();
    int flagsValue = 0;
    if (allFlags != "" && allFlags != null) {

        TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter('|');
        splitter.setString(allFlags);
        boolean existErrors = false;
        for (String flagName : splitter) {

            Log.i(CLASSNAME, ">>" + flagName + "<<");

            flagName = flagName.trim();
            if (!flagName.equals("") && flagName != null) { // BARRY
                                                            // need
                                                            // both?
                if (isHex(flagName)) {
                    Log.i(CLASSNAME, flagName + " is hex");
                    flagsValue |= Integer.parseInt(flagName.substring(2), 16);
                } else if (isDec(flagName)) {
                    Log.i(CLASSNAME, flagName + " is decimal");
                    flagsValue |= Integer.parseInt(flagName);
                } else {
                    Field flagsField = null;
                    try {
                        Log.i(CLASSNAME, "About to do reflection>>" + flagName + "<<");
                        flagsField = Intent.class.getField(flagName);
                        Log.i(CLASSNAME, Integer.toString(flagsField.getInt(this)));
                        flagsValue |= flagsField.getInt(this);
                    } catch (SecurityException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    } catch (NoSuchFieldException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    } catch (IllegalAccessException ex) {
                        existErrors = true;
                        ex.printStackTrace();
                    }
                    try {
                        Log.i(CLASSNAME, Integer.toHexString(flagsValue));
                        if (flagsValue != 0) {
                            intent.addFlags(flagsValue);
                        }
                    } catch (IllegalArgumentException e) {
                        existErrors = true;
                        e.printStackTrace();
                    }
                }
            }
        }
        if (flagsValue != 0) {
            intent.addFlags(flagsValue);
        }
        intent.putExtra("existErrors", existErrors);

        Log.i(CLASSNAME, "About to start " + intent.toString());
        startActivity(intent);
    }
}

From source file:com.oakonell.dndcharacter.views.character.CharacterActivity.java

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        Intent intent = new Intent();
        intent.setClassName(this, SettingsActivity.class.getName());
        startActivity(intent);/*from  w w  w  . j a va2 s.  c om*/
        return true;
    }
    if (id == R.id.action_about) {
        final AboutDialog aboutDialog = AboutDialog.create();
        aboutDialog.show(getSupportFragmentManager(), "about");
        return true;
    }
    if (id == R.id.action_long_rest) {
        LongRestDialogFragment dialog = LongRestDialogFragment.createDialog();
        dialog.show(getSupportFragmentManager(), "short_rest_frag");
        return true;
    }
    if (id == R.id.action_add_effect) {
        SelectEffectDialogFragment dialog = SelectEffectDialogFragment
                .createDialog(new SelectEffectDialogFragment.AddEffectToCharacterListener(this));
        dialog.show(getSupportFragmentManager(), ADD_EFFECT_DIALOG);
        return true;
    }
    if (id == R.id.action_dice_roller) {
        DiceRollerFragment dialog = DiceRollerFragment.createDialog();
        dialog.show(getSupportFragmentManager(), "dice_roller");
        return true;
    }
    if (id == R.id.action_short_rest) {
        ShortRestDialogFragment dialog = ShortRestDialogFragment.createDialog();
        dialog.show(getSupportFragmentManager(), "short_rest_frag");

        return true;
    }
    if (id == R.id.action_delete) {
        Toast.makeText(this, "Clicked delete character ", Toast.LENGTH_SHORT).show();
        return true;
    }
    if (id == R.id.action_level_up) {
        AddClassLevelDialogFragment dialog = AddClassLevelDialogFragment.createDialog();
        dialog.show(getSupportFragmentManager(), "level_up");
        return true;
    }

    return super.onOptionsItemSelected(item);
}