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.example.chu.googleplaylibrary.ui.BaseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LogHelper.d(TAG, "Activity onCreate");

    // Connect a media browser just to get the media session token. There are other ways
    // this can be done, for example by sharing the session token directly.
    mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class),
            mConnectionCallback, null);//from   ww  w.  j ava2  s  . c  o  m
}

From source file:com.commonsware.android.broadcast.fanout.MainActivity.java

private static void sendImplicitBroadcast(Context ctxt, Intent i) {
    PackageManager pm = ctxt.getPackageManager();
    List<ResolveInfo> matches = pm.queryBroadcastReceivers(i, 0);

    for (ResolveInfo resolveInfo : matches) {
        Intent explicit = new Intent(i);
        ComponentName cn = new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,
                resolveInfo.activityInfo.name);

        explicit.setComponent(cn);/*  w  w w  . ja  va 2s.  c o  m*/
        ctxt.sendBroadcast(explicit);
    }
}

From source file:com.doctoror.fuckoffmusicplayer.data.media.session.MediaSessionFactoryImpl.java

public MediaSessionFactoryImpl(@NonNull final Context context,
        @NonNull final Class<? extends Activity> sessionActivityClass,
        @NonNull final MediaSessionCompat.Callback mediaSessionCallback) {
    this.context = context;
    this.sessionActivityClass = sessionActivityClass;
    this.mediaSessionCallback = mediaSessionCallback;

    this.mediaButtonReceiver = new ComponentName(context, MediaButtonReceiver.class);
    this.mediaButtonIntent = PendingIntent.getBroadcast(context, 1,
            new Intent(context, MediaButtonReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.bayapps.android.robophish.ui.tv.TvVerticalGridActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tv_vertical_grid);

    mMediaId = getIntent().getStringExtra(TvBrowseActivity.SAVED_MEDIA_ID);
    mTitle = getIntent().getStringExtra(TvBrowseActivity.BROWSE_TITLE);

    getWindow().setBackgroundDrawableResource(R.drawable.bg);

    mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class),
            mConnectionCallback, null);//www.  j  a  va  2s  .c  o m
}

From source file:com.android.google.gcm.GCMBaseBroadcastReceiver.java

@Override
public final void onReceive(Context context, Intent intent) {
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(), getIntentServiceHandlerClass().getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);/*ww  w  .  j  av  a 2s  .c o m*/
}

From source file:com.bayapps.android.robophish.ui.tv.TvBrowseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LogHelper.d(TAG, "Activity onCreate");

    setContentView(R.layout.tv_activity_player);

    mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class),
            mConnectionCallback, null);/* www. j a  v a  2  s . c  o  m*/
}

From source file:com.bluros.music.widgets.SleepModeDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    context = getActivity().getBaseContext();
    Intent action = new Intent(MusicService.SLEEP_MODE_STOP_ACTION);
    ComponentName serviceName = new ComponentName(context, MusicService.class);
    action.setComponent(serviceName);/*from  w ww .  jav  a2s.  co  m*/
    pendingIntent = PendingIntent.getService(context, 4, action, 0);
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.sleep_mode_time_selector, null);
    int minutes = Integer.valueOf(getString(R.string.default_interval));
    final TextView tvPopUpTime = (TextView) view.findViewById(R.id.pop_up_time);
    tvPopUpTime.setText(String.valueOf(minutes));
    final SeekBar sBar = (SeekBar) view.findViewById(R.id.seekbar);
    sBar.setProgress(minutes - 1);
    sBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            tvPopUpTime.setText(String.valueOf(arg1 + 1));
        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }
    });
    builder.setTitle(R.string.select_quit_time);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int arg1) {
            long timeLeft = (sBar.getProgress() + 1) * mMill;
            alarmManager.set(AlarmManager.RTC_WAKEUP, timeLeft + System.currentTimeMillis(), pendingIntent);
            MusicPlayer.setSleepMode(true);
            Toast.makeText(context, String.format(getString(R.string.quit_warining), sBar.getProgress() + 1),
                    Toast.LENGTH_SHORT).show();
            dialog.dismiss();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int arg1) {
            dialog.dismiss();
        }
    });
    builder.setView(view);
    return builder.create();
}

