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:de.ub0r.android.callmeter.ui.prefs.PreferencesPlain.java

/** Load widget list. */
@SuppressWarnings("deprecation")
private void loadWidgets() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    Preference p = findPreference("container");
    if (p != null && p instanceof PreferenceScreen) {
        PreferenceScreen ps = (PreferenceScreen) p;
        ps.removeAll();// w w  w  .ja  v a  2  s .  c  om
        int[] ids = AppWidgetManager.getInstance(this)
                .getAppWidgetIds(new ComponentName(this, StatsAppWidgetProvider.class));
        boolean added = false;
        if (ids != null && ids.length > 0) {
            for (int id : ids) {
                if (prefs.getLong(StatsAppWidgetProvider.WIDGET_PLANID + id, -1) <= 0) {
                    continue;
                }
                added = true;
                p = new Preference(this);
                p.setTitle(getString(R.string.widget_) + " #" + id);
                final int fid = id;
                p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(final Preference preference) {
                        Intent i = new Intent(PreferencesPlain.this, StatsAppWidgetConfigure.class);
                        i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, fid);
                        PreferencesPlain.this.startActivity(i);
                        return true;
                    }
                });
                ps.addPreference(p);
            }
        }
        ids = AppWidgetManager.getInstance(this)
                .getAppWidgetIds(new ComponentName(this, LogsAppWidgetProvider.class));
        if (ids != null && ids.length > 0) {
            for (int id : ids) {
                if (prefs.getLong(LogsAppWidgetProvider.WIDGET_PLANID + id, -1) <= 0) {
                    continue;
                }
                added = true;
                p = new Preference(this);
                p.setTitle(getString(R.string.widget_) + " #" + id);
                final int fid = id;
                p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(final Preference preference) {
                        Intent i = new Intent(PreferencesPlain.this, LogsAppWidgetConfigure.class);
                        i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, fid);
                        PreferencesPlain.this.startActivity(i);
                        return true;
                    }
                });
                ps.addPreference(p);
            }
        }
        if (!added) {
            p = new Preference(this);
            p.setTitle(R.string.widgets_no_widgets_);
            p.setSummary(R.string.widgets_no_widgets_hint);
            ps.addPreference(p);
        }
    }
}

From source file:co.shunya.gita.player.MusicService.java

@Override
public void onCreate() {
    //        Log.i(TAG, "debug: Creating service");

    // Create the Wifi lock (this does not acquire the lock, this just creates it)
    mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock");

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    // create the Audio Focus Helper, if the Audio Focus feature is available (SDK 8 or above)
    if (android.os.Build.VERSION.SDK_INT >= 8)
        mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this);
    else// ww w .  j  a  v a2 s.  c  o m
        mAudioFocus = AudioFocus.Focused; // no focus feature, so we always "have" audio focus

    mDummyAlbumArt = BitmapFactory.decodeResource(getResources(), R.drawable.krishnanarayana);

    mMediaButtonReceiverComponent = new ComponentName(this, MusicIntentReceiver.class);

    BusProvider.getMediaEventBus().register(this);

}

From source file:com.google.android.gms.location.sample.geofencing.GeofenceTransitionsIntentService.java

