Example usage for android.content ComponentName ComponentName

List of usage examples for android.content ComponentName ComponentName

Introduction

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

Prototype

private ComponentName(String pkg, Parcel in) 

Source Link

Usage

From source file:com.cyanogenmod.account.ui.SetupWizardActivity.java

private void disableSetupWizards(Intent intent) {
    final PackageManager pm = getPackageManager();
    final List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo info : resolveInfos) {
        if (GOOGLE_SETUPWIZARD_PACKAGE.equals(info.activityInfo.packageName)) {
            final ComponentName componentName = new ComponentName(info.activityInfo.packageName,
                    info.activityInfo.name);
            pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
        }/*from w ww  . jav  a 2  s .c  o m*/
    }
    pm.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:com.darshancomputing.alockblock.ALockBlockService.java

private void maximize() {
    mNotificationManager.cancelAll();// ww w. j a  v a2  s  . c o m
    stopForeground(true);

    Intent mainWindowIntent = new Intent(context, ALockBlockActivity.class);
    mainWindowPendingIntent = PendingIntent.getActivity(context, 0, mainWindowIntent, 0);

    ComponentName comp = new ComponentName(getPackageName(), ALockBlockService.class.getName());
    Intent reEnableIntent = new Intent().setComponent(comp).putExtra(EXTRA_ACTION, ACTION_REENABLE);
    PendingIntent reEnablePendingIntent = PendingIntent.getService(this, 0, reEnableIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder kgunb = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.kg_unlocked)
            .setLargeIcon(largeIconU).setContentTitle("Lock Screen Disabled").setContentText("A Lock Block")
            .setContentIntent(mainWindowPendingIntent).setShowWhen(false).setOngoing(true)
            .setPriority(NotificationCompat.PRIORITY_MAX);

    if (settings.getBoolean(SettingsActivity.KEY_REENABLE_FROM_NOTIFICATION, false))
        kgunb.addAction(R.drawable.ic_menu_login, "Re-enable", reEnablePendingIntent);

    startForeground(NOTIFICATION_KG_UNLOCKED, kgunb.build());
}

From source file:com.inloc.dr.StepService.java

/**
 * Show a notification while this service is running.
 *///from   w ww  .  j  a v a2s.c  om
private void showNotification() {
    CharSequence text = getText(R.string.app_name);
    Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    Intent pedometerIntent = new Intent();
    pedometerIntent.setComponent(new ComponentName(this, DeadReckoning.class));
    pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, pedometerIntent, 0);
    notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent);

    mNM.notify(R.string.app_name, notification);
}

From source file:com.android.tv.tuner.setup.TunerSetupActivity.java

/**
 * Returns a {@link Intent} to launch the tuner TV input service.
 *
 * @param context a {@link Context} instance
 *//*from ww w.ja  v a  2  s  .  com*/
public static Intent createSetupActivity(Context context) {
    String inputId = TvContract
            .buildInputId(new ComponentName(context.getPackageName(), TunerTvInputService.class.getName()));

    // Make an intent to launch the setup activity of TV tuner input.
    Intent intent = TvCommonUtils.createSetupIntent(new Intent(context, TunerSetupActivity.class), inputId);
    intent.putExtra(TvCommonConstants.EXTRA_INPUT_ID, inputId);
    Intent tvActivityIntent = new Intent();
    tvActivityIntent.setComponent(new ComponentName(context, TV_ACTIVITY_CLASS_NAME));
    intent.putExtra(TvCommonConstants.EXTRA_ACTIVITY_AFTER_COMPLETION, tvActivityIntent);
    return intent;
}

From source file:net.sf.asap.PlayerService.java

private void registerMediaButtonEventReceiver(String methodName) {
    Object audioManager = getSystemService(AUDIO_SERVICE);
    ComponentName eventReceiver = new ComponentName(getPackageName(), MediaButtonEventReceiver.class.getName());
    Util.invokeMethod(audioManager, methodName, eventReceiver);
}

From source file:androidx.media.session.MediaButtonReceiver.java