From source file:com.hybris.mobile.lib.commerce.sync.CatalogSyncService.java

@Override
public void onCreate() {
    Log.i(TAG, "Service for the CatalogSyncAdapter starting");

    // The sync adapter is created as a singleton
    synchronized (mSingletonLock) {
        if (mSyncAdapter == null) {

            try {
                ComponentName componentName = new ComponentName(this, this.getClass());
                Bundle bundle = getPackageManager().getServiceInfo(componentName,
                        PackageManager.GET_META_DATA).metaData;

                String urlBackend = bundle
                        .getString(getApplicationContext().getString(R.string.sync_url_backend_metadata_name));
                String urlPathCatalogMetadataName = bundle.getString(
                        getApplicationContext().getString(R.string.sync_url_path_catalog_metadata_name));
                String urlPathCatalogIdMetadataName = bundle.getString(
                        getApplicationContext().getString(R.string.sync_url_path_catalog_id_metadata_name));
                String urlPathCatalogVersionIdMetadataName = bundle.getString(getApplicationContext()
                        .getString(R.string.sync_url_path_catalog_version_id_metadata_name));
                String idMainCategory = bundle
                        .getString(getApplicationContext().getString(R.string.sync_id_category_main));

                if (StringUtils.isBlank(urlBackend) || StringUtils.isBlank(urlBackend)
                        || StringUtils.isBlank(urlBackend) || StringUtils.isBlank(idMainCategory)) {
                    throw new IllegalArgumentException("You must provide the metadata "
                            + getApplicationContext().getString(R.string.sync_url_backend_metadata_name) + ", "
                            + getApplicationContext().getString(R.string.sync_url_path_catalog_metadata_name)
                            + ", "
                            + getApplicationContext().getString(R.string.sync_url_path_catalog_id_metadata_name)
                            + ", "
                            + getApplicationContext()
                                    .getString(R.string.sync_url_path_catalog_version_id_metadata_name)
                            + ", " + getApplicationContext().getString(R.string.sync_id_category_main) + " for "
                            + this.getClass());
                }/*  ww w .j  ava2s .c  o  m*/

                Configuration configuration = new Configuration();
                configuration.setBackendUrl(urlBackend);
                configuration.setCatalog(urlPathCatalogMetadataName);
                configuration.setCatalogId(urlPathCatalogIdMetadataName);
                configuration.setCatalogVersionId(urlPathCatalogVersionIdMetadataName);
                configuration.setCatalogIdMainCategory(idMainCategory);

                // Provider authority
                String provider_authority = getString(R.string.sync_default_authority);

                try {
                    componentName = new ComponentName(this, CatalogProvider.class);

                    // Authority name from the manifest file
                    String tmpAuthority = getPackageManager().getProviderInfo(componentName,
                            PackageManager.GET_META_DATA).authority;

                    if (StringUtils.isNotBlank(tmpAuthority)) {
                        provider_authority = tmpAuthority;
                    }

                } catch (PackageManager.NameNotFoundException e) {
                    Log.e(TAG, "Package name not found. Details:" + e.getLocalizedMessage());
                }

                configuration.setCatalogAuthority(provider_authority);

                // SSL Helper for the ssl factory and hostname verifier
                String sslHelperClassName = bundle
                        .getString(getApplicationContext().getString(R.string.sync_ssl_helper));
                SSLSocketFactory sslSocketFactory = null;
                HostnameVerifier hostnameVerifier = null;

                if (StringUtils.isNotBlank(sslHelperClassName)) {
                    SSLHelper sslHelper = null;
                    String errorMessage = null;
                    try {
                        Class sslFactory = Class.forName(sslHelperClassName);
                        Constructor<SSLHelper> constructor = sslFactory.getConstructor();
                        sslHelper = constructor.newInstance();

                        sslSocketFactory = sslHelper.getSSLSocketFactory();
                        hostnameVerifier = sslHelper.getHostnameVerifier();
                    } catch (ClassNotFoundException e) {
                        errorMessage = e.getLocalizedMessage();
                        Log.e(TAG, "ClassNotFoundException with SSLHelper. Details: " + errorMessage);
                    } catch (InvocationTargetException e) {
                        errorMessage = e.getLocalizedMessage();
                        Log.e(TAG, "InvocationTargetException with SSLHelper. Details: " + errorMessage);
                    } catch (NoSuchMethodException e) {
                        errorMessage = e.getLocalizedMessage();
                        Log.e(TAG, "NoSuchMethodException with SSLHelper. Details: " + errorMessage);
                    } catch (InstantiationException e) {
                        errorMessage = e.getLocalizedMessage();
                        Log.e(TAG, "InstantiationException with SSLHelper. Details: " + errorMessage);
                    } catch (IllegalAccessException e) {
                        errorMessage = e.getLocalizedMessage();
                        Log.e(TAG, "IllegalAccessException with SSLHelper. Details: " + errorMessage);
                    }

                    if (sslHelper == null) {
                        throw new IllegalArgumentException(
                                "Error instantiating SSLHelper. Details: " + errorMessage);
                    }
                }

                // Create the sync adapter
                mSyncAdapter = buildSyncAdapter(configuration, sslSocketFactory, hostnameVerifier);
            } catch (PackageManager.NameNotFoundException e) {
                Log.e(TAG, "Package name not found. Details:" + e.getLocalizedMessage());
                throw new IllegalArgumentException(
                        "Error getting the information from the metadata of " + this.getClass());
            }

        }
    }
}