private void activateScanReceiver() {
    System.out.println("? ? ?");
    ComponentName receiver = new ComponentName(this, WiFiScanReceiver.class);

    PackageManager pm = this.getPackageManager();

    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:org.wso2.emm.agent.services.operation.OperationProcessor.java

private boolean isDeviceAdminActive() {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context
            .getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName cdmDeviceAdmin = new ComponentName(context, AgentDeviceAdminReceiver.class);
    return devicePolicyManager.isAdminActive(cdmDeviceAdmin);
}

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

private static ComponentName getSamsungBrowser(Context context) {
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> installedPackages = context.getPackageManager().queryIntentActivities(mainIntent, 0);

    ArrayList<ActivityInfo> samsungActivities = new ArrayList<>();
    for (ResolveInfo installedPackage : installedPackages) {
        if (installedPackage.activityInfo.packageName.startsWith(SAMSUNG_BROWSER_PACKAGE)) {
            samsungActivities.add(installedPackage.activityInfo);
        }//from w w  w  .ja v a2  s. com
    }

    if (CollectionUtils.isNotEmpty(samsungActivities)) {
        Collections.sort(samsungActivities, new Comparator<ActivityInfo>() {
            @Override
            public int compare(ActivityInfo lhs, ActivityInfo rhs) {
                return lhs.packageName.compareTo(rhs.packageName);
            }
        });

        ActivityInfo activityInfo = samsungActivities.get(0);
        return new ComponentName(activityInfo.packageName, activityInfo.name);

    }

    return null;
}

From source file:com.adityarathi.muo.services.AudioPlaybackService.java

/**
 * Prepares the MediaPlayer objects for first use 
 * and starts the service. The workflow of the entire 
 * service starts here.// ww  w. j  av  a2  s .co  m
 * 
 * @param intent Calling intent.
 * @param flags Service flags.
 * @param startId Service start ID.
 */
@SuppressLint("NewApi")
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    //Context.
    mContext = getApplicationContext();
    mService = this;
    mHandler = new Handler();

    mApp = (Common) getApplicationContext();
    mApp.setService((AudioPlaybackService) this);
    mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);

    //Initialize Google Analytics.
    initGoogleAnalytics();

    //Initialize the MediaPlayer objects.
    initMediaPlayers();

    //Time to play nice with other music players (and audio apps) and request audio focus.
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioManagerHelper = new AudioManagerHelper();

    // Request audio focus for playback
    mAudioManagerHelper.setHasAudioFocus(requestAudioFocus());

    //Grab the crossfade duration for this session.
    mCrossfadeDuration = mApp.getCrossfadeDuration();

    //Initialize audio effects (equalizer, virtualizer, bass boost) for this session.
    initAudioFX();

    mMediaButtonReceiverComponent = new ComponentName(this.getPackageName(),
            HeadsetButtonsReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);

    //if (mApp.getSharedPreferences().getBoolean(Common.SHOW_LOCKSCREEN_CONTROLS, true)==true) {
    //   initRemoteControlClient();
    //}

    mApp.getPlaybackKickstarter().setBuildCursorListener(buildCursorListener);

    //The service has been successfully started.
    setPrepareServiceListener(mApp.getPlaybackKickstarter());
    getPrepareServiceListener().onServiceRunning(this);

    return START_STICKY;
}

From source file:com.scoreflex.ScoreflexView.java

