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:fm.smart.r1.activity.ItemActivity.java

static void setSound(ImageView sound_icon, final String sound_url, final Context context, final int type_id,
        final String artifact_id, final String to_record) {
    if (!TextUtils.isEmpty(sound_url)) {
        OnClickListener sound_listener = new OnClickListener() {
            public void onClick(View v) {
                Main.playSound(sound_url, ItemListActivity.mMediaPlayer, context);
            }/*w w  w .j a  v a  2s  .c  o  m*/
        };
        sound_icon.setOnClickListener(sound_listener);
    } else {
        if (type_id == R.id.response_sound || type_id == R.id.translation_sound) {
            sound_icon.setVisibility(View.INVISIBLE);
        } else {
            sound_icon.setImageBitmap(
                    BitmapFactory.decodeResource(context.getResources(), R.drawable.inactive_sound_add));

            OnClickListener listener = new OnClickListener() {
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setClassName(context, CreateSoundActivity.class.getName());
                    Utils.putExtra(intent, "item_id", (String) item.item_node.atts.get("id"));
                    Utils.putExtra(intent, "to_record", to_record);
                    Utils.putExtra(intent, "id", artifact_id);
                    Utils.putExtra(intent, "sound_type", Integer.toString(type_id));
                    context.startActivity(intent);

                }
            };
            sound_icon.setOnClickListener(listener);
        }
    }
}

From source file:com.linkbubble.MainApplication.java

public static boolean handleBubbleAction(final Context context, BubbleAction action, final String urlAsString,
        long totalTrackedLoadTime) {
    Constant.ActionType actionType = Settings.get().getConsumeBubbleActionType(action);
    boolean result = false;
    if (actionType == Constant.ActionType.Share) {
        String consumePackageName = Settings.get().getConsumeBubblePackageName(action);
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString()
                + ", consumePackageName:" + consumePackageName);
        String consumeName = Settings.get().getConsumeBubbleActivityClassName(action);

        if (consumePackageName.equals(BuildConfig.APPLICATION_ID)
                && consumeName.equals(Constant.SHARE_PICKER_NAME)) {
            AlertDialog alertDialog = ActionItem.getShareAlert(context, false,
                    new ActionItem.OnActionItemSelectedListener() {
                        @Override
                        public void onSelected(ActionItem actionItem) {
                            Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("text/plain");
                            intent.setClassName(actionItem.mPackageName, actionItem.mActivityClassName);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra(Intent.EXTRA_TEXT, urlAsString);
                            String title = MainApplication.sTitleHashMap != null
                                    ? MainApplication.sTitleHashMap.get(urlAsString)
                                    : null;
                            if (title != null) {
                                intent.putExtra(Intent.EXTRA_SUBJECT, title);
                            }//from  www  .  j  a  v  a2  s.  c  om
                            context.startActivity(intent);
                        }
                    });
            Util.showThemedDialog(alertDialog);
            return true;
        }

        // TODO: Retrieve the class name below from the app in case Twitter ever change it.
        Intent intent = Util.getSendIntent(consumePackageName, consumeName, urlAsString);
        try {
            context.startActivity(intent);
            if (totalTrackedLoadTime > -1) {
                Settings.get().trackLinkLoadTime(totalTrackedLoadTime, Settings.LinkLoadType.ShareToOtherApp,
                        urlAsString);
            }
            result = true;
        } catch (ActivityNotFoundException ex) {
            Toast.makeText(context, R.string.consume_activity_not_found, Toast.LENGTH_LONG).show();
        } catch (SecurityException ex) {
            Toast.makeText(context, R.string.consume_activity_security_exception, Toast.LENGTH_SHORT).show();
        }
    } else if (actionType == Constant.ActionType.View) {
        String consumePackageName = Settings.get().getConsumeBubblePackageName(action);
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString()
                + ", consumePackageName:" + consumePackageName);
        result = MainApplication.loadIntent(context, consumePackageName,
                Settings.get().getConsumeBubbleActivityClassName(action), urlAsString, -1, true);
    } else if (action == BubbleAction.Close || action == BubbleAction.BackButton) {
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString());
        result = true;
    }

    if (result) {
        boolean hapticFeedbackEnabled = android.provider.Settings.System.getInt(context.getContentResolver(),
                android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) != 0;
        if (hapticFeedbackEnabled && action != BubbleAction.BackButton) {
            Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator.hasVibrator()) {
                vibrator.vibrate(10);
            }
        }
    }

    return result;
}

From source file:com.adguard.android.commons.BrowserUtils.java

public static void openSamsungBlockingOptions(Context context) {
    Intent intent = new Intent();
    intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        boolean found = false;
        for (ResolveInfo info : list) {
            if (info.activityInfo.packageName.contains(SAMSUNG_PACKAGE_PREFIX)
                    || info.activityInfo.packageName.contains(SAMSUNG)) {
                found = true;/*from w w w . j a  va 2 s  .  c om*/
                intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
            }
        }
        if (found) {
            context.startActivity(intent);
        }
    }
}

From source file:Main.java

/**
 * Returns a copy of {@param intent} with a class name set, if a class inside this app
 * has a corresponding intent filter./*www . j av a2s .c o m*/
 */