From source file:org.deviceconnect.message.intent.impl.io.IntentHttpMessageWriter.java

@Override
public void write(final HttpMessage message) throws IOException, HttpException {
    mLogger.entering(getClass().getName(), "write");

    DConnectMessage dmessage = HttpMessageFactory.getMessageFactory().newDConnectMessage(message);
    Intent intent = IntentMessageFactory.getMessageFactory().newPackagedMessage(dmessage);

    // put intent optional extras
    Header host = message.getFirstHeader(HttpHeaders.HOST);
    if (host != null) {
        intent.setComponent(ComponentName.unflattenFromString(host.getValue()));
    }/*from  w w w  . j a  va2s.c om*/
    intent.putExtra(DConnectMessage.EXTRA_RECEIVER, new ComponentName(mContext, IntentResponseReceiver.class));

    // send broadcast
    mLogger.fine("send request broadcast: " + intent);
    mLogger.fine("send request extra: " + intent.getExtras());
    mContext.sendBroadcast(intent);

    mLogger.exiting(getClass().getName(), "write");
}

From source file:com.baidu.android.voicedemo.ActivityTouch.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sdk2_api);//from  w  w w  .  j  av a2s.  c om
    txtResult = (TextView) findViewById(R.id.txtResult);
    txtLog = (TextView) findViewById(R.id.txtLog);
    btn = (Button) findViewById(R.id.btn);
    setting = (Button) findViewById(R.id.setting);
    setting.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent("com.baidu.speech.asr.demo.setting");
            startActivity(intent);
        }
    });
    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
            new ComponentName(this, VoiceRecognitionService.class));
    speechRecognizer.setRecognitionListener(this);

    speechTips = View.inflate(this, R.layout.bd_asr_popup_speech, null);
    speechWave = speechTips.findViewById(R.id.wave);
    speechTips.setVisibility(View.GONE);
    addContentView(speechTips, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    btn.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                speechTips.setVisibility(View.VISIBLE);
                speechRecognizer.cancel();
                Intent intent = new Intent();
                bindParams(intent);
                intent.putExtra("vad", "touch");
                txtResult.setText("");
                txtLog.setText("");
                speechRecognizer.startListening(intent);
                return true;
            case MotionEvent.ACTION_UP:
                speechRecognizer.stopListening();
                speechTips.setVisibility(View.GONE);
                break;
            }
            return false;
        }
    });
}