/**
 * The constructor of the view.//  w w w.  ja  va  2s. c o m
 * @param activity The activity holding the view.
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public ScoreflexView(Activity activity, AttributeSet attrs, int defStyle) {
    super(activity, attrs, defStyle);

    // Keep a reference on the activity
    mParentActivity = activity;

    // Default layout params
    if (null == getLayoutParams()) {
        setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Scoreflex.getDensityIndependantPixel(R.dimen.scoreflex_panel_height)));
    }

    // Set our background color
    setBackgroundColor(getContext().getResources().getColor(R.color.scoreflex_background_color));

    // Create the top bar
    View topBar = new View(getContext());
    topBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height), Gravity.TOP));
    topBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.scoreflex_gradient_background));
    addView(topBar);

    // Create the retry button
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mErrorLayout = (ViewGroup) inflater.inflate(R.layout.scoreflex_error_layout, null);
    if (mErrorLayout != null) {

        // Configure refresh button
        Button refreshButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_retry_button);
        if (null != refreshButton) {
            refreshButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (null == Scoreflex.getPlayerId()) {
                        setUserInterfaceState(new LoadingState());
                        loadUrlAfterLoggedIn(mInitialResource, mInitialRequestParams);
                    } else if (null == mWebView.getUrl()) {
                        setResource(mInitialResource);
                    } else {
                        mWebView.reload();
                    }
                }
            });
        }

        // Configure cancel button
        Button cancelButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_cancel_button);
        if (null != cancelButton) {
            cancelButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    close();
                }
            });
        }

        // Get hold of the message view
        mMessageView = (TextView) mErrorLayout.findViewById(R.id.scoreflex_error_message_view);
        addView(mErrorLayout);

    }

    // Create the close button
    mCloseButton = new ImageButton(getContext());
    Drawable closeButtonDrawable = getResources().getDrawable(R.drawable.scoreflex_close_button);
    int closeButtonMargin = (int) ((getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height)
            - closeButtonDrawable.getIntrinsicHeight()) / 2.0f);
    FrameLayout.LayoutParams closeButtonLayoutParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.TOP | Gravity.RIGHT);
    closeButtonLayoutParams.setMargins(0, closeButtonMargin, closeButtonMargin, 0);
    mCloseButton.setLayoutParams(closeButtonLayoutParams);
    mCloseButton.setImageDrawable(closeButtonDrawable);
    mCloseButton.setBackgroundDrawable(null);
    mCloseButton.setPadding(0, 0, 0, 0);
    mCloseButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            close();
        }
    });
    addView(mCloseButton);

    // Create the web view
    mWebView = new WebView(mParentActivity);
    mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    // mWebView.setBackgroundColor(Color.RED);
    mWebView.setWebViewClient(new ScoreflexWebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d("Scoreflex", "javascript Error: "
                    + String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId()));
            return true;
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            // mtbActivity.mUploadMessage = uploadMsg;
            mUploadMessage = uploadMsg;

            String fileName = "picture.jpg";
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, fileName);
            // mOutputFileUri = mParentActivity.getContentResolver().insert(
            // MediaStore.Images.Media.DATA, values);
            final List<Intent> cameraIntents = new ArrayList<Intent>();
            final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            final PackageManager packageManager = mParentActivity.getPackageManager();
            final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
            for (ResolveInfo res : listCam) {
                final String packageName = res.activityInfo.packageName;
                final Intent intent = new Intent(captureIntent);
                intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
                intent.setPackage(packageName);
                cameraIntents.add(intent);
            }

            // Filesystem.
            final Intent galleryIntent = new Intent();
            galleryIntent.setType("image/*");
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

            // Chooser of filesystem options.
            final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source please");

            // Add the camera options.
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

            mParentActivity.startActivityForResult(chooserIntent, Scoreflex.FILECHOOSER_RESULTCODE);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
            openFileChooser(uploadMsg);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            openFileChooser(uploadMsg);
        }
    });
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setDatabasePath(
            getContext().getFilesDir().getPath() + "/data/" + getContext().getPackageName() + "/databases/");
    addView(mWebView);

    TypedArray a = mParentActivity.obtainStyledAttributes(attrs, R.styleable.ScoreflexView, defStyle, 0);
    String resource = a.getString(R.styleable.ScoreflexView_resource);
    if (null != resource)
        setResource(resource);

    a.recycle();

    // Create the animated spinner

    mProgressBar = (ProgressBar) ((LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.scoreflex_progress_bar, null);
    mProgressBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
    addView(mProgressBar);
    LocalBroadcastManager.getInstance(activity).registerReceiver(mLoginReceiver,
            new IntentFilter(Scoreflex.INTENT_USER_LOGED_IN));
    setUserInterfaceState(new InitialState());
}

From source file:io.radio.streamer.MainActivity.java

@TargetApi(14)
private void initializeRemoteControls() {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ComponentName eventReceiver = new ComponentName(getPackageName(),
                RemoteControlReceiver.class.getName());

        audioManager.registerMediaButtonEventReceiver(eventReceiver);
        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        mediaButtonIntent.setComponent(eventReceiver);
        PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
                mediaButtonIntent, 0);//from w  w w .j  a  va 2s. c  o  m
        remoteControlClient = new RemoteControlClient(mediaPendingIntent);
        remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                | RemoteControlClient.FLAG_KEY_MEDIA_STOP | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE);
        audioManager.registerRemoteControlClient(remoteControlClient);
    }
}

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

private static ComponentName getYandexBrowser(Context context, String action) {
    Intent mainIntent = new Intent();
    mainIntent.setAction(action);//from  w ww .  ja  va  2  s .c om

    for (String packageName : yandexBrowserPackageList) {
        mainIntent.setPackage(packageName);

        List<ResolveInfo> installedPackages = context.getPackageManager().queryIntentActivities(mainIntent,
                PackageManager.MATCH_DEFAULT_ONLY);

        if (!installedPackages.isEmpty()) {
            ResolveInfo resolveInfo = installedPackages.get(0);

            return new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
        }
    }

    return null;
}

From source file:com.dudu.aios.ui.activity.MainRecordActivity.java

private void initData() {
    log_init = LoggerFactory.getLogger("init.start");
    log_web = LoggerFactory.getLogger("workFlow.webSocket");

    log_init.debug("MainActivity onCreate?...");

    setWeatherAlarm();/* w w w  .j  a  v  a2s  .c  om*/

    registerTFlashCardReceiver();

    registerScreenReceiver();

    // ???
    mPolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

    // AdminReceiver  DeviceAdminReceiver
    componentName = new ComponentName(this, AdminReceiver.class);

}