private static Intent getIntentInAppIfExists(Context context, Intent intent) {
    try {
        final Intent intentCopy = new Intent(intent);
        // Force this intentCopy to open inside the current app.
        intentCopy.setPackage(context.getPackageName());
        final List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intentCopy,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (list != null && list.size() != 0) {
            // Now that we know the intentCopy will work inside the current app, we
            // can return this intent non-null.
            if (list.get(0).activityInfo != null && !TextUtils.isEmpty(list.get(0).activityInfo.name)) {
                // Now that we know the class name, we may as well attach it to intentCopy
                // to prevent the package manager from needing to find it again inside
                // startActivity(). This is only needed for efficiency.
                intentCopy.setClassName(context.getPackageName(), list.get(0).activityInfo.name);
            }
            return intentCopy;
        }
        return null;
    } catch (Exception e) {
        // Don't let the package manager crash our app. If the package manager can't resolve the
        // intent here, then we can still call startActivity without calling setClass() first.
        return null;
    }
}

From source file:com.liferay.mobile.push.PushNotificationsReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    intent.setClassName(context, getServiceClassName());
    startWakefulService(context, intent);
}

From source file:org.csware.ee.utils.Tools.java

public static void show(final Activity activity, final int id) {
    final Context context = activity;
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("");
    builder.setMessage("");

    builder.setPositiveButton("", new DialogInterface.OnClickListener() {
        @Override//from   w  w w.ja v  a 2s .  c  o m
        public void onClick(DialogInterface dialog, int which) {
            int version = android.os.Build.VERSION.SDK_INT;
            Intent intent;
            if (version < 11) {
                intent = new Intent();
                intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings");
            } else {
                //3.0?
                //intent = new Intent( android.provider.Settings.ACTION_WIRELESS_SETTINGS);
                intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
            }
            if (id == 1) {
                activity.finish();
            }
            context.startActivity(intent);
        }
    });
    builder.setNegativeButton("?", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (id == 1) {
                activity.finish();
            }
        }
    });
    builder.create().show();
}

From source file:com.felkertech.n.ActivityUtils.java

public static void browsePlugins(final Activity activity) {
    //Same opening
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }// www  . j  av a  2s . co m
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);

    new MaterialDialog.Builder(activity).title(R.string.installed_plugins).items(plugin_names2)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog materialDialog, View view, int i,
                        CharSequence charSequence) {
                    // Load the given plugin with some additional info
                    ChannelDatabase cd = ChannelDatabase.getInstance(activity);
                    String s = cd.toString();
                    Intent intent = new Intent();
                    if (DEBUG) {
                        Log.d(TAG, "Try to start");
                    }
                    ResolveInfo plugin_info = plugins.get(i);
                    Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                            + plugin_info.activityInfo.name);

                    intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                            plugin_info.activityInfo.name);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EXTRA_READ_ALL);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ALL_CHANNELS, s);
                    activity.startActivity(intent);
                }
            }).positiveText(R.string.download_more_plugins)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse("http://play.google.com/store/search?q=cumulustv&c=apps"));
                    activity.startActivity(i);
                }
            }).show();
}

From source file:com.adguard.android.commons.BrowserUtils.java

public static void openYandexBlockingOptions(Context context) {
    Intent intent = new Intent();
    intent.setAction(YANDEX_CONTENT_BLOCKER_ACTION);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        context.startActivity(intent);//  w  w w .jav  a2s .c  o  m
        return;
    }

    // For samsung-type action in Yandex browser
    intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION);
    list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {

        ComponentName componentName = getYandexBrowser(context, SAMSUNG_CONTENT_BLOCKER_ACTION);
        if (componentName != null) {
            intent.setClassName(componentName.getPackageName(), componentName.getClassName());
        }

        context.startActivity(intent);
    }
}

From source file:com.felkertech.n.ActivityUtils.java

public static void openPluginPicker(final boolean newChannel, final JsonChannel queriedChannel,
        final Activity activity) {
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<String>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }/*from ww w.jav a 2s . com*/
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);
    if (DEBUG) {
        Log.d(TAG, "Load plugins " + plugin_names.toString());
    }
    if (plugin_names.size() == 1) {
        Intent intent = new Intent();
        if (newChannel) {
            if (DEBUG) {
                Log.d(TAG, "Try to start ");
            }
            ResolveInfo plugin_info = plugins.get(0);
            if (DEBUG) {
                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                        + plugin_info.activityInfo.name);
            }

            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
        } else {
            ResolveInfo plugin_info = plugins.get(0);
            Log.d(TAG,
                    plugin_info.activityInfo.applicationInfo.packageName + " " + plugin_info.activityInfo.name);
            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
        }
        activity.startActivity(intent);
    } else {
        new MaterialDialog.Builder(activity).items(plugin_names2).title(R.string.choose_an_app)
                .content(R.string.choose_default_app).itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog materialDialog, View view, int i,
                            CharSequence charSequence) {
                        Intent intent = new Intent();
                        if (newChannel) {
                            if (DEBUG) {
                                Log.d(TAG, "Try to start");
                            }
                            ResolveInfo plugin_info = plugins.get(i);
                            if (DEBUG) {
                                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                                        + plugin_info.activityInfo.name);
                            }

                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);

                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
                        } else {
                            ResolveInfo plugin_info = plugins.get(i);
                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
                        }
                        activity.startActivity(intent);
                    }
                }).show();
    }
}

From source file:ServiceConsumerActivity.java

void bind() {
    Intent intent = new Intent();
    intent.setClassName("com.allyourcode.p03_03_13", "com.allyourcode.p03_03_13.MyWeatherService");
    isBound = bindService(intent, connection, Context.BIND_AUTO_CREATE);
}