List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:com.maskyn.fileeditorpro.activity.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, final Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { if (requestCode == SELECT_FILE_CODE) { final Uri data = intent.getData(); final GreatUri newUri = new GreatUri(data, AccessStorageApi.getPath(this, data), AccessStorageApi.getName(this, data)); newFileToOpen(newUri, ""); } else if (requestCode == SELECT_FOLDER_CODE) { FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isFile(); }//from www . j a v a2s . c o m }; final Uri data = intent.getData(); File dir = new File(data.getPath()); File[] fileList = dir.listFiles(fileFilter); for (int i = 0; i < fileList.length; i++) { Uri particularUri = Uri.parse("file://" + fileList[i].getPath()); final GreatUri newUri = new GreatUri(particularUri, AccessStorageApi.getPath(this, particularUri), AccessStorageApi.getName(this, particularUri)); greatUris.add(newUri); refreshList(newUri, true, false); arrayAdapter.selectPosition(newUri); } if (fileList.length > 0) { Uri particularUri = Uri.parse("file://" + fileList[0].getPath()); final GreatUri newUri = new GreatUri(particularUri, AccessStorageApi.getPath(this, particularUri), AccessStorageApi.getName(this, particularUri)); newFileToOpen(newUri, ""); } } else { final Uri data = intent.getData(); final GreatUri newUri = new GreatUri(data, AccessStorageApi.getPath(this, data), AccessStorageApi.getName(this, data)); // grantUriPermission(getPackageName(), data, Intent.FLAG_GRANT_READ_URI_PERMISSION); final int takeFlags = intent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); // Check for the freshest data. getContentResolver().takePersistableUriPermission(data, takeFlags); if (requestCode == READ_REQUEST_CODE || requestCode == CREATE_REQUEST_CODE) { newFileToOpen(newUri, ""); } if (requestCode == SAVE_AS_REQUEST_CODE) { new SaveFileTask(this, newUri, pageSystem.getAllText(mEditor.getText().toString()), currentEncoding, new SaveFileTask.SaveFileInterface() { @Override public void fileSaved(Boolean success) { savedAFile(greatUri, false); newFileToOpen(newUri, ""); } }).execute(); } } } }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java
/** * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. * The intent will call closeExternalStorageFiles() if the external media * is going to be ejected, so applications can clean up any files they have open. *//*from w w w. j av a 2s . c om*/ public void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_EJECT)) { saveQueue(true); mQueueIsSaveable = false; closeExternalStorageFiles(intent.getData().getPath()); } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { mMediaMountedCount++; mCardId = MusicUtils.getCardId(MediaPlaybackService.this); reloadQueue(); mQueueIsSaveable = true; notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(Intent.ACTION_MEDIA_EJECT); iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); iFilter.addDataScheme("file"); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:com.ringdroid.RingdroidEditActivity.java
/** Called with an Activity we started with an Intent returns. */ @Override/*from w ww.j a v a2 s. c o m*/ protected void onActivityResult(int requestCode, int resultCode, Intent dataIntent) { if (requestCode == REQUEST_CODE_CHOOSE_CONTACT) { // The user finished saving their ringtone and they're // just applying it to a contact. When they return here, // they're done. // sendStatsToServerIfAllowedAndFinish(); return; } if (requestCode != REQUEST_CODE_RECORD) { return; } if (resultCode != RESULT_OK) { finish(); return; } if (dataIntent == null) { finish(); return; } // Get the recorded file and open it, but save the uri and // filename so that we can delete them when we exit; the // recorded file is only temporary and only the edited & saved // ringtone / other sound will stick around. mRecordingUri = dataIntent.getData(); mRecordingFilename = getFilenameFromUri(mRecordingUri); if (mRecordingFilename == null) return; mFilename = mRecordingFilename; loadFromFile(); }
From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (requestCode == REQUEST_CODE_SCAN && resultCode == Activity.RESULT_OK) { final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT); new StringInputParser(input) { @Override// w w w .j a v a 2 s.c o m protected void handlePaymentIntent(@Nonnull final PaymentIntent paymentIntent) { SendCoinsActivity.start(WalletActivity.this, paymentIntent); } @Override protected void handlePrivateKey(@Nonnull final ECKey key) { SweepWalletActivity.start(WalletActivity.this, key); } @Override protected void handleDirectTransaction(final Transaction tx) throws VerificationException { application.processDirectTransaction(tx); } @Override protected void error(final int messageResId, final Object... messageArgs) { dialog(WalletActivity.this, null, R.string.button_scan, messageResId, messageArgs); } }.parse(); } if (requestCode == REQUEST_CODE_SCAN_ADD_CONTACT && resultCode == Activity.RESULT_OK) { addContactScanResult = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT); } if (requestCode == REQUEST_PICK_BACKUP && resultCode == Activity.RESULT_OK) { pickBackupResult = intent.getData(); } }
From source file:me.spadival.podmode.PodModeService.java
void processAddRequest(Intent intent) { // user wants to play a song directly by URL or path. The URL or path // comes in the "data" // part of the Intent. This Intent is sent by {@link MainActivity} after // the user//from www .ja v a 2 s. co m // specifies the URL/path via an alert box. if (mState == State.Retrieving) { // we'll play the requested URL right after we finish retrieving mWhatToPlayAfterRetrieve = intent.getData(); mStartPlayingAfterRetrieve = true; } else if (mState == State.Playing || mState == State.Paused || mState == State.Stopped) { Log.i(TAG, "Playing from URL/path: " + intent.getData().toString()); tryToGetAudioFocus(); playNextSong(intent.getData().toString()); } }
From source file:cgeo.geocaching.CacheListActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_IMPORT_GPX && resultCode == Activity.RESULT_OK) { // The document selected by the user won't be returned in the intent. // Instead, a URI to that document will be contained in the return intent // provided to this method as a parameter. Pull that uri using "resultData.getData()" if (data != null) { final Uri uri = data.getData(); new GPXImporter(this, listId, importGpxAttachementFinishedHandler).importGPX(uri, null, getDisplayName(uri)); }//from ww w. j a va 2s.com } else if (requestCode == REQUEST_CODE_IMPORT_PQ && resultCode == Activity.RESULT_OK) { if (data != null) { final Uri uri = data.getData(); new GPXImporter(this, listId, importGpxAttachementFinishedHandler).importGPX(uri, data.getType(), null); } } else if (requestCode == FilterActivity.REQUEST_SELECT_FILTER && resultCode == Activity.RESULT_OK) { final int[] filterIndex = data.getIntArrayExtra(FilterActivity.EXTRA_FILTER_RESULT); setFilter(FilterActivity.getFilterFromPosition(filterIndex[0], filterIndex[1])); } else if (requestCode == REQUEST_CODE_RESTART && resultCode == Activity.RESULT_OK) { restartActivity(); } if (type == CacheListType.OFFLINE && requestCode != REQUEST_CODE_RESTART) { refreshCurrentList(); } }
From source file:me.myatminsoe.myansms.Message.java
/** * Get a {@link OnLongClickListener} to save the attachment. * * @param context {@link Context}//from ww w .java2 s .co m * @return {@link OnLongClickListener} */ public OnLongClickListener getSaveAttachmentListener(final Activity context) { if (contentIntent == null) { return null; } return new OnLongClickListener() { @Override public boolean onLongClick(final View v) { // check/request permission Manifest.permission.WRITE_EXTERNAL_STORAGE if (!SMSdroid.requestPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE, 0, R.string.permissions_write_external_storage, null)) { return true; } try { String fn = ATTACHMENT_FILE; final Intent ci = Message.this.contentIntent; final String ct = ci.getType(); if (ct == null) { fn += "null"; } else if (ct.startsWith("image/")) { switch (ct) { case "image/jpeg": fn += "jpg"; break; case "image/gif": fn += "gif"; break; default: fn += "png"; break; } } else if (ct.startsWith("audio/")) { switch (ct) { case "audio/3gpp": fn += "3gpp"; break; case "audio/mpeg": fn += "mp3"; break; case "audio/mid": fn += "mid"; break; default: fn += "wav"; break; } } else if (ct.startsWith("video/")) { if (ct.equals("video/3gpp")) { fn += "3gpp"; } else { fn += "avi"; } } else { fn += "ukn"; } final File file = Message.this.createUniqueFile(Environment.getExternalStorageDirectory(), fn); //noinspection ConstantConditions InputStream in = context.getContentResolver().openInputStream(ci.getData()); OutputStream out = new FileOutputStream(file); IOUtils.copy(in, out); out.flush(); out.close(); //noinspection ConstantConditions in.close(); Toast.makeText(context, context.getString(R.string.attachment_saved) + " " + fn, Toast.LENGTH_LONG).show(); return true; } catch (IOException e) { Toast.makeText(context, R.string.attachment_not_saved, Toast.LENGTH_LONG).show(); } catch (NullPointerException e) { Toast.makeText(context, R.string.attachment_not_saved, Toast.LENGTH_LONG).show(); } return true; } }; }
From source file:com.dycody.android.idealnote.DetailFragment.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void onActivityResultManageReceivedFiles(Intent intent) { List<Uri> uris = new ArrayList<>(); if (Build.VERSION.SDK_INT > 16 && intent.getClipData() != null) { for (int i = 0; i < intent.getClipData().getItemCount(); i++) { uris.add(intent.getClipData().getItemAt(i).getUri()); }/*w ww . j av a 2s . com*/ } else { uris.add(intent.getData()); } for (Uri uri : uris) { String name = FileHelper.getNameFromUri(mainActivity, uri); new AttachmentTask(this, uri, name, this).execute(); } }
From source file:com.fvd.nimbus.PaintActivity.java
/** Called when the activity is first created. */ @Override//from ww w . j ava 2 s . co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); try { requestWindowFeature(Window.FEATURE_NO_TITLE); } catch (Exception e) { e.printStackTrace(); } ctx = this; prefs = PreferenceManager.getDefaultSharedPreferences(this); dWidth = prefs.getInt("dWidth", 2); fWidth = prefs.getInt("fWidth", 1); dColor = prefs.getInt(pColor, Color.RED); saveFormat = Integer.parseInt(prefs.getString("saveFormat", "1")); serverHelper.getInstance().setCallback(this, this); serverHelper.getInstance().setMode(saveFormat); setContentView(R.layout.screen_edit); drawer = (DrawerLayout) findViewById(R.id.root); findViewById(R.id.bDraw1).setOnClickListener(this); findViewById(R.id.bDraw2).setOnClickListener(this); findViewById(R.id.bDraw3).setOnClickListener(this); findViewById(R.id.bDraw4).setOnClickListener(this); findViewById(R.id.bDraw5).setOnClickListener(this); findViewById(R.id.bDraw6).setOnClickListener(this); findViewById(R.id.bDraw8).setOnClickListener(this); findViewById(R.id.bColor1).setOnClickListener(this); findViewById(R.id.bColor2).setOnClickListener(this); findViewById(R.id.bColor3).setOnClickListener(this); findViewById(R.id.bColor4).setOnClickListener(this); findViewById(R.id.bColor5).setOnClickListener(this); paletteButton = (CircleButton) findViewById(R.id.bToolColor); paletteButton.setOnClickListener(this); paletteButton_land = (CircleButton) findViewById(R.id.bToolColor_land); //paletteButton_land.setOnClickListener(this); ((SeekBar) findViewById(R.id.seekBarLine)).setProgress(dWidth * 10); ((SeekBar) findViewById(R.id.seekBarType)).setProgress(fWidth * 10); ((TextView) findViewById(R.id.tvTextType)).setText(String.format("%d", 40 + fWidth * 20)); findViewById(R.id.bUndo).setOnClickListener(this); findViewById(R.id.btnBack).setOnClickListener(this); findViewById(R.id.bClearAll).setOnClickListener(this); findViewById(R.id.bTurnLeft).setOnClickListener(this); findViewById(R.id.bTurnRight).setOnClickListener(this); findViewById(R.id.bDone).setOnClickListener(this); findViewById(R.id.bApplyText).setOnClickListener(this); ((ImageButton) findViewById(R.id.bStroke)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.setSelected(!v.isSelected()); } }); lineWidthListener = new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub if (true || fromUser) { /*dWidth = (progress/10); drawView.setWidth((dWidth+1)*5);*/ dWidth = progress; drawView.setWidth(dWidth); Editor e = prefs.edit(); e.putInt("dWidth", dWidth); e.commit(); } } }; ((SeekBar) findViewById(R.id.seekBarLine)).setOnSeekBarChangeListener(lineWidthListener); ((SeekBar) findViewById(R.id.ls_seekBarLine)).setOnSeekBarChangeListener(lineWidthListener); fontSizeListener = new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub if (fromUser) { fWidth = progress / 10; int c = 40 + fWidth * 20; drawView.setFontSize(c); Editor e = prefs.edit(); e.putInt("fWidth", fWidth); e.commit(); try { ((TextView) findViewById(R.id.tvTextType)).setText(String.format("%d", c)); ((TextView) findViewById(R.id.ls_tvTextType)).setText(String.format("%d", c)); } catch (Exception ex) { } } } }; ((SeekBar) findViewById(R.id.seekBarType)).setOnSeekBarChangeListener(fontSizeListener); ((SeekBar) findViewById(R.id.ls_seekBarType)).setOnSeekBarChangeListener(fontSizeListener); drawView = (DrawView) findViewById(R.id.painter); drawView.setWidth((dWidth + 1) * 5); drawView.setFontSize(40 + fWidth * 20); setBarConfig(getResources().getConfiguration().orientation); findViewById(R.id.bEditPage).setOnClickListener(this); findViewById(R.id.bToolColor).setOnClickListener(this); findViewById(R.id.bErase).setOnClickListener(this); findViewById(R.id.bToolShape).setOnClickListener(this); findViewById(R.id.bToolText).setOnClickListener(this); findViewById(R.id.bToolCrop).setOnClickListener(this); findViewById(R.id.btnBack).setOnClickListener(this); findViewById(R.id.bDone).setOnClickListener(this); findViewById(R.id.btnShare).setOnClickListener(this); findViewById(R.id.bSave2SD).setOnClickListener(this); findViewById(R.id.bSave2Nimbus).setOnClickListener(this); userMail = prefs.getString("userMail", ""); userPass = prefs.getString("userPass", ""); sessionId = prefs.getString("sessionId", ""); appSettings.sessionId = sessionId; appSettings.userMail = userMail; appSettings.userPass = userPass; storePath = ""; Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); //storePath= intent.getPackage().getClass().toString(); if ((Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SEND.equals(action) || "com.onebit.nimbusnote.EDIT_PHOTO".equals(action)) && type != null) { if (type.startsWith("image/")) { Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); if (imageUri == null) imageUri = intent.getData(); if (imageUri != null) { String url = Uri.decode(imageUri.toString()); if (url.startsWith(CONTENT_PHOTOS_URI_PREFIX)) { url = getPhotosPhotoLink(url); } //else url=Uri.decode(url); ContentResolver cr = getContentResolver(); InputStream is; try { is = cr.openInputStream(Uri.parse(url)); if ("com.onebit.nimbusnote.EDIT_PHOTO".equals(action)) storePath = " ";//getGalleryPath(Uri.parse(url)); Bitmap bmp = BitmapFactory.decodeStream(is); if (bmp.getWidth() != -1 && bmp.getHeight() != -1) drawView.setBitmap(bmp, 0); } catch (Exception e) { appSettings.appendLog("paint:onCreate " + e.getMessage()); } } } } else { String act = getIntent().getExtras().getString("act"); if ("photo".equals(act)) { getPhoto(); } else if ("picture".equals(act)) { getPicture(); } else { String filePath = getIntent().getExtras().getString("path"); boolean isTemp = getIntent().getExtras().getBoolean("temp"); domain = getIntent().getExtras().getString("domain"); if (domain == null) domain = serverHelper.getDate(); if (filePath.contains("://")) { Bitmap bmp = helper.LoadImageFromWeb(filePath); if (bmp != null) { drawView.setBitmap(bmp, 0); } } else { File file = new File(filePath); if (file.exists()) { try { int orient = helper.getOrientationFromExif(filePath); Bitmap bmp = helper.decodeSampledBitmap(filePath, 1000, 1000); if (bmp != null) { drawView.setBitmap(bmp, orient); } } catch (Exception e) { appSettings.appendLog("paint.onCreate() " + e.getMessage()); } if (isTemp) file.delete(); } } } } drawView.setBackgroundColor(Color.WHITE); drawView.requestFocus(); drawView.setColour(dColor); setPaletteColor(dColor); drawView.setSelChangeListener(new shapeSelectionListener() { @Override public void onSelectionChanged(int shSize, int fSize, int shColor) { setSelectedFoot(0); setLandToolSelected(R.id.bEditPage_land); //updateColorDialog(shSize!=-1?(shSize/5)-1:dWidth, fSize!=-1?(fSize-40)/20:fWidth, shColor!=0?colorToId(shColor):dColor); dColor = shColor; ccolor = shColor; int sw = shSize != -1 ? shSize : dWidth; canChange = false; ((SeekBar) findViewById(R.id.seekBarLine)).setProgress(sw); ((SeekBar) findViewById(R.id.ls_seekBarLine)).setProgress(sw); setPaletteColor(dColor); drawView.setColour(dColor); canChange = true; } @Override public void onTextChanged(String text, boolean stroke) { if (findViewById(R.id.text_field).getVisibility() != View.VISIBLE) { hideTools(); findViewById(R.id.bStroke).setSelected(stroke); ((EditText) findViewById(R.id.etEditorText)).setText(text); findViewById(R.id.text_field).setVisibility(View.VISIBLE); findViewById(R.id.etEditorText).requestFocus(); ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(findViewById(R.id.etEditorText), 0); findViewById(R.id.bToolText).postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub setSelectedFoot(2); } }, 100); } } }); setColorButtons(dColor); //mPlanetTitles = getResources().getStringArray(R.array.lmenu_paint); /*ListView listView = (ListView) findViewById(R.id.left_drawer); listView.setAdapter(new DrawerMenuAdapter(this,getResources().getStringArray(R.array.lmenu_paint))); listView.setOnItemClickListener(this);*/ }
From source file:com.maskyn.fileeditorpro.activity.MainActivity.java
/** * Parses the intent//w w w. ja va 2 s.co m */ private void parseIntent(Intent intent) { final String action = intent.getAction(); final String type = intent.getType(); if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action) || Intent.ACTION_PICK.equals(action) && type != null) { // Post event //newFileToOpen(new File(intent // .getData().getPath()), ""); Uri uri = intent.getData(); GreatUri newUri = new GreatUri(uri, AccessStorageApi.getPath(this, uri), AccessStorageApi.getName(this, uri)); newFileToOpen(newUri, ""); } else if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { newFileToOpen(new GreatUri(Uri.EMPTY, "", ""), intent.getStringExtra(Intent.EXTRA_TEXT)); } } }