List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:com.gecq.musicwave.player.NotificationHelper.java
/** * @param which Which {@link PendingIntent} to return * @return A {@link PendingIntent} ready to control playback *//*from www.j av a 2 s. co m*/ private final PendingIntent retreivePlaybackActions(final int which) { Intent action; PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(mService, PlayerService.class); switch (which) { case 1: // Play and pause action = new Intent(PlayerService.TOGGLEPAUSE_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 1, action, 0); return pendingIntent; case 2: // Skip tracks action = new Intent(PlayerService.NEXT_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 2, action, 0); return pendingIntent; case 3: // Previous tracks action = new Intent(PlayerService.PREVIOUS_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 3, action, 0); return pendingIntent; case 4: // Stop and collapse the notification action = new Intent(PlayerService.STOP_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 4, action, 0); return pendingIntent; default: break; } return null; }
From source file:com.kaytat.simpleprotocolplayer.MainActivity.java
public void onClick(View target) { // Send the correct intent to the MusicService, according to the button that was clicked if (target == mPlayButton) { // Get the IP address and port and put it in the intent Intent i = new Intent(MusicService.ACTION_PLAY); i.setComponent(serviceComponent); String ipAddr = mIPAddrText.getText().toString(); String portStr = mAudioPortText.getText().toString(); if (ipAddr == null || ipAddr.equals("")) { Toast.makeText(getApplicationContext(), "Invalid address", Toast.LENGTH_SHORT).show(); return; }//from www. jav a 2 s . c o m if (portStr == null || portStr.equals("")) { Toast.makeText(getApplicationContext(), "Invalid port", Toast.LENGTH_SHORT).show(); return; } i.putExtra(MusicService.DATA_IP_ADDRESS, ipAddr); int audioPort; try { audioPort = Integer.parseInt(portStr); } catch (NumberFormatException nfe) { Log.e(TAG, "Invalid port:" + nfe); Toast.makeText(getApplicationContext(), "Invalid port", Toast.LENGTH_SHORT).show(); return; } hideKb(); i.putExtra(MusicService.DATA_AUDIO_PORT, audioPort); // Extract sample rate Spinner sampleRateSpinner = (Spinner) findViewById(R.id.spinnerSampleRate); try { String rateStr = String.valueOf(sampleRateSpinner.getSelectedItem()); String[] rateSplit = rateStr.split(" "); if (rateSplit.length != 0) { // mSampleRate = Integer.parseInt(rateSplit[0]); // FIXME broken on Android TV? mSampleRate = 48000; Log.i(TAG, "rate:" + mSampleRate); i.putExtra(MusicService.DATA_SAMPLE_RATE, mSampleRate); } } catch (Exception e) { // Ignore parsing errors. The intent will have a default } // Extract stereo/mono setting Spinner stereoSpinner = (Spinner) findViewById(R.id.stereo); try { String stereoSettingString = String.valueOf(stereoSpinner.getSelectedItem()); String[] stereoSplit = stereoSettingString.split(" "); String stereoKey = getResources().getString(R.string.stereoKey); if (stereoSplit.length != 0) { mStereo = stereoSplit[0].contains(stereoKey); Log.i(TAG, "stereo:" + mStereo); i.putExtra(MusicService.DATA_STEREO, mStereo); } } catch (Exception e) { // Ignore parsing errors. The intent will have a default } // Get the latest buffer entry /* FIXME broken on Android TV? EditText e = (EditText)findViewById(R.id.editTextBufferSize); String bufferMsString = e.getText().toString(); if (bufferMsString == null || bufferMsString.isEmpty()) { mBufferMs = 0; } else { mBufferMs = Integer.parseInt(bufferMsString); } */ mBufferMs = 500; i.putExtra(MusicService.DATA_BUFFER_MS, mBufferMs); // Save current settings savePrefs(); startService(i); } else if (target == mStopButton) { Intent i = new Intent(MusicService.ACTION_STOP); i.setComponent(serviceComponent); hideKb(); startService(i); //boolean ok = stopService(i); //Log.i(TAG, "stopService: " + Boolean.valueOf(ok).toString()); } }
From source file:com.uphyca.testing.support.v4.FragmentUnitTestCase.java
private void attachActivity(Object lastNonConfigurationInstance) throws Exception { if (mActivityAttached) { return;/*from w w w .j a va 2 s .com*/ } IBinder token = null; if (mApplication == null) { setApplication(Robolectric.application); } if (mActivity == null) { setActivity(new MockFragmentActivity()); } ComponentName cn = new ComponentName(mActivity.getClass().getPackage().getName(), mActivity.getClass().getName()); Intent intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(cn); ActivityInfo info = new ActivityInfo(); CharSequence title = mActivity.getClass().getName(); mMockParent = new MockParent(); String id = null; ActivityTrojanHorse.callAttach(getInstrumentation(), mActivity, mFragmentContext, token, mApplication, intent, info, title, mMockParent, id, lastNonConfigurationInstance); mActivityAttached = true; }
From source file:nuclei.ui.share.PackageTargetManager.java
/** * Create an intent with package specific modifications * * @param authority The file authority provider to be used for sharing files * @param permissionRequestCode Some packages may require we put files on external storage, * this is the permission request code that will be used to request that permission *///from w w w. ja v a 2 s. co m public Intent onCreateIntent(Activity activity, String authority, ResolveInfo info, int permissionRequestCode) { int maxLen = getMaxLen(info.activityInfo.packageName); String text = mText; if (maxLen != Integer.MAX_VALUE) text = trim(text, mUrl, maxLen); else if (mText != null && mUrl != null) text += '\n' + mUrl; Intent intent = new Intent( TextUtils.isEmpty(mEmail) && TextUtils.isEmpty(mSms) ? Intent.ACTION_SEND : Intent.ACTION_SENDTO); intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name)); intent.setPackage(info.activityInfo.packageName); onSetDefault(activity, info.activityInfo.packageName, authority, intent, text); switch (info.activityInfo.packageName) { case FACEBOOK: intent = onFacebook(activity, intent); break; case WECHAT: intent = onExternalStorage(activity, info.activityInfo.packageName, authority, intent, permissionRequestCode, true); break; case LINE: case TELEGRAM: case WHATSAP: intent = onExternalStorage(activity, info.activityInfo.packageName, authority, intent, permissionRequestCode, false); break; case INSTAGRAM: if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) intent = onExternalStorage(activity, info.activityInfo.packageName, authority, intent, permissionRequestCode, false); break; } return intent; }
From source file:org.cyanogenmod.theme.chooser.ChooserBrowseFragment.java
private void launchThemeStore() { Intent intent = new Intent(); intent.setComponent(new ComponentName(THEME_STORE_PACKAGE_NAME, THEME_STORE_ACTIVITY)); getActivity().startActivity(intent); }
From source file:org.onepf.oms.appstore.SamsungAppsBillingService.java
@Override public void launchPurchaseFlow(Activity activity, String sku, String itemType, int requestCode, OnIabPurchaseFinishedListener listener, String extraData) { String itemGroupId = getItemGroupId(sku); String itemId = getItemId(sku); Bundle bundle = new Bundle(); bundle.putString(KEY_NAME_THIRD_PARTY_NAME, activity.getPackageName()); bundle.putString(KEY_NAME_ITEM_GROUP_ID, itemGroupId); bundle.putString(KEY_NAME_ITEM_ID, itemId); if (isDebugLog()) Log.d(TAG, "launchPurchase: itemGroupId = " + itemGroupId + ", itemId = " + itemId); ComponentName cmpName = new ComponentName(SamsungApps.IAP_PACKAGE_NAME, PAYMENT_ACTIVITY_NAME); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(cmpName); intent.putExtras(bundle);//from w w w . java2s . co m mRequestCode = requestCode; mPurchaseListener = listener; purchasingItemType = itemType; mItemGroupId = itemGroupId; mExtraData = extraData; if (isDebugLog()) Log.d(TAG, "Request code: " + requestCode); activity.startActivityForResult(intent, requestCode); }
From source file:com.rareventure.gps2.GTG.java
public static Intent getGTGAppStart(Context context, String appPackage) { Intent i = new Intent(); i.setComponent(new ComponentName(appPackage, START_ACTIVITY_CLASS.getName())); //check if premium is installed if (Util.isCallable(context, i)) { return i; }/*from w ww. jav a2 s .c om*/ return null; }
From source file:com.googlecode.android_scripting.facade.BluetoothFacade.java
@Rpc(description = "Connect to a device over Bluetooth. Blocks until the connection is established or fails.", returns = "True if the connection was established successfully.") public String bluetoothConnect( @RpcParameter(name = "uuid", description = "The UUID passed here must match the UUID used by the server device.") @RpcDefault(DEFAULT_UUID) String uuid, @RpcParameter(name = "address", description = "The user will be presented with a list of discovered devices to choose from if an address is not provided.") @RpcOptional String address) throws IOException { if (address == null) { Intent deviceChooserIntent = new Intent(); deviceChooserIntent.setComponent(Constants.BLUETOOTH_DEVICE_LIST_COMPONENT_NAME); Intent result = mAndroidFacade.startActivityForResult(deviceChooserIntent); if (result != null && result.hasExtra(Constants.EXTRA_DEVICE_ADDRESS)) { address = result.getStringExtra(Constants.EXTRA_DEVICE_ADDRESS); } else {/*ww w.j a va 2 s. c om*/ return null; } } BluetoothDevice mDevice; BluetoothSocket mSocket; BluetoothConnection conn; mDevice = mBluetoothAdapter.getRemoteDevice(address); mSocket = mDevice.createRfcommSocketToServiceRecord(UUID.fromString(uuid)); // Always cancel discovery because it will slow down a connection. mBluetoothAdapter.cancelDiscovery(); mSocket.connect(); conn = new BluetoothConnection(mSocket); return addConnection(conn); }
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);//w w w . jav a2 s.com 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); } }