List of usage examples for android.content Intent getDataString
public @Nullable String getDataString()
From source file:net.oschina.app.v2.activity.zxing.CaptureActivity.java
@Override protected void onResume() { super.onResume(); // historyManager must be initialized here to update the history preference // historyManager = new HistoryManager(this); // historyManager.trimHistory(); // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't // want to open the camera driver and measure the screen size if we're going to show the help on // first launch. That led to bugs where the scanning rectangle was the wrong size and partially // off screen. cameraManager = new CameraManager(getApplication()); viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); viewfinderView.setCameraManager(cameraManager); resultView = findViewById(R.id.result_view); statusView = (TextView) findViewById(R.id.status_view); handler = null;//from w w w . j a va 2 s. c om lastResult = null; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) { //setRequestedOrientation(getCurrentOrientation()); } else { //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } resetStatusView(); beepManager.updatePrefs(); ambientLightManager.start(cameraManager); inactivityTimer.onResume(); Intent intent = getIntent(); copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true) && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true)); source = IntentSource.NONE; sourceUrl = null; scanFromWebPageManager = null; decodeFormats = null; characterSet = null; if (intent != null) { String action = intent.getAction(); String dataString = intent.getDataString(); if (Intents.Scan.ACTION.equals(action)) { // Scan the formats the intent requested, and return the result to the calling activity. source = IntentSource.NATIVE_APP_INTENT; decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); decodeHints = DecodeHintManager.parseDecodeHints(intent); if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) { int width = intent.getIntExtra(Intents.Scan.WIDTH, 0); int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0); if (width > 0 && height > 0) { cameraManager.setManualFramingRect(width, height); } } if (intent.hasExtra(Intents.Scan.CAMERA_ID)) { int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1); if (cameraId >= 0) { cameraManager.setManualCameraId(cameraId); } } String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE); if (customPromptMessage != null) { statusView.setText(customPromptMessage); } } else if (dataString != null && dataString.contains("http://www.google") && dataString.contains("/m/products/scan")) { // Scan only products and send the result to mobile Product Search. source = IntentSource.PRODUCT_SEARCH_LINK; sourceUrl = dataString; decodeFormats = DecodeFormatManager.PRODUCT_FORMATS; } else if (isZXingURL(dataString)) { // Scan formats requested in query string (all formats if none specified). // If a return URL is specified, send the results there. Otherwise, handle it ourselves. source = IntentSource.ZXING_LINK; sourceUrl = dataString; Uri inputUri = Uri.parse(dataString); scanFromWebPageManager = new ScanFromWebPageManager(inputUri); decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri); // Allow a sub-set of the hints to be specified by the caller. decodeHints = DecodeHintManager.parseDecodeHints(inputUri); } characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET); } SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { // The activity was paused but not stopped, so the surface still exists. Therefore // surfaceCreated() won't be called, so init the camera here. initCamera(surfaceHolder); } else { // Install the callback and wait for surfaceCreated() to init the camera. surfaceHolder.addCallback(this); } }
From source file:org.dkf.jmule.activities.MainActivity.java
private void openTorrentUrl(Intent intent) { try {//from ww w .ja v a 2 s .co m //Open a Torrent from a URL or from a local file :), say from Astro File Manager. //Show me the transfer tab Intent i = new Intent(this, MainActivity.class); i.setAction(ED2KService.ACTION_SHOW_TRANSFERS); i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(i); //go! final String uri = intent.getDataString(); intent.setAction(null); if (uri != null) { if (uri.startsWith("file") || uri.startsWith("http") || uri.startsWith("https") || uri.startsWith("magnet")) { //TransferManager.instance().downloadTorrent(uri, new HandpickedTorrentDownloadDialogOnFetch(this)); } else if (uri.startsWith("content")) { String newUri = saveViewContent(this, Uri.parse(uri), "content-intent.torrent"); if (newUri != null) { //TransferManager.instance().downloadTorrent(newUri, new HandpickedTorrentDownloadDialogOnFetch(this)); } } } else { log.warn( "MainActivity.onNewIntent(): Couldn't start torrent download from Intent's URI, intent.getDataString() -> null"); log.warn("(maybe URI is coming in another property of the intent object - #fragmentation)"); } } catch (Throwable e) { log.error("Error opening torrent from intent", e); } }
From source file:com.hybris.mobile.app.commerce.fragment.ProductDetailFragmentBase.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_product_detail, container, false); // Initialize View by linking and giving instance to xml element in the // layout/*from w ww . j a v a 2s . co m*/ mCloseProductDetailButton = (ImageButton) view.findViewById(R.id.product_detail_exit); mProductDetaiNameText = (TextView) view.findViewById(R.id.product_detail_name); mOrderFormButton = (ImageButton) view.findViewById(R.id.product_detail_order_form); mViewPager = (ViewPager) view.findViewById(R.id.product_detail_view_pager); mImageAdapter = new ImagePagerAdapter(new ArrayList<Image>()); mLayoutIndicator = (LinearLayout) view.findViewById(R.id.product_detail_view_pager_indicator_bar); mProductPrice = (TextView) view.findViewById(R.id.product_detail_volume_price); mVolumePricingExpandableButton = (Button) view.findViewById(R.id.product_detail_volume_pricing_button); mVolumePricingExpandableLayout = (TableLayout) view .findViewById(R.id.product_detail_volume_pricing_table_layout); mProductDetailDescriptionLayout = (LinearLayout) view.findViewById(R.id.product_detail_description_layout); mProductShortDescription = (TextView) view.findViewById(R.id.product_detail_short_description); mStocklevelText = (TextView) view.findViewById(R.id.product_detail_stocklevel_text); mTotalPriceText = (TextView) view.findViewById(R.id.product_detail_total_price_text); mQuantityEditText = (EditText) view.findViewById(R.id.product_detail_quantity_editText); mAddToCartButton = (LinearLayout) view.findViewById(R.id.product_detail_add_to_cart_layout_button); mProductDetailAddToCartText = (TextView) view.findViewById(R.id.product_detail_add_to_cart_text); mProductDetailExpandableButton = (Button) view.findViewById(R.id.product_detail_expandable_button); mProductDetailExpandableText = (TextView) view.findViewById(R.id.product_detail_expandable_text); mDeliveryExpandableButton = (Button) view.findViewById(R.id.product_detail_delivery_expandable_button); mDeliveryExpandableText = (TextView) view.findViewById(R.id.product_detail_delivery_expandable_text); mProductDetailVariantSpinner1 = (Spinner) view.findViewById(R.id.product_detail_variant_spinner_1); mProductDetailVariantSpinner2 = (Spinner) view.findViewById(R.id.product_detail_variant_spinner_2); mProductDetailVariantSpinner3 = (Spinner) view.findViewById(R.id.product_detail_variant_spinner_3); mStocklevelTextLoading = (ProgressBar) view.findViewById(R.id.product_detail_stocklevel_text_loading); mNoImage = view.findViewById(R.id.product_item_no_image); mRatingBar = (RatingBar) view.findViewById(R.id.product_detail_rating); mReviews = (TextView) view.findViewById(R.id.product_detail_reviews); mReviews.setOnClickListener(mReviewOnClickListener); // Zoom UI mProductDetailScrollView = (ScrollView) view.findViewById(R.id.product_detail_scrollView); mScrollViewLayout = (LinearLayout) view.findViewById(R.id.product_detail_scrollView_layout); mImageLayout = (LinearLayout) view.findViewById(R.id.product_detail_image_layout); mMiddleSection = (LinearLayout) view.findViewById(R.id.product_detail_middle_section); mBottomSection = (LinearLayout) view.findViewById(R.id.product_detail_bottom_section); mViewDivider = view.findViewById(R.id.product_detail_middle_divider); // Only show description when not blank mProductDetailDescriptionLayout.setVisibility(View.GONE); // Listener mCloseProductDetailButton.setOnClickListener(exitProductDetailButtonListener); mOrderFormButton.setOnClickListener(orderFormButtonListener); mViewPager.setOnTouchListener(imageViewPagerOnTouchListener); mViewPager.addOnPageChangeListener(imageViewPagerOnPageChangeListener); mVolumePricingExpandableButton.setOnClickListener(expandableLayoutListener); mProductDetailExpandableButton.setOnClickListener( new ExpandablePanelListener(mProductDetailExpandableButton, mProductDetailExpandableText)); mDeliveryExpandableButton.setOnClickListener( new ExpandablePanelListener(mDeliveryExpandableButton, mDeliveryExpandableText)); mQuantityEditText.setOnFocusChangeListener(quantityEditTextListener); mAddToCartButton.setOnClickListener(addToCartButtonListener); mProductDetailVariantSpinner1.setOnItemSelectedListener(getVariantSpinnerListener()); mProductDetailVariantSpinner2.setOnItemSelectedListener(getVariantSpinnerListener()); mProductDetailVariantSpinner3.setOnItemSelectedListener(getVariantSpinnerListener()); mSpinnersVariants = new ArrayList<>(); mSpinnersVariants.add(mProductDetailVariantSpinner1); mSpinnersVariants.add(mProductDetailVariantSpinner2); mSpinnersVariants.add(mProductDetailVariantSpinner3); mQuantityEditText.addTextChangedListener(quantityEditTextTextWatcher); mQuantityEditText.setOnEditorActionListener(new SubmitListener() { @Override public void onSubmitAction() { addToCart(); } }); // When clicking outside a EditText, hide keyboard, remove focus and // reset to the default value // Clicking on the main view view.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { UIUtils.hideKeyboard(getActivity()); mQuantityEditText.clearFocus(); v.performClick(); return false; } }); Intent intentCaller = getActivity().getIntent(); // Query object to get the products details mQueryProduct = new QueryProduct(); if (intentCaller.hasExtra(IntentConstants.PRODUCT_CODE)) { mQueryProduct.setCode(getActivity().getIntent().getStringExtra(IntentConstants.PRODUCT_CODE)); } else if (StringUtils.equals(intentCaller.getAction(), Intent.ACTION_VIEW)) { mQueryProduct.setCode(RegexUtils.getProductCode(intentCaller.getDataString())); } // Restore the current spinner selection if (savedInstanceState != null) { if (savedInstanceState.containsKey(SAVED_INSTANCE_PRODUCT_CODE)) { mQueryProduct.setCode(savedInstanceState.getString(SAVED_INSTANCE_PRODUCT_CODE, null)); } } mProductLoader = getProductLoader(getActivity(), CommerceApplication.getContentServiceHelper(), mQueryProduct, new OnRequestListener() { @Override public void beforeRequest() { afterBeforeRequest(true); } @Override public void afterRequestBeforeResponse() { } @Override public void afterRequest(boolean isDataSynced) { afterBeforeRequest(false); } }); return view; }
From source file:com.owncloud.android.files.InstantUploadBroadcastReceiver.java
private void handleNewPictureAction(Context context, Intent intent) { Cursor c = null;/*from www . ja v a 2 s.c o m*/ String file_path = null; String file_name = null; String mime_type = null; long date_taken = 0; Log_OC.i(TAG, "New photo received"); if (!PreferenceManager.instantPictureUploadEnabled(context)) { Log_OC.d(TAG, "Instant picture upload disabled, ignoring new picture"); return; } Account account = AccountUtils.getCurrentOwnCloudAccount(context); if (account == null) { Log_OC.w(TAG, "No account found for instant upload, aborting"); return; } String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE, Images.Media.SIZE }; int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE); if (android.content.pm.PackageManager.PERMISSION_GRANTED != permissionCheck) { Log_OC.w(TAG, "Read external storage permission isn't granted, aborting"); return; } c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null); if (!c.moveToFirst()) { Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString()); return; } file_path = c.getString(c.getColumnIndex(Images.Media.DATA)); file_name = c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME)); mime_type = c.getString(c.getColumnIndex(Images.Media.MIME_TYPE)); date_taken = System.currentTimeMillis(); c.close(); if (file_path.equals(lastUploadedPhotoPath)) { Log_OC.d(TAG, "Duplicate detected: " + file_path + ". Ignore."); return; } lastUploadedPhotoPath = file_path; Log_OC.d(TAG, "Path: " + file_path + ""); new FileUploader.UploadRequester(); int behaviour = getUploadBehaviour(context); Boolean subfolderByDate = PreferenceManager.instantPictureUploadPathUseSubfolders(context); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); String uploadPathdef = context.getString(R.string.instant_upload_path); String uploadPath = pref.getString("instant_upload_path", uploadPathdef); FileUploader.UploadRequester requester = new FileUploader.UploadRequester(); requester.uploadNewFile(context, account, file_path, FileStorageUtils.getInstantUploadFilePath(uploadPath, file_name, date_taken, subfolderByDate), behaviour, mime_type, true, // create parent folder if not existent UploadFileOperation.CREATED_AS_INSTANT_PICTURE); }
From source file:org.transdroid.core.gui.TorrentsActivity.java
/** * If required, add torrents from the supplied intent extras. *//* w ww . j a v a2 s. co m*/ protected void addFromIntent() { Intent intent = getIntent(); Uri dataUri = intent.getData(); String data = intent.getDataString(); String action = intent.getAction(); // Adding multiple torrents at the same time (as found in the Intent extras Bundle) if (action != null && action.equals("org.transdroid.ADD_MULTIPLE")) { // Intent should have some extras pointing to possibly multiple torrents String[] urls = intent.getStringArrayExtra("TORRENT_URLS"); String[] titles = intent.getStringArrayExtra("TORRENT_TITLES"); if (urls != null) { for (int i = 0; i < urls.length; i++) { String title = (titles != null && titles.length >= i ? titles[i] : NavigationHelper.extractNameFromUri(Uri.parse(urls[i]))); if (intent.hasExtra("PRIVATE_SOURCE")) { // This is marked by the Search Module as being a private source site; get the url locally first addTorrentFromPrivateSource(urls[i], title, intent.getStringExtra("PRIVATE_SOURCE")); } else { addTorrentByUrl(urls[i], title); } } } return; } // Add a torrent from a local or remote data URI? if (dataUri == null) { return; } if (dataUri.getScheme() == null) { SnackbarManager .show(Snackbar.with(this).text(R.string.error_invalid_url_form).colorResource(R.color.red)); return; } // Get torrent title String title = NavigationHelper.extractNameFromUri(dataUri); if (intent.hasExtra("TORRENT_TITLE")) { title = intent.getStringExtra("TORRENT_TITLE"); } // Adding a torrent from the Android downloads manager if (dataUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { addTorrentFromDownloads(dataUri, title); return; } // Adding a torrent from http or https URL if (dataUri.getScheme().equals("http") || dataUri.getScheme().equals("https")) { String privateSource = getIntent().getStringExtra("PRIVATE_SOURCE"); WebsearchSetting match = null; if (privateSource == null) { // Check if the target URL is also defined as a web search in the user's settings List<WebsearchSetting> websearches = applicationSettings.getWebsearchSettings(); for (WebsearchSetting setting : websearches) { Uri uri = Uri.parse(setting.getBaseUrl()); if (uri.getHost() != null && uri.getHost().equals(dataUri.getHost())) { match = setting; break; } } } // If the URL is also a web search and it defines cookies, use the cookies by downloading the targeted // torrent file (while supplies the cookies to the HTTP request) instead of sending the URL directly to the // torrent client. If instead it is marked (by the Torrent Search module) as being form a private site, use // the Search Module instead to download the url locally first. if (match != null && match.getCookies() != null) { addTorrentFromWeb(data, match, title); } else if (privateSource != null) { addTorrentFromPrivateSource(data, title, privateSource); } else { // Normally send the URL to the torrent client addTorrentByUrl(data, title); } return; } // Adding a torrent from magnet URL if (dataUri.getScheme().equals("magnet")) { addTorrentByMagnetUrl(data, title); return; } // Adding a local .torrent file; the title we show is just the file name if (dataUri.getScheme().equals("file")) { addTorrentByFile(data, title); } }
From source file:org.zirco.ui.activities.MainActivity.java
/** * Handle url request from external apps. * @param intent The intent./*from w ww. j a va 2 s. co m*/ */ @Override protected void onNewIntent(Intent intent) { if (intent.getData() != null) { addTab(false); navigateToUrl(intent.getDataString()); } setIntent(intent); super.onNewIntent(intent); }
From source file:com.android.launcher3.Utilities.java
/** * Returns true if the intent is a valid launch intent for a launcher activity of an app. * This is used to identify shortcuts which are different from the ones exposed by the * applications' manifest file./*from w w w .ja va 2 s . com*/ * * @param launchIntent The intent that will be launched when the shortcut is clicked. */ public static boolean isLauncherAppTarget(Intent launchIntent) { if (launchIntent != null && Intent.ACTION_MAIN.equals(launchIntent.getAction()) && launchIntent.getComponent() != null && launchIntent.getCategories() != null && launchIntent.getCategories().size() == 1 && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && TextUtils.isEmpty(launchIntent.getDataString())) { // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE. Bundle extras = launchIntent.getExtras(); if (extras == null) { return true; } else { Set<String> keys = extras.keySet(); return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE); } } ; return false; }
From source file:im.vector.receiver.VectorUniversalLinkReceiver.java
@Override public void onReceive(final Context aContext, final Intent aIntent) { String action, uriString;/*from ww w . jav a2s. co m*/ Uri intentUri; Log.d(LOG_TAG, "## onReceive() IN"); // get session mSession = Matrix.getInstance(aContext).getDefaultSession(); // user is not yet logged in if (null == mSession) { Log.e(LOG_TAG, "## onReceive() Warning - Unable to proceed URL link: Session is null"); // No user is logged => no session. Just forward request to the login activity Intent intent = new Intent(aContext, LoginActivity.class); intent.putExtra(EXTRA_UNIVERSAL_LINK_URI, aIntent.getData()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); aContext.startActivity(intent); return; } // sanity check if (null != aIntent) { action = aIntent.getAction(); uriString = aIntent.getDataString(); boolean isSessionActive = mSession.isAlive(); boolean isLoginStepDone = mSession.getDataHandler().isInitialSyncComplete(); Log.d(LOG_TAG, "## onReceive() uri getDataString=" + uriString + "isSessionActive=" + isSessionActive + " isLoginStepDone=" + isLoginStepDone); if (TextUtils.equals(action, BROADCAST_ACTION_UNIVERSAL_LINK)) { Log.d(LOG_TAG, "## onReceive() action = BROADCAST_ACTION_UNIVERSAL_LINK"); intentUri = aIntent.getData(); } else if (TextUtils.equals(action, BROADCAST_ACTION_UNIVERSAL_LINK_RESUME)) { Log.d(LOG_TAG, "## onReceive() action = BROADCAST_ACTION_UNIVERSAL_LINK_RESUME"); // A first BROADCAST_ACTION_UNIVERSAL_LINK has been received with a room alias that could not be translated to a room ID. // Translation has been asked to server, and the response is processed here. // ...................... intentUri = aIntent.getParcelableExtra(EXTRA_UNIVERSAL_LINK_URI); // aIntent.getParcelableExtra(EXTRA_UNIVERSAL_LINK_SENDER_ID); } else { // unknown action (very unlikely) Log.e(LOG_TAG, "## onReceive() Unknown action received (" + action + ") - unable to proceed URL link"); return; } if (null != intentUri) { Log.d(LOG_TAG, "## onCreate() intentUri - host=" + intentUri.getHost() + " path=" + intentUri.getPath() + " queryParams=" + intentUri.getQuery()); //intentUri.getEncodedSchemeSpecificPart() = //vector.im/beta/ intentUri.getSchemeSpecificPart() = //vector.im/beta/ HashMap<String, String> params = parseUniversalLink(intentUri); if (null != params) { if (!isSessionActive) { Log.w(LOG_TAG, "## onReceive() Warning: Session is not alive"); } if (!isLoginStepDone) { Log.w(LOG_TAG, "## onReceive() Warning: Session is not complete - start Login Activity"); // Start the login activity and wait for BROADCAST_ACTION_UNIVERSAL_LINK_RESUME. // Once the login process flow is complete, BROADCAST_ACTION_UNIVERSAL_LINK_RESUME is // sent back to resume the URL link processing. Intent intent = new Intent(aContext, LoginActivity.class); intent.putExtra(EXTRA_UNIVERSAL_LINK_URI, aIntent.getData()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); aContext.startActivity(intent); } else { mParameters = params; if (mParameters.containsKey(ULINK_ROOM_ID_OR_ALIAS_KEY)) { manageRoomOnActivity(aContext); } else if (mParameters.containsKey(ULINK_MATRIX_USER_ID_KEY)) { manageMemberDetailsActivity(aContext); } else if (mParameters.containsKey(ULINK_GROUP_ID_KEY)) { manageGroupDetailsActivity(aContext); } else { Log.e(LOG_TAG, "## onReceive() : nothing to do"); } } } else { Log.e(LOG_TAG, "## onReceive() Path not supported: " + intentUri.getPath()); } } } }
From source file:com.github.dfa.diaspora_android.activity.DiasporaStreamFragment.java
public void onImageUploadResult(int requestCode, int resultCode, Intent data) { AppLog.d(this, "onImageUploadResult"); switch (requestCode) { case MainActivity.INPUT_FILE_REQUEST_CODE_NEW: { AppLog.v(this, "Upload image using recent method (Lollipop+)"); if (imageUploadFilePathCallbackNew == null || resultCode != Activity.RESULT_OK) { AppLog.e(this, "Callback is null: " + (imageUploadFilePathCallbackNew == null) + " resultCode: " + resultCode);/*from w ww . j a v a 2 s.co m*/ if (imageUploadFilePathCallbackNew != null) imageUploadFilePathCallbackNew.onReceiveValue(new Uri[] {}); return; } Uri[] results = null; if (data == null) { if (mCameraPhotoPath != null) { AppLog.v(this, "Intent data is null. Try to parse cameraPhotoPath"); results = new Uri[] { Uri.parse(mCameraPhotoPath) }; } else { AppLog.w(this, "Intent data is null and cameraPhotoPath is null"); } } else { String dataString = data.getDataString(); if (dataString != null) { AppLog.v(this, "Intent has data. Try to parse dataString"); results = new Uri[] { Uri.parse(dataString) }; } else { AppLog.w(this, "dataString is null"); } } AppLog.v(this, "handle received result over to callback"); imageUploadFilePathCallbackNew.onReceiveValue(results); imageUploadFilePathCallbackNew = null; return; } case MainActivity.INPUT_FILE_REQUEST_CODE_OLD: { AppLog.v(this, "Upload image using legacy method (Jelly Bean, Kitkat)"); if (imageUploadFilePathCallbackOld == null || resultCode != Activity.RESULT_OK) { AppLog.e(this, "Callback is null: " + (imageUploadFilePathCallbackOld == null) + " resultCode: " + resultCode); if (imageUploadFilePathCallbackOld != null) imageUploadFilePathCallbackOld.onReceiveValue(null); return; } Uri results = null; if (data == null) { if (mCameraPhotoPath != null) { AppLog.v(this, "Intent has no data. Try to parse cameraPhotoPath"); results = Uri.parse(mCameraPhotoPath); } else { AppLog.w(this, "Intent has no data and cameraPhotoPath is null"); } } else { String dataString = data.getDataString(); if (dataString != null) { AppLog.v(this, "Intent has data. Try to parse dataString"); results = Uri.parse(dataString); } else { AppLog.w(this, "dataString is null"); } } AppLog.v(this, "handle received result over to callback"); imageUploadFilePathCallbackOld.onReceiveValue(results); imageUploadFilePathCallbackOld = null; } } }
From source file:com.cerema.cloud2.files.InstantUploadBroadcastReceiver.java
private void handleNewPictureAction(Context context, Intent intent) { Cursor c = null;/*w w w . jav a2 s .com*/ String file_path = null; String file_name = null; String mime_type = null; Log_OC.w(TAG, "New photo received"); if (!instantPictureUploadEnabled(context)) { Log_OC.d(TAG, "Instant picture upload disabled, ignoring new picture"); return; } Account account = AccountUtils.getCurrentOwnCloudAccount(context); if (account == null) { Log_OC.w(TAG, "No account found for instant upload, aborting"); return; } String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE, Images.Media.SIZE }; int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE); if (android.content.pm.PackageManager.PERMISSION_GRANTED != permissionCheck) { Log_OC.w(TAG, "Read external storage permission isn't granted, aborting"); return; } c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null); if (!c.moveToFirst()) { Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString()); return; } file_path = c.getString(c.getColumnIndex(Images.Media.DATA)); file_name = c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME)); mime_type = c.getString(c.getColumnIndex(Images.Media.MIME_TYPE)); c.close(); Log_OC.d(TAG, file_path + ""); // save always temporally the picture to upload DbHandler db = new DbHandler(context); db.putFileForLater(file_path, account.name, null); db.close(); if (!isOnline(context) || (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))) { return; } Intent i = new Intent(context, FileUploader.class); i.putExtra(FileUploader.KEY_ACCOUNT, account); i.putExtra(FileUploader.KEY_LOCAL_FILE, file_path); i.putExtra(FileUploader.KEY_REMOTE_FILE, FileStorageUtils.getInstantUploadFilePath(context, file_name)); i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE); i.putExtra(FileUploader.KEY_MIME_TYPE, mime_type); i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true); // instant upload behaviour i = addInstantUploadBehaviour(i, context); context.startService(i); }