List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:com.tasomaniac.openwith.resolver.ResolverActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { final Intent intent = makeMyIntent(); setTheme(R.style.BottomSheet_Light); super.onCreate(savedInstanceState); mPm = getPackageManager();/*from w ww .ja v a2s.c o m*/ mRequestedUri = intent.getData(); boolean isCallerPackagePreferred = false; final String callerPackage = getCallerPackage(); ResolveInfo lastChosen = null; final Cursor query = getContentResolver().query(withHost(intent.getData().getHost()), null, null, null, null); if (query != null && query.moveToFirst()) { final boolean isPreferred = query.getInt(query.getColumnIndex(PREFERRED)) == 1; final boolean isLastChosen = query.getInt(query.getColumnIndex(LAST_CHOSEN)) == 1; if (isPreferred || isLastChosen) { final String componentString = query.getString(query.getColumnIndex(COMPONENT)); final Intent lastChosenIntent = new Intent(); final ComponentName lastChosenComponent = ComponentName.unflattenFromString(componentString); lastChosenIntent.setComponent(lastChosenComponent); ResolveInfo ri = mPm.resolveActivity(lastChosenIntent, PackageManager.MATCH_DEFAULT_ONLY); if (isPreferred && ri != null) { isCallerPackagePreferred = ri.activityInfo.packageName.equals(callerPackage); if (!isCallerPackagePreferred) { intent.setComponent(lastChosenComponent); startActivity(intent); finish(); return; } } lastChosen = ri; } query.close(); } mPackageMonitor.register(this, getMainLooper(), false); mRegistered = true; final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); mIconDpi = am.getLauncherLargeIconDensity(); mAdapter = new ResolveListAdapter(this, getHistory(), intent, callerPackage, lastChosen, true); mAdapter.setPriorityItems(intent.getStringArrayExtra(EXTRA_PRIORITY_PACKAGES)); mAlwaysUseOption = true; final int layoutId; final boolean useHeader; if (mAdapter.hasFilteredItem()) { layoutId = R.layout.resolver_list_with_default; mAlwaysUseOption = false; useHeader = true; } else { useHeader = false; layoutId = R.layout.resolver_list; } //If the caller is already the preferred, don't change it. if (isCallerPackagePreferred) { mAlwaysUseOption = false; } int count = mAdapter.mList.size(); if (count > 1) { setContentView(layoutId); mListView = (RecyclerView) findViewById(R.id.resolver_list); mListView.setAdapter(mAdapter); mAdapter.setOnItemClickedListener(this); mAdapter.setOnItemLongClickedListener(this); if (mAlwaysUseOption) { mAdapter.setSelectable(true); } if (useHeader) { mAdapter.setHeader(new ResolveListAdapter.Header()); } } else if (count == 1) { startActivity(mAdapter.intentForPosition(0, false)); mPackageMonitor.unregister(); mRegistered = false; finish(); return; } else { setContentView(R.layout.resolver_list); final TextView empty = (TextView) findViewById(R.id.empty); empty.setVisibility(View.VISIBLE); mListView = (RecyclerView) findViewById(R.id.resolver_list); mListView.setVisibility(View.GONE); } mListView.setLayoutManager(new LinearLayoutManager(this)); // Prevent the Resolver window from becoming the top fullscreen window and thus from taking // control of the system bars. getWindow().clearFlags(FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR); final ResolverDrawerLayout rdl = (ResolverDrawerLayout) findViewById(R.id.contentPanel); if (rdl != null) { rdl.setOnDismissedListener(new ResolverDrawerLayout.OnDismissedListener() { @Override public void onDismissed() { finish(); } }); } CharSequence title = getTitleForAction(); if (!TextUtils.isEmpty(title)) { final TextView titleView = (TextView) findViewById(R.id.title); if (titleView != null) { titleView.setText(title); } setTitle(title); } final ImageView iconView = (ImageView) findViewById(R.id.icon); final DisplayResolveInfo iconInfo = mAdapter.getFilteredItem(); if (iconView != null && iconInfo != null) { new LoadIconIntoViewTask(iconView).execute(iconInfo); } if (mAlwaysUseOption || mAdapter.hasFilteredItem()) { final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar); if (buttonLayout != null) { buttonLayout.setVisibility(View.VISIBLE); mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always); mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once); } else { mAlwaysUseOption = false; } } if (mAdapter.hasFilteredItem()) { mAlwaysButton.setEnabled(true); mOnceButton.setEnabled(true); } }
From source file:org.chromium.chrome.browser.download.DownloadNotificationService.java
/** * Helper method to build an download action Intent from the provided information. * @param action Download action to perform. * @param notificationId ID of the notification. * @param downloadGuid GUID of the download. * @param fileName Name of the download file. * @param isOfflinePage Whether the intent is for offline page download. *///from w w w .j a va 2 s . co m private Intent buildActionIntent(String action, int notificationId, String downloadGuid, String fileName, boolean isOfflinePage) { ComponentName component = new ComponentName(mContext.getPackageName(), DownloadBroadcastReceiver.class.getName()); Intent intent = new Intent(action); intent.setComponent(component); intent.putExtra(EXTRA_DOWNLOAD_NOTIFICATION_ID, notificationId); intent.putExtra(EXTRA_DOWNLOAD_GUID, downloadGuid); intent.putExtra(EXTRA_DOWNLOAD_FILE_NAME, fileName); intent.putExtra(EXTRA_DOWNLOAD_IS_OFFLINE_PAGE, isOfflinePage); return intent; }
From source file:org.deviceconnect.android.manager.DConnectMessageService.java
/** * ????.// w w w .ja va 2s .c o m * @param plugin ??? * @param serviceId ID * @param event ?? */ private void createClientOfDevicePlugin(final DevicePlugin plugin, final String serviceId, final Intent event) { Intent intent = new Intent(IntentDConnectMessage.ACTION_GET); intent.setComponent(plugin.getComponentName()); intent.putExtra(DConnectMessage.EXTRA_PROFILE, ServiceDiscoveryProfileConstants.PROFILE_NAME); intent.putExtra(DConnectMessage.EXTRA_SERVICE_ID, serviceId); DiscoveryDeviceRequest request = new DiscoveryDeviceRequest(); request.setContext(this); request.setLocalOAuth(mLocalOAuth); request.setUseAccessToken(true); request.setRequireOrigin(true); request.setDestination(plugin); request.setRequest(intent); request.setEvent(event); request.setDevicePluginManager(mPluginMgr); addRequest(request); }
From source file:com.geryon.ocraa.MusicService.java
/** * Starts playing the next song. If manualUrl is null, the next song will be randomly selected * from our Media Retriever (that is, it will be a random song in the user's device). If * manualUrl is non-null, then it specifies the URL or path to the song that will be played * next./*www .j a v a 2 s . c o m*/ */ void playNextSong(int pos) { position = pos; mState = State.Stopped; progressBarHandler.removeCallbacks(mUpdateTimeTask); MusicRetriever.Item playingItem = null; relaxResources(false); // release everything except MediaPlayer try { if ((position == -1) || (repeat == false && shuffle == true)) { Random mRandom = new Random(); int random = mRandom.nextInt(mRetriever.ItemSize()); playingItem = mRetriever.getItem(random); Log.d("Randomize:", String.valueOf(random)); position = random; Log.d("Position:", String.valueOf(random)); if (playingItem == null) { Toast.makeText(this, "No available music to play. Place some music on your external storage " + "device (e.g. your SD card) and try again.", Toast.LENGTH_LONG).show(); processStopRequest(true); // stop everything! return; } createMediaPlayerIfNeeded(); mPlayer.setDataSource(playingItem.getURI().toString()); } else if (position != -1) { if (repeat == false) { if (shuffle == false) { if (position == mRetriever.ItemSize() - 1) { position = 0; } else { position++; } } } playingItem = mRetriever.getItem(position); createMediaPlayerIfNeeded(); mPlayer.setDataSource(playingItem.getURI().toString()); } mSongTitle = playingItem.getTitle(); mState = State.Preparing; setUpAsForeground(mSongTitle + " (loading)"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); // Use the remote control APIs (if available) to set the playback state if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast( this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClientCompat.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP); // Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, playingItem.getArtist()) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, playingItem.getAlbum()) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, playingItem.getTitle()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, playingItem.getDuration()) // TODO: fetch real item artwork .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, mDummyAlbumArt) .apply(); // starts preparing the media player in the background. When it's done, it will call // our OnPreparedListener (that is, the onPrepared() method on this class, since we set // the listener to 'this'). // // Until the media player is prepared, we *cannot* call start() on it! mPlayer.prepareAsync(); updateProgressBar(); // If we are streaming from the internet, we want to hold a Wifi lock, which prevents // the Wifi radio from going to sleep while the song is playing. If, on the other hand, // we are *not* streaming, we want to release the lock if we were holding it before. if (mIsStreaming) mWifiLock.acquire(); else if (mWifiLock.isHeld()) mWifiLock.release(); } catch (IOException ex) { // Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); // ex.printStackTrace(); } }
From source file:com.abc.driver.PersonalActivity.java
private void doCrop() { Log.d(TAG, "doCrop()"); final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>(); Intent intent = new Intent("com.android.camera.action.CROP"); intent.setType("image/*"); List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(intent, 0); int size = list.size(); if (size == 0) { Log.d(TAG, " Crop activity is not found. List size is zero."); Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null); app.setPortaritBitmap(Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IMAGE_WIDTH, CellSiteConstants.IMAGE_HEIGHT, false)); mUserPortraitIv.setImageBitmap(app.getPortaritBitmap()); isPortraitChanged = true;//w ww. java 2 s . co m Log.d(TAG, "set bitmap"); return; } else { Log.d(TAG, "found the crop activity."); intent.setData(imageUri); intent.putExtra("outputX", CellSiteConstants.IMAGE_WIDTH); intent.putExtra("outputY", CellSiteConstants.IMAGE_HEIGHT); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("scale", true); intent.putExtra("return-data", true); if (size == 1) { Log.d(TAG, "Just one as choose it as crop activity."); Intent i = new Intent(intent); ResolveInfo res = list.get(0); i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); startActivityForResult(i, CellSiteConstants.CROP_PICTURE); } else { Log.d(TAG, "More that one activity for crop is found . will chooose one"); for (ResolveInfo res : list) { final CropOption co = new CropOption(); co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo); co.icon = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo); co.appIntent = new Intent(intent); co.appIntent .setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); cropOptions.add(co); } CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose Crop App"); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { startActivityForResult(cropOptions.get(item).appIntent, CellSiteConstants.CROP_PICTURE); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { // @Override public void onCancel(DialogInterface dialog) { if (imageUri != null) { getContentResolver().delete(imageUri, null, null); imageUri = null; isPortraitChanged = false; } } }); AlertDialog alert = builder.create(); alert.show(); } } }
From source file:com.playtech.ezpush.gcm.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // We need an Editor object to make preference changes. // All objects are from android.context.Context SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0); String token = intent.getExtras().getString("registration_id"); if (token != null && !token.isEmpty() && !token.equals("")) { SharedPreferences.Editor editor = settings.edit(); editor.putString("PUSH_TOKEN", token); editor.commit();//from w w w . j a va 2 s . c om } // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); }
From source file:co.shunya.gita.player.MusicService.java
/** * Starts playing the next song. If manualUrl is null, the next song will be randomly selected * from our Media Retriever (that is, it will be a random song in the user's device). If * manualUrl is non-null, then it specifies the URL or path to the song that will be played * next.//from w w w. j a v a2 s .c om */ void playNextSong(Long id) { if (id == null || id < 0) { throw new IllegalArgumentException("id must be non nul +ve"); } setState(State.Stopped); relaxResources(false); // release everything except MediaPlayer try { // set the source of the media player to a manual URL or path Track playingItem = mRetriever.getItem(id); createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); if (playingItem == null) { Toast.makeText(this, "All Tracks of current category is been played", Toast.LENGTH_LONG).show(); processStopRequest(true); // stop everything! return; } // BusProvider.getInstance().post(playingItem); mCurrentID = id; mPlayer.setDataSource(playingItem.isDownloded() ? playingItem.getLocalUrl(this) : playingItem.getUrl()); mIsStreaming = playingItem.getUrl().startsWith("http:") || playingItem.getUrl().startsWith("https:"); mSongTitle = playingItem.getTitle(); setState(State.Preparing); updateUI(); setUpAsForeground(mSongTitle + " (loading)"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); // Use the remote control APIs (if available) to set the playback state if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast( this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_STOP); // Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "Gita") .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, playingItem.getTitle()) .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, mDummyAlbumArt) .apply(); // starts preparing the media player in the background. When it's done, it will call // our OnPreparedListener (that is, the onPrepared() method on this class, since we set // the listener to 'this'). // // Until the media player is prepared, we *cannot* call start() on it! mPlayer.prepareAsync(); // If we are streaming from the internet, we want to hold a Wifi lock, which prevents // the Wifi radio from going to sleep while the song is playing. If, on the other hand, // we are *not* streaming, we want to release the lock if we were holding it before. if (mIsStreaming) mWifiLock.acquire(); else if (mWifiLock.isHeld()) mWifiLock.release(); } catch (IOException ex) { Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); ex.printStackTrace(); } }
From source file:com.andreadec.musicplayer.MusicService.java
/** * Called when the service is created.//w w w .j a v a 2 s. com */ @Override public void onCreate() { PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MusicServiceWakelock"); // Initialize the telephony manager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); phoneStateListener = new MusicPhoneStateListener(); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Initialize pending intents quitPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.quit"), 0); previousPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.previous"), 0); playpausePendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.playpause"), 0); nextPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.next"), 0); pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), PendingIntent.FLAG_UPDATE_CURRENT); // Read saved user preferences preferences = PreferenceManager.getDefaultSharedPreferences(this); // Initialize the media player mediaPlayer = new MediaPlayer(); mediaPlayer.setOnCompletionListener(this); mediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK); // Enable the wake lock to keep CPU running when the screen is switched off shuffle = preferences.getBoolean(Constants.PREFERENCE_SHUFFLE, Constants.DEFAULT_SHUFFLE); repeat = preferences.getBoolean(Constants.PREFERENCE_REPEAT, Constants.DEFAULT_REPEAT); repeatAll = preferences.getBoolean(Constants.PREFERENCE_REPEATALL, Constants.DEFAULT_REPEATALL); try { // This may fail if the device doesn't support bass boost bassBoost = new BassBoost(1, mediaPlayer.getAudioSessionId()); bassBoost.setEnabled( preferences.getBoolean(Constants.PREFERENCE_BASSBOOST, Constants.DEFAULT_BASSBOOST)); setBassBoostStrength(preferences.getInt(Constants.PREFERENCE_BASSBOOSTSTRENGTH, Constants.DEFAULT_BASSBOOSTSTRENGTH)); bassBoostAvailable = true; } catch (Exception e) { bassBoostAvailable = false; } try { // This may fail if the device doesn't support equalizer equalizer = new Equalizer(1, mediaPlayer.getAudioSessionId()); equalizer.setEnabled( preferences.getBoolean(Constants.PREFERENCE_EQUALIZER, Constants.DEFAULT_EQUALIZER)); setEqualizerPreset( preferences.getInt(Constants.PREFERENCE_EQUALIZERPRESET, Constants.DEFAULT_EQUALIZERPRESET)); equalizerAvailable = true; } catch (Exception e) { equalizerAvailable = false; } random = new Random(System.nanoTime()); // Necessary for song shuffle shakeListener = new ShakeListener(this); if (preferences.getBoolean(Constants.PREFERENCE_SHAKEENABLED, Constants.DEFAULT_SHAKEENABLED)) { shakeListener.enable(); } telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); // Start listen for telephony events // Inizialize the audio manager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName()); audioManager.registerMediaButtonEventReceiver(mediaButtonReceiverComponent); audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); // Initialize remote control client if (Build.VERSION.SDK_INT >= 14) { icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mediaButtonReceiverComponent); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0); remoteControlClient = new RemoteControlClient(mediaPendingIntent); remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT); audioManager.registerRemoteControlClient(remoteControlClient); } updateNotificationMessage(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("com.andreadec.musicplayer.quit"); intentFilter.addAction("com.andreadec.musicplayer.previous"); intentFilter.addAction("com.andreadec.musicplayer.previousNoRestart"); intentFilter.addAction("com.andreadec.musicplayer.playpause"); intentFilter.addAction("com.andreadec.musicplayer.next"); intentFilter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals("com.andreadec.musicplayer.quit")) { sendBroadcast(new Intent("com.andreadec.musicplayer.quitactivity")); stopSelf(); return; } else if (action.equals("com.andreadec.musicplayer.previous")) { previousItem(false); } else if (action.equals("com.andreadec.musicplayer.previousNoRestart")) { previousItem(true); } else if (action.equals("com.andreadec.musicplayer.playpause")) { playPause(); } else if (action.equals("com.andreadec.musicplayer.next")) { nextItem(); } else if (action.equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { if (preferences.getBoolean(Constants.PREFERENCE_STOPPLAYINGWHENHEADSETDISCONNECTED, Constants.DEFAULT_STOPPLAYINGWHENHEADSETDISCONNECTED)) { pause(); } } } }; registerReceiver(broadcastReceiver, intentFilter); if (!isPlaying()) { loadLastSong(); } startForeground(Constants.NOTIFICATION_MAIN, notification); }
From source file:com.brandroidtools.filemanager.activities.PickerActivity.java
/** * {@inheritDoc}// ww w .ja v a 2s. c o m */ @Override public void onDismiss(DialogInterface dialog) { if (this.mFso != null) { File src = new File(this.mFso.getFullPath()); if (getIntent().getExtras() != null) { // Some AOSP applications use the gallery to edit and crop the selected image // with the Gallery crop editor. In this case pass the picked file to the // CropActivity with the requested parameters // Expected result is on onActivityResult Bundle extras = getIntent().getExtras(); String crop = extras.getString(EXTRA_CROP); if (Boolean.parseBoolean(crop)) { // We want to use the Gallery3d activity because we know about it, and his // parameters. At least we have a compatible one. Intent intent = new Intent(ACTION_CROP); if (getIntent().getType() != null) { intent.setType(getIntent().getType()); } intent.setData(Uri.fromFile(src)); intent.putExtras(extras); intent.setComponent(CROP_COMPONENT); startActivityForResult(intent, RESULT_CROP_IMAGE); return; } } // Return the picked file, as expected (this activity should fill the intent data // and return RESULT_OK result) Intent result = new Intent(); result.setData(getResultUriForFileFromIntent(src, getIntent())); setResult(Activity.RESULT_OK, result); finish(); } else { cancel(); } }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
private Intent buildIntent(String action, String uri, String type, JSONObject extras, String packagename, String classname, JSONArray categories) throws JSONException { Intent intent = new Intent(action); intent.setDataAndType(uri != null ? Uri.parse(uri) : null, type); if (packagename != null && classname != null) { intent.setComponent(new ComponentName(packagename, classname)); }/*ww w.j a va 2 s. c o m*/ if (extras != null) { putExtrasFromJsonObject(extras, intent); } if (categories != null) { for (int i = 0; i < categories.length(); i++) { intent.addCategory(categories.getString(i)); } } return intent; }