List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:sjizl.com.ChatActivity.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (data != null) { // Get the URI of the selected file final Uri uri = data.getData(); Log.i("ffff:", "Uri = " + uri.toString()); try { // Get the file path from the URI final String path = FileUtils.getPath(this, uri); // Toast.makeText(ChatActivity.this, // "File Selected: " + path, Toast.LENGTH_LONG).show(); // CommonUtilities.custom_toast(getApplicationContext(), ChatActivity.this,"File Selected: " + path, null,R.drawable.iconbd); Thread thread = new Thread(new Runnable() { public void run() { doFileUpload(path); runOnUiThread(new Runnable() { public void run() { }/*from w w w. ja v a 2s .c o m*/ }); } }); thread.start(); } catch (Exception e) { Log.e("FileSelectorTestActivity", "File select error", e); } } } }
From source file:com.gelakinetic.mtgfam.activities.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* http://stackoverflow.com/questions/13179620/force-overflow-menu-in-actionbarsherlock/13180285 * // w ww . j a va 2 s .c o m * Open ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/ActionMenuPresenter.java, go to method reserveOverflow * Replace the original with: * public static boolean reserveOverflow(Context context) { return true; } */ if (DEVICE_VERSION >= DEVICE_HONEYCOMB) { try { ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); if (menuKeyField != null) { menuKeyField.setAccessible(true); menuKeyField.setBoolean(config, false); } } catch (Exception ex) { // Ignore } } mFragmentManager = getSupportFragmentManager(); try { pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (NameNotFoundException e) { pInfo = null; } if (prefAdapter == null) { prefAdapter = new PreferencesAdapter(this); } int lastVersion = prefAdapter.getLastVersion(); if (pInfo.versionCode != lastVersion) { // Clear the robospice cache on upgrade. This way, no cached values w/o foil prices will exist try { spiceManager.removeAllDataFromCache(); } catch (NullPointerException e) { // eat it. tasty } showDialogFragment(CHANGELOGDIALOG); prefAdapter.setLastVersion(pInfo.versionCode); bounceMenu = lastVersion <= 15; //Only bounce if the last version is 1.8.1 or lower (or a fresh install) } File mtr = new File(getFilesDir(), JudgesCornerFragment.MTR_LOCAL_FILE); File ipg = new File(getFilesDir(), JudgesCornerFragment.IPG_LOCAL_FILE); if (!mtr.exists()) { try { InputStream in = getResources().openRawResource(R.raw.mtr); FileOutputStream fos = new FileOutputStream(mtr); IOUtils.copy(in, fos); } catch (FileNotFoundException e) { Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage()); } catch (IOException e) { Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage()); } } if (!ipg.exists()) { try { InputStream in = getResources().openRawResource(R.raw.ipg); FileOutputStream fos = new FileOutputStream(ipg); IOUtils.copy(in, fos); } catch (FileNotFoundException e) { Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage()); } catch (IOException e) { Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage()); } } ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setIcon(R.drawable.sliding_menu_icon); SlidingMenu slidingMenu = getSlidingMenu(); slidingMenu.setBehindWidthRes(R.dimen.sliding_menu_width); slidingMenu.setBehindScrollScale(0.0f); slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); slidingMenu.setShadowWidthRes(R.dimen.shadow_width); slidingMenu.setShadowDrawable(R.drawable.sliding_menu_shadow); setSlidingActionBarEnabled(false); setBehindContentView(R.layout.fragment_menu); me = this; boolean autoupdate = prefAdapter.getAutoUpdate(); if (autoupdate) { // Only update the banning list if it hasn't been updated recently long curTime = new Date().getTime(); int updatefrequency = Integer.valueOf(prefAdapter.getUpdateFrequency()); int lastLegalityUpdate = prefAdapter.getLastLegalityUpdate(); // days to ms if (((curTime / 1000) - lastLegalityUpdate) > (updatefrequency * 24 * 60 * 60)) { startService(new Intent(this, DbUpdaterService.class)); } } timerHandler = new Handler(); registerReceiver(endTimeReceiver, new IntentFilter(RoundTimerFragment.RESULT_FILTER)); registerReceiver(startTimeReceiver, new IntentFilter(RoundTimerService.START_FILTER)); registerReceiver(cancelTimeReceiver, new IntentFilter(RoundTimerService.CANCEL_FILTER)); updatingDisplay = false; timeShowing = false; getSlidingMenu().setOnOpenedListener(new OnOpenedListener() { @Override public void onOpened() { // Close the keyboard if the slidingMenu is opened hideKeyboard(); } }); setContentView(R.layout.fragment_activity); getSupportFragmentManager().beginTransaction().replace(R.id.frag_menu, new MenuFragment()).commit(); showOnePane(); if (findViewById(R.id.middle_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mIsATablet = true; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { mThreePane = true; } else { mThreePane = false; } } else { mThreePane = false; mIsATablet = false; if (findViewById(R.id.middle_container) != null) { findViewById(R.id.middle_container).setVisibility(View.GONE); findViewById(R.id.right_container).setVisibility(View.GONE); } } Intent intent = getIntent(); if (savedInstanceState == null) { try { if (intent.getAction().equals(Intent.ACTION_VIEW)) { //apparently this can NPE on 4.3. because why not. if we catch it, launch the default frag // handles a click on a search suggestion; launches activity to show word Uri u = intent.getData(); long id = Long.parseLong(u.getLastPathSegment()); // add a fragment Bundle args = new Bundle(); args.putBoolean("isSingle", true); args.putLong("id", id); CardViewFragment rlFrag = new CardViewFragment(); rlFrag.setArguments(args); attachSingleFragment(rlFrag, "left_frag", false, false); showOnePane(); hideKeyboard(); } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) { boolean consolidate = prefAdapter.getConsolidateSearch(); String query = intent.getStringExtra(SearchManager.QUERY); SearchCriteria sc = new SearchCriteria(); sc.Name = query; sc.Set_Logic = (consolidate ? CardDbAdapter.FIRSTPRINTING : CardDbAdapter.ALLPRINTINGS); // add a fragment Bundle args = new Bundle(); args.putBoolean(SearchViewFragment.RANDOM, false); args.putSerializable(SearchViewFragment.CRITERIA, sc); if (mIsATablet) { SearchViewFragment svFrag = new SearchViewFragment(); svFrag.setArguments(args); attachSingleFragment(svFrag, "left_frag", false, false); } else { ResultListFragment rlFrag = new ResultListFragment(); rlFrag.setArguments(args); attachSingleFragment(rlFrag, "left_frag", false, false); } hideKeyboard(); } else if (intent.getAction().equals(ACTION_FULL_SEARCH)) { attachSingleFragment(new SearchViewFragment(), "left_frag", false, false); showOnePane(); } else if (intent.getAction().equals(ACTION_WIDGET_SEARCH)) { attachSingleFragment(new SearchWidgetFragment(), "left_frag", false, false); showOnePane(); } else if (intent.getAction().equals(ACTION_ROUND_TIMER)) { attachSingleFragment(new RoundTimerFragment(), "left_frag", false, false); showOnePane(); } else { launchDefaultFragment(); } } catch (NullPointerException e) { launchDefaultFragment(); } } }
From source file:com.abeo.tia.noordin.AddCaseStep2of4.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { System.out.println("workingthom2"); if (requestCode == 1) { if (null == data) return; Uri selectedImageUri = data.getData(); // MEDIA GALLERY System.out.println(selectedImageUri); selectedImagePath = selectedImageUri.getPath(); //selectedImagePath = getRealPathFromURI(selectedImageUri); //ImageFilePath.getPath(getApplicationContext(), selectedImageUri); Log.i("Image File Path", "" + selectedImagePath); edittextFile.setText("File Path : " + selectedImagePath); messageText.setText("File Path : " + selectedImagePath); }/* w ww . j av a2 s .c om*/ } }
From source file:org.geometerplus.android.fbreader.network.ActivityNetworkContext.java
public boolean onActivityResult(int requestCode, int resultCode, Intent data) { boolean processed = true; try {/*from w w w. j a va 2 s. co m*/ switch (requestCode) { default: processed = false; break; case NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER: if (resultCode == Activity.RESULT_OK && data != null) { myAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); } break; case NetworkLibraryActivity.REQUEST_AUTHORISATION: if (resultCode == Activity.RESULT_OK) { myAuthorizationConfirmed = true; } break; case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN: if (resultCode == Activity.RESULT_OK && data != null) { final CookieStore store = cookieStore(); final Map<String, String> cookies = (Map<String, String>) data .getSerializableExtra(NetworkLibraryActivity.COOKIES_KEY); if (cookies != null) { for (Map.Entry<String, String> entry : cookies.entrySet()) { final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue()); c.setDomain(data.getData().getHost()); c.setPath("/"); final Calendar expire = Calendar.getInstance(); expire.add(Calendar.YEAR, 1); c.setExpiryDate(expire.getTime()); c.setSecure(true); c.setDiscard(false); store.addCookie(c); } } } break; } } finally { if (processed) { synchronized (this) { notifyAll(); } } return processed; } }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.PostFragment.java
/** * Handles the return from the camera activity * /*from w w w .j a v a 2 s . c o m*/ * @param requestCode Type of activity requested * @param resultCode Code indicating activity success/failure * @param data Image data associated with the camera activity */ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { if (requestCode == ImageHelper.REQUEST_CAMERA) { Bitmap imageBitmap = null; try { imageBitmap = BitmapFactory.decodeStream( getActivity().getContentResolver().openInputStream(Uri.fromFile(imageFile))); } catch (FileNotFoundException e) { Toaster.toastShort("Error. Could not load image."); } Bitmap squareBitmap = ThumbnailUtils.extractThumbnail(imageBitmap, 100, 100); image = scaleImage(imageBitmap); imageThumb = squareBitmap; Bundle bundle = getArguments(); bundle.putParcelable("IMAGE_THUMB", imageThumb); bundle.putParcelable("IMAGE_FULL", image); } else if (requestCode == ImageHelper.REQUEST_GALLERY) { Bitmap imageBitmap = null; try { imageBitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data.getData()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Bitmap squareBitmap = ThumbnailUtils.extractThumbnail(imageBitmap, 100, 100); image = scaleImage(imageBitmap); imageThumb = squareBitmap; Bundle bundle = getArguments(); bundle.putParcelable("IMAGE_THUMB", imageThumb); bundle.putParcelable("IMAGE_FULL", image); } } }
From source file:com.example.office.ui.mail.MailItemFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case MailItemActivity.CAMERA_REQUEST_CODE: if (resultCode == Activity.RESULT_OK) { try { String currentPhotoPath = ((MailItemActivity) getActivity()).getCurrentPhotoPath(); Bitmap bmp = BitmapFactory.decodeFile(currentPhotoPath); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(CompressFormat.JPEG, 100, stream); MailItem mail = (MailItem) getActivity().getIntent().getExtras() .get(getString(R.string.intent_mail_key)); Utility.showToastNotification("Starting file uploading"); mId = mail.getId();//from w w w . ja v a2 s . c o m mImageBytes = stream.toByteArray(); mFilename = StringUtils.substringAfterLast(currentPhotoPath, "/"); getMessageAndAttachData(); } catch (Exception e) { Utility.showToastNotification("Error during getting image from camera"); } } break; case MailItemActivity.SELECT_PHOTO: if (resultCode == Activity.RESULT_OK) { try { Uri selectedImage = data.getData(); InputStream imageStream = getActivity().getContentResolver().openInputStream(selectedImage); MailItem mail = (MailItem) getActivity().getIntent().getExtras() .get(getString(R.string.intent_mail_key)); Utility.showToastNotification("Starting file uploading"); mId = mail.getId(); mImageBytes = IOUtils.toByteArray(imageStream); mFilename = selectedImage.getLastPathSegment(); getMessageAndAttachData(); } catch (Throwable t) { Utility.showToastNotification("Error during getting image from file"); } } break; default: super.onActivityResult(requestCode, resultCode, data); } }
From source file:com.markupartist.sthlmtraveling.RoutesActivity.java
private JourneyQuery getJourneyQueryFromIntent(Intent intent) { JourneyQuery journeyQuery;/*from ww w. j av a 2s .com*/ if (intent.hasExtra(EXTRA_JOURNEY_QUERY)) { journeyQuery = intent.getExtras().getParcelable(EXTRA_JOURNEY_QUERY); } else { journeyQuery = getJourneyQueryFromUri(intent.getData()); } return journeyQuery; }
From source file:br.com.bioscada.apps.biotracks.io.file.importer.ImportActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); importAll = intent.getBooleanExtra(EXTRA_IMPORT_ALL, false); trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT); if (trackFileFormat == null) { trackFileFormat = TrackFileFormat.GPX; }/*from w w w . j av a 2 s . com*/ if (!FileUtils.isExternalStorageAvailable()) { Toast.makeText(this, R.string.external_storage_not_available, Toast.LENGTH_LONG).show(); finish(); return; } String directoryPath; if (importAll) { directoryDisplayName = FileUtils.getPathDisplayName(trackFileFormat.getExtension()); directoryPath = FileUtils.getPath(trackFileFormat.getExtension()); if (!FileUtils.isDirectory(new File(directoryPath))) { Toast.makeText(this, getString(R.string.import_no_directory, directoryDisplayName), Toast.LENGTH_LONG).show(); finish(); return; } } else { String action = intent.getAction(); if (!(Intent.ACTION_ATTACH_DATA.equals(action) || Intent.ACTION_VIEW.equals(action))) { Log.d(TAG, "Invalid action: " + intent); finish(); return; } Uri data = intent.getData(); if (!UriUtils.isFileUri(data)) { Log.d(TAG, "Invalid data: " + intent); finish(); return; } directoryDisplayName = data.getPath(); directoryPath = data.getPath(); } Object retained = getLastNonConfigurationInstance(); if (retained instanceof ImportAsyncTask) { importAsyncTask = (ImportAsyncTask) retained; importAsyncTask.setActivity(this); } else { importAsyncTask = new ImportAsyncTask(this, importAll, trackFileFormat, directoryPath); importAsyncTask.execute(); } }
From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java
public void imageSharing(Intent data, String type) { // Get the Uri of the selected file Uri uri = data.getData(); Log.d("imageSharing - type", type + " @"); Log.d("File Uri: ", uri.toString() + " #"); // Get the path String path = null;/*w w w .jav a2 s .co m*/ try { path = getPath(this, uri); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d("File Path: ", path + " #"); if (path != null) { String userNum = prefs.getString(stored_user_country_code, "") + prefs.getString(stored_user_mobile_no, ""); String fileName = System.currentTimeMillis() + getFileFormat(path); String msg; if (type.equals("video")) { msg = "VID-" + userNum + "-" + fileName; } else if (type.equals("audio")) { msg = "AUD-" + userNum + "-" + fileName; } else { msg = "IMG-" + userNum + "-" + fileName; } String numb = prefs.getString(stored_chatuserNumber, ""); Log.d("nnumb", numb + " #"); String savefileuri = saveImage(path, fileName, stripNumber(numb)); if (savefileuri.equals(FILE_SIZE_ERROR + "")) { Toast toast = Toast.makeText(getApplicationContext(), "you upload file size is exceed to 30 MB", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (!savefileuri.equals("")) { Log.d("msg1", msg + " !"); sendInitmsg(msg, numb); new AsyncTaskUploadFile(savefileuri, msg).execute(); } else { Toast.makeText(getApplicationContext(), "File not found", Toast.LENGTH_SHORT).show(); } } }