List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:com.polyvi.xface.extension.contact.XContactsExt.java
/** * ?activity// ww w . ja va 2 s. c o m * @param intent */ private boolean handleResult(Intent intent) { Uri contactData = intent.getData(); Cursor cursor = getContext().getContentResolver().query(contactData, null, null, null, null); if (cursor.moveToFirst()) { String contactID = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); Cursor cursorContact = mContactAccessor.getContactById(contactID); JSONArray result = populateContactArray(getContactFieldSet(mFields), cursorContact, Integer.MAX_VALUE); return sendJSCallback(result); } return false; }
From source file:org.bwgz.quotation.activity.QuotationActivity.java
@Override protected void onResume() { super.onResume(); Uri uri = history.current();//from w w w .j a v a 2 s . c o m Log.d(TAG, String.format("onResume - uri: %s", uri)); Intent intent = getIntent(); Log.d(TAG, String.format("onResume - intent: %s", intent)); if (intent != null && intent.getData() != null) { uri = intent.getData(); } Log.d(TAG, String.format("onResume - uri: %s", uri)); if (uri == null) { loadRandomQuote(); } else { history.add(uri); if (menu != null) { menu.findItem(R.id.actionbar_back).setEnabled(history.hasBack()); menu.findItem(R.id.actionbar_forward).setEnabled(history.hasForward()); } loadQuote(uri); } }
From source file:com.ritul.truckshare.RegisterActivity.DriverLicenseActivity.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Utility.GALLERY_PICTURE && data != null) { isImage = true;/*from w w w . j av a2 s .com*/ // data contains result // Do some task Image_Selecting_Task(data); Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = DriverLicenseActivity.this.getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); selectedpath = cursor.getString(columnIndex); cursor.close(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 8; final Bitmap bitmap = BitmapFactory.decodeFile(selectedpath, options); convertimagetobyte(); imagedata = Base64.encodeToString(imageByte, Base64.DEFAULT); } else if (requestCode == Utility.CAMERA_PICTURE && data != null) { isImage = true; // Do some task //Image_Selecting_Task(data); if (requestCode == Utility.CAMERA_PICTURE && resultCode == RESULT_OK && data != null) { Bitmap photo = (Bitmap) data.getExtras().get("data"); preview.setImageBitmap(photo); Bitmap bitmap = ((BitmapDrawable) preview.getDrawable()).getBitmap(); imagedata = Base64.encodeToString(getBytesFromBitmap(bitmap), Base64.DEFAULT); } } }
From source file:ca.rmen.android.scrumchatter.main.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.v(TAG, "onCreate"); super.onCreate(savedInstanceState); Theme.checkTheme(this); mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); StrictModeUtil.enable();//from www .j a va2s . com // Set up the action bar. setSupportActionBar(mBinding.toolbarTabs.toolbar); ActionBar supportActionBar = getSupportActionBar(); assert supportActionBar != null; supportActionBar.setDisplayHomeAsUpEnabled(true); supportActionBar.setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mBinding.drawerLayout, /* DrawerLayout object */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */); // Explanation of setDrawerIndicatorEnabled and setHomeAsUpIndicator: // We want to only have a hamburger icon, always, without any animation. // If we don't call either of these methods, we use the default indicator, // which is the hamburger icon transitioning to a left-arrow icon, as the drawer is opened. // If we only call setDrawerIndicatorUpEnabled, we'll have the left arrow icon always. // If we only call setHomeAsUpIndicator (with a hamburger icon), we'll have a hamburger icon // but with a bug: If you open the drawer, rotate, and close it, you'll have the left arrow // again. // With the combination of both setDrawerIndicatorEnabled and setHomeAsUpIndicator, we // have a hamburger icon always. mDrawerToggle.setDrawerIndicatorEnabled(false); mDrawerToggle.setHomeAsUpIndicator(new DrawerArrowDrawable(this)); mMainPagerAdapter = new MainPagerAdapter(this, getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mBinding.pager.setAdapter(mMainPagerAdapter); mBinding.toolbarTabs.tabs.setupWithViewPager(mBinding.pager); // If our activity was opened by choosing a file from a mail attachment, file browser, or other program, // import the database from this file. Intent intent = getIntent(); if (intent != null) { if (Intent.ACTION_VIEW.equals(intent.getAction())) importDB(intent.getData()); } // Register various observers. mTeamsObserver = new TeamsObserver(this, mOnTeamsChangedListener); mOnTeamsChangedListener.onTeamsChanged(); mTeamsObserver.register(); mTeamNavigationMenu = new TeamNavigationMenu(this, mBinding.leftDrawer.getMenu()); mTeamNavigationMenu.load(); mBinding.leftDrawer.setNavigationItemSelectedListener(mOnNavigationItemSelectedListener); IntentFilter filter = new IntentFilter(ACTION_IMPORT_COMPLETE); filter.addAction(ACTION_EXPORT_COMPLETE); LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(mBroadcastReceiver, filter); }
From source file:br.com.GUI.perfil.PerfilAluno.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == 200 || requestCode == 202) { if (requestCode == 200) { selectedImageUri = data.getData(); cortar(requestCode);/*w w w . j a v a2s.co m*/ /*selectedImageUri = Uri.fromFile(photo); ContentResolver cr = getContentResolver(); Bitmap foto; try{ foto = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImageUri); bmp = ImageUtils.compactImages(foto); imagem.setImageBitmap(foto); }catch(FileNotFoundException e){ Log.i("Exception", e.toString()); e.printStackTrace(); } catch (IOException e){ }*/ } else if (requestCode == 202) { //get the returned data Bundle extras = data.getExtras(); //get the cropped bitmap Bitmap foto = extras.getParcelable("data"); bmp = ImageUtils.compactImages(foto); img.setImageBitmap(bmp); //Log.i("tirei a foto ", "e setei no canvas"); Aluno p = new Aluno(); p.setUsuario(pref.getString("usuario", null)); if (p.editarFotoAlunoWeb(ImageUtils.bitmapToByteArray(bmp))) { if (p.atualizarFotoAluno(b, ImageUtils.bitmapToByteArray(bmp))) { Toast.makeText(getActivity(), "Atualizada com sucesso!", Toast.LENGTH_SHORT).show(); } } refresh(); } } else if (requestCode == 100 || requestCode == 102) { if (requestCode == 100) { selectedImageUri = data.getData(); cortar(requestCode); } else if (requestCode == 102) { //get the returned data Bundle extras = data.getExtras(); //get the cropped bitmap Bitmap foto = extras.getParcelable("data"); bmp = ImageUtils.compactImages(foto); img.setImageBitmap(bmp); Aluno p = new Aluno(); p.setUsuario(pref.getString("usuario", null)); if (p.editarFotoAlunoWeb(ImageUtils.bitmapToByteArray(bmp))) { if (p.atualizarFotoAluno(b, ImageUtils.bitmapToByteArray(bmp))) { Toast.makeText(getActivity(), "Atualizada com sucesso!", Toast.LENGTH_SHORT).show(); } } refresh(); } /*try { Uri selectedImage = data.getData(); String[] nomeCaminho = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(selectedImage, nomeCaminho, null, null, null); cursor.moveToFirst(); int indexColuna = cursor.getColumnIndex(nomeCaminho[0]); String caminho = cursor.getString(indexColuna); bmp = ImageUtils.compactImages(BitmapFactory.decodeFile(caminho)); imagem.setImageBitmap(BitmapFactory.decodeFile(caminho)); } catch (Exception e) { Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show(); Log.e("Camera", e.toString()); } */ } } else { selectedImageUri = null; img.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.profile)); } }
From source file:com.tuxpan.foregroundvideocapture.CaptureFG.java
/** * Called when the video view exits./*ww w . jav a 2 s . com*/ * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). * @throws JSONException */ public void onActivityResult(int requestCode, int resultCode, final Intent intent) { // Result received okay if (resultCode == Activity.RESULT_OK) { // An audio clip was requested final CaptureFG that = this; Runnable captureVideo = new Runnable() { @Override public void run() { Uri data = null; if (intent != null) { // Get the uri of the video clip data = intent.getData(); } if (data == null) { File movie = new File(getTempDirectoryPath(), "video.3gp"); data = Uri.fromFile(movie); } // create a file object from the uri if (data == null) { that.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null")); } else { results.put(createMediaFile(data)); // Send Uri back to JavaScript for viewing video that.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results)); } } }; this.cordova.getThreadPool().execute(captureVideo); } // If canceled else if (resultCode == Activity.RESULT_CANCELED) { // If we have partial results send them back to the user if (results.length() > 0) { this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results)); } // user canceled the action else { this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Canceled.")); } } // If something else else { // If we have partial results send them back to the user if (results.length() > 0) { this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results)); } // something bad happened else { this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Did not complete!")); } } }
From source file:ca.cmput301f13t03.adventure_datetime.view.FullScreen_Image.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if (resultCode != RESULT_OK) { if (requestCode == CAMERA) { _fragment.removeMedia(_fragment.getStoryMedia().size() - 1); }/*from w w w .j a va 2 s.c om*/ return; } switch (requestCode) { case GALLERY: try { InputStream is = getContentResolver().openInputStream(imageReturnedIntent.getData()); Bitmap bit = BitmapFactory.decodeStream(is); Image selectedImage = new Image(Image.compressBitmap(bit, 85)); _fragment.addMedia(selectedImage); Locator.getAuthorController().saveFragment(_fragment); } catch (Exception e) { Log.e(TAG, "Error getting new image", e); } break; case CAMERA: try { InputStream is = getContentResolver().openInputStream(_newImage); Bitmap bit = BitmapFactory.decodeStream(is); Image selectedImage = new Image(Image.compressBitmap(bit, 85)); _fragment.addMedia(selectedImage); Locator.getAuthorController().saveFragment(_fragment); } catch (Exception e) { Log.e(TAG, "Error getting new image", e); } break; } }
From source file:com.github.chenxiaolong.dualbootpatcher.settings.RomSettingsFragment.java
@Override public void onActivityResult(int request, int result, Intent data) { switch (request) { case REQUEST_BACKUP_DIRECTORY: if (data != null && result == Activity.RESULT_OK) { Uri treeDocumentUri = FileUtils.getDocumentUriFromTreeUri(data.getData()); if (treeDocumentUri != null) { new SetBackupPathTask().execute(treeDocumentUri); }//from w ww.j a v a 2 s.com } break; default: super.onActivityResult(request, result, data); break; } }
From source file:com.phonegap.Capture.java
/** * Called when the video view exits. /* ww w . ja v a 2 s . c o m*/ * * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). * @throws JSONException */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Result received okay if (resultCode == Activity.RESULT_OK) { // An audio clip was requested if (requestCode == CAPTURE_AUDIO) { // Get the uri of the audio clip Uri data = intent.getData(); // create a file object from the uri results.put(createMediaFile(data)); if (results.length() >= limit) { // Send Uri back to JavaScript for listening to audio this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId); } else { // still need to capture more audio clips captureAudio(); } } else if (requestCode == CAPTURE_IMAGE) { // For some reason if I try to do: // Uri data = intent.getData(); // It crashes in the emulator and on my phone with a null pointer exception // To work around it I had to grab the code from CameraLauncher.java try { // Create an ExifHelper to save the exif data that is lost during compression ExifHelper exif = new ExifHelper(); exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Capture.jpg"); exif.readExifData(); // Read in bitmap of captured image Bitmap bitmap = android.provider.MediaStore.Images.Media .getBitmap(this.ctx.getContentResolver(), imageUri); // Create entry in media store for image // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it) ContentValues values = new ContentValues(); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, IMAGE_JPEG); Uri uri = null; try { uri = this.ctx.getContentResolver() .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.ctx.getContentResolver() .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.fail(createErrorObject(CAPTURE_INTERNAL_ERR, "Error capturing image - no media storage found.")); return; } } // Add compressed version of captured image to returned media store Uri OutputStream os = this.ctx.getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os); os.close(); bitmap.recycle(); bitmap = null; System.gc(); // Restore exif data to file exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx)); exif.writeExifData(); // Add image to results results.put(createMediaFile(uri)); if (results.length() >= limit) { // Send Uri back to JavaScript for viewing image this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId); } else { // still need to capture more images captureImage(); } } catch (IOException e) { e.printStackTrace(); this.fail(createErrorObject(CAPTURE_INTERNAL_ERR, "Error capturing image.")); } } else if (requestCode == CAPTURE_VIDEO) { // Get the uri of the video clip Uri data = intent.getData(); // create a file object from the uri results.put(createMediaFile(data)); if (results.length() >= limit) { // Send Uri back to JavaScript for viewing video this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId); } else { // still need to capture more video clips captureVideo(duration); } } } // If canceled else if (resultCode == Activity.RESULT_CANCELED) { // If we have partial results send them back to the user if (results.length() > 0) { this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId); } // user canceled the action else { this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Canceled.")); } } // If something else else { // If we have partial results send them back to the user if (results.length() > 0) { this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId); } // something bad happened else { this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Did not complete!")); } } }