private static ComponentName getServiceComponentByAction(Context context, String action) {
    PackageManager pm = context.getPackageManager();
    Intent queryIntent = new Intent(action);
    queryIntent.setPackage(context.getPackageName());
    List<ResolveInfo> resolveInfos = pm.queryIntentServices(queryIntent, 0 /* flags */);
    if (resolveInfos.size() == 1) {
        ResolveInfo resolveInfo = resolveInfos.get(0);
        return new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
    } else if (resolveInfos.isEmpty()) {
        return null;
    } else {//from www. jav a 2  s.c o m
        throw new IllegalStateException(
                "Expected 1 service that handles " + action + ", found " + resolveInfos.size());
    }
}

From source file:Main.java

private static void startActivityForResult(final Activity activity, final Bundle extras, final String pkg,
        final String cls, final int requestCode, final Bundle options) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (extras != null)
        intent.putExtras(extras);/*from   w  w w.j  a va2  s. com*/
    intent.setComponent(new ComponentName(pkg, cls));
    startActivityForResult(intent, activity, requestCode, options);
}

From source file:com.android.tv.TvApplication.java

/**
 * Checks the input counts and enable/disable TvActivity. Also updates the input list in
 * {@link SetupUtils}.//from   w w w. j a v a2 s.  co m
 *
 * @param calledByTunerServiceChanged true if it is called when UsbTunerTvInputService
 *        is enabled or disabled.
 * @param tunerServiceEnabled it's available only when calledByTunerServiceChanged is true.
 * @param dontKillApp when TvActivity is enabled or disabled by this method, the app restarts
 *        by default. But, if dontKillApp is true, the app won't restart.
 */
public void handleInputCountChanged(boolean calledByTunerServiceChanged, boolean tunerServiceEnabled,
        boolean dontKillApp) {
    TvInputManager inputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
    boolean enable = (calledByTunerServiceChanged && tunerServiceEnabled)
            || Features.UNHIDE.isEnabled(TvApplication.this);
    if (!enable) {
        List<TvInputInfo> inputs = inputManager.getTvInputList();
        boolean skipTunerInputCheck = false;
        // Enable the TvActivity only if there is at least one tuner type input.
        if (!skipTunerInputCheck) {
            for (TvInputInfo input : inputs) {
                if (calledByTunerServiceChanged && !tunerServiceEnabled
                        && UsbTunerTvInputService.getInputId(this).equals(input.getId())) {
                    continue;
                }
                if (input.getType() == TvInputInfo.TYPE_TUNER) {
                    enable = true;
                    break;
                }
            }
        }
        if (DEBUG)
            Log.d(TAG, "Enable MainActivity: " + enable);
    }
    PackageManager packageManager = getPackageManager();
    ComponentName name = new ComponentName(this, TvActivity.class);
    int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (packageManager.getComponentEnabledSetting(name) != newState) {
        packageManager.setComponentEnabledSetting(name, newState,
                dontKillApp ? PackageManager.DONT_KILL_APP : 0);
    }
    SetupUtils.getInstance(TvApplication.this).onInputListUpdated(inputManager);
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) {
    RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);

    // Launch setinngs when clicking on the time in the widget only if not a lock screen widget
    Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
    if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
            -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) {
        Intent mIntent = new Intent(Intent.ACTION_MAIN);
        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings");
        mIntent.setComponent(component);
        widget.setOnClickPendingIntent(R.id.digital_appwidget,
                PendingIntent.getActivity(context, 0, mIntent, 0));
    }/*  w w  w.  j  a va  2s  .  c o  m*/

    //cg sai.pan begin
    refreshWifiStatus(context, widget);
    refreshBtStatus(context, widget);
    refreshAirplaneStatus(context, widget,
            Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0);
    mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
    refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
    //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0);
    requestLocation(context);
    //cg sai.pan end

    // SPRD for bug421127 add am/pm for widget
    WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
            R.id.the_clock);
    WidgetUtils.setClockSize(context, widget, ratio);

    // Set today's date format
    CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(),
            context.getString(R.string.abbrev_wday_month_day_no_year));
    widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat);
    widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat);

    appWidgetManager.updateAppWidget(appWidgetId, widget);
}

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

private String createDefaultExtensionList() {
    StringBuilder sb = new StringBuilder();

    for (Class cls : DEFAULT_EXTENSIONS) {
        if (sb.length() > 0) {
            sb.append(",");
        }/*from   w w w.  j av a 2 s  .  c  o m*/
        sb.append(new ComponentName(mApplicationContext, cls).flattenToString());
    }

    return sb.toString();
}