List of usage examples for android.content Intent getDataString
public @Nullable String getDataString()
From source file:cn.devit.app.ip_messenger.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { System.out.println("activity result:" + requestCode + ":" + resultCode); if (resultCode == RESULT_OK) { System.out.println("request code:" + requestCode); switch (requestCode) { case PICKFILE_RESULT_CODE: default://from w w w. ja v a2 s .c o m File file; try { file = new File(new URI(data.getDataString())); attaches.add(file); System.out.println("attach url:" + data.getDataString()); } catch (URISyntaxException e) { e.printStackTrace(); } break; } } else { System.out.println("result code is not ok."); } }
From source file:com.owncloud.android.services.observer.InstantUploadsHandler.java
public boolean handleNewVideoAction(Intent intent, InstantUploadsConfiguration configuration, Context context) { Log_OC.i(TAG, "New video received"); if (!configuration.isEnabledForVideos()) { Log_OC.d(TAG, "Instant upload disabled for videos, ignoring new video"); return false; }/*from w w w. j av a2 s . co m*/ /// retrieve file data from MediaStore String[] CONTENT_PROJECTION = { MediaStore.Video.Media.DATA, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.MIME_TYPE, MediaStore.Video.Media.SIZE }; Cursor c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null); if (c == null || !c.moveToFirst()) { Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString()); if (c != null) { c.close(); } return false; } String localPath = c.getString(c.getColumnIndex(MediaStore.Video.Media.DATA)); String fileName = c.getString(c.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME)); String mimeType = c.getString(c.getColumnIndex(MediaStore.Video.Media.MIME_TYPE)); c.close(); Log_OC.d(TAG, "Local path: " + localPath); return handleNewMediaFile(fileName, localPath, mimeType, false, configuration, context); }
From source file:org.quantumbadger.redreader.activities.ImageViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences); if (solidblack) getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); final Intent intent = getIntent(); mUrl = General.uriFromString(intent.getDataString()); final RedditPost src_post = intent.getParcelableExtra("post"); if (mUrl == null) { General.quickToast(this, "Invalid URL. Trying web browser."); revertToWeb();//w ww.ja v a2s . c om return; } Log.i("ImageViewActivity", "Loading URL " + mUrl.toString()); final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal); final LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(progressBar); CacheManager.getInstance(this) .makeRequest(mRequest = new CacheRequest(mUrl, RedditAccountManager.getAnon(), null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, this) { private void setContentView(View v) { layout.removeAllViews(); layout.addView(v); v.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; v.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context.getApplicationContext(), new RRError(null, null, t)); } @Override protected void onDownloadNecessary() { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { progressBar.setVisibility(View.VISIBLE); progressBar.setIndeterminate(true); } }); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(final RequestFailureType type, Throwable t, StatusLine status, final String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, url.toString()); AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { // TODO handle properly mRequest = null; progressBar.setVisibility(View.GONE); layout.addView(new ErrorView(ImageViewActivity.this, error)); } }); } @Override protected void onProgress(final boolean authorizationInProgress, final long bytesRead, final long totalBytes) { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { progressBar.setVisibility(View.VISIBLE); progressBar.setIndeterminate(authorizationInProgress); progressBar.setProgress((int) ((100 * bytesRead) / totalBytes)); } }); } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, final String mimetype) { if (mimetype == null || (!Constants.Mime.isImage(mimetype) && !Constants.Mime.isVideo(mimetype))) { revertToWeb(); return; } final InputStream cacheFileInputStream; try { cacheFileInputStream = cacheFile.getInputStream(); } catch (IOException e) { notifyFailure(RequestFailureType.PARSE, e, null, "Could not read existing cached image."); return; } if (cacheFileInputStream == null) { notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image"); return; } if (Constants.Mime.isVideo(mimetype)) { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { if (mIsDestroyed) return; mRequest = null; try { final RelativeLayout layout = new RelativeLayout(context); layout.setGravity(Gravity.CENTER); final VideoView videoView = new VideoView(ImageViewActivity.this); videoView.setVideoURI(cacheFile.getUri()); layout.addView(videoView); setContentView(layout); layout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; layout.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; videoView.setLayoutParams( new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.setLooping(true); videoView.start(); } }); videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(final MediaPlayer mediaPlayer, final int i, final int i1) { revertToWeb(); return true; } }); videoView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent motionEvent) { finish(); return true; } }); } catch (OutOfMemoryError e) { General.quickToast(context, R.string.imageview_oom); revertToWeb(); } catch (Throwable e) { General.quickToast(context, R.string.imageview_invalid_video); revertToWeb(); } } }); } else if (Constants.Mime.isImageGif(mimetype)) { final PrefsUtility.GifViewMode gifViewMode = PrefsUtility .pref_behaviour_gifview_mode(context, sharedPreferences); if (gifViewMode == PrefsUtility.GifViewMode.INTERNAL_BROWSER) { revertToWeb(); return; } else if (gifViewMode == PrefsUtility.GifViewMode.EXTERNAL_BROWSER) { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { LinkHandler.openWebBrowser(ImageViewActivity.this, Uri.parse(mUrl.toString())); finish(); } }); return; } if (AndroidApi.isIceCreamSandwichOrLater() && gifViewMode == PrefsUtility.GifViewMode.INTERNAL_MOVIE) { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { if (mIsDestroyed) return; mRequest = null; try { final GIFView gifView = new GIFView(ImageViewActivity.this, cacheFileInputStream); setContentView(gifView); gifView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); } catch (OutOfMemoryError e) { General.quickToast(context, R.string.imageview_oom); revertToWeb(); } catch (Throwable e) { General.quickToast(context, R.string.imageview_invalid_gif); revertToWeb(); } } }); } else { gifThread = new GifDecoderThread(cacheFileInputStream, new GifDecoderThread.OnGifLoadedListener() { public void onGifLoaded() { AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { if (mIsDestroyed) return; mRequest = null; imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); setContentView(imageView); gifThread.setView(imageView); imageView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); } }); } public void onOutOfMemory() { General.quickToast(context, R.string.imageview_oom); revertToWeb(); } public void onGifInvalid() { General.quickToast(context, R.string.imageview_invalid_gif); revertToWeb(); } }); gifThread.start(); } } else { final ImageTileSource imageTileSource; try { final long bytes = cacheFile.getSize(); final byte[] buf = new byte[(int) bytes]; try { new DataInputStream(cacheFileInputStream).readFully(buf); } catch (IOException e) { throw new RuntimeException(e); } try { imageTileSource = new ImageTileSourceWholeBitmap(buf); } catch (Throwable t) { Log.e("ImageViewActivity", "Exception when creating ImageTileSource", t); General.quickToast(context, R.string.imageview_decode_failed); revertToWeb(); return; } } catch (OutOfMemoryError e) { General.quickToast(context, R.string.imageview_oom); revertToWeb(); return; } AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { public void run() { if (mIsDestroyed) return; mRequest = null; mImageViewDisplayerManager = new ImageViewDisplayListManager(imageTileSource, ImageViewActivity.this); surfaceView = new RRGLSurfaceView(ImageViewActivity.this, mImageViewDisplayerManager); setContentView(surfaceView); surfaceView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); if (mIsPaused) { surfaceView.onPause(); } else { surfaceView.onResume(); } } }); } } }); final RedditPreparedPost post = src_post == null ? null : new RedditPreparedPost(this, CacheManager.getInstance(this), 0, src_post, -1, false, false, false, false, RedditAccountManager.getInstance(this).getDefaultAccount(), false); final FrameLayout outerFrame = new FrameLayout(this); outerFrame.addView(layout); if (post != null) { final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(this); final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(this, new BezelSwipeOverlay.BezelSwipeListener() { public boolean onSwipe(BezelSwipeOverlay.SwipeEdge edge) { toolbarOverlay.setContents( post.generateToolbar(ImageViewActivity.this, false, toolbarOverlay)); toolbarOverlay.show(edge == BezelSwipeOverlay.SwipeEdge.LEFT ? SideToolbarOverlay.SideToolbarPosition.LEFT : SideToolbarOverlay.SideToolbarPosition.RIGHT); return true; } public boolean onTap() { if (toolbarOverlay.isShown()) { toolbarOverlay.hide(); return true; } return false; } }); outerFrame.addView(bezelOverlay); outerFrame.addView(toolbarOverlay); bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT; } setContentView(outerFrame); }
From source file:org.fdroid.fdroid.net.DownloaderService.java
/** * This method is invoked on the worker thread with a request to process. * Only one Intent is processed at a time, but the processing happens on a * worker thread that runs independently from other application logic. * So, if this code takes a long time, it will hold up other requests to * the same DownloaderService, but it will not hold up anything else. * When all requests have been handled, the DownloaderService stops itself, * so you should not ever call {@link #stopSelf}. * <p/>//from ww w .j a v a 2 s.c om * Downloads are put into subdirectories based on hostname/port of each repo * to prevent files with the same names from conflicting. Each repo enforces * unique APK file names on the server side. * * @param intent The {@link Intent} passed via {@link * android.content.Context#startService(Intent)}. */ protected void handleIntent(Intent intent) { final Uri uri = intent.getData(); File downloadDir = new File(Utils.getApkCacheDir(this), uri.getHost() + "-" + uri.getPort()); downloadDir.mkdirs(); final SanitizedFile localFile = new SanitizedFile(downloadDir, uri.getLastPathSegment()); final String packageName = getPackageNameFromIntent(intent); sendBroadcast(uri, Downloader.ACTION_STARTED, localFile); if (Preferences.get().isUpdateNotificationEnabled()) { Notification notification = createNotification(intent.getDataString(), getPackageNameFromIntent(intent)) .build(); startForeground(NOTIFY_DOWNLOADING, notification); } try { downloader = DownloaderFactory.create(this, uri, localFile); downloader.setListener(new Downloader.DownloaderProgressListener() { @Override public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) { if (isActive(uri.toString())) { Intent intent = new Intent(Downloader.ACTION_PROGRESS); intent.setData(uri); intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead); intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes); localBroadcastManager.sendBroadcast(intent); if (Preferences.get().isUpdateNotificationEnabled()) { NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = createNotification(uri.toString(), packageName) .setProgress(totalBytes, bytesRead, false).build(); nm.notify(NOTIFY_DOWNLOADING, notification); } } } }); downloader.download(); sendBroadcast(uri, Downloader.ACTION_COMPLETE, localFile); DownloadCompleteService.notify(this, packageName, intent.getDataString()); } catch (InterruptedException e) { sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile); } catch (IOException e) { e.printStackTrace(); sendBroadcast(uri, Downloader.ACTION_INTERRUPTED, localFile, e.getLocalizedMessage()); } finally { if (downloader != null) { downloader.close(); } // May have already been removed in response to a cancel intent, but that wont cause // problems if we ask to remove it again. QUEUE_WHATS.remove(uri.toString()); stopForeground(true); } downloader = null; }
From source file:com.owncloud.android.services.observer.InstantUploadsHandler.java
public boolean handleNewPictureAction(Intent intent, InstantUploadsConfiguration configuration, Context context) {/* w w w . ja v a 2 s . co m*/ Log_OC.i(TAG, "New photo received"); if (!configuration.isEnabledForPictures()) { Log_OC.d(TAG, "Instant upload disabled for images, ignoring new picture"); return false; } /// retrieve file data from MediaStore String[] CONTENT_PROJECTION = { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.MIME_TYPE, MediaStore.Images.Media.SIZE }; Cursor c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null); if (c == null || !c.moveToFirst()) { Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString()); if (c != null) { c.close(); } return false; } String localPath = c.getString(c.getColumnIndex(MediaStore.Images.Media.DATA)); String fileName = c.getString(c.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME)); String mimeType = c.getString(c.getColumnIndex(MediaStore.Images.Media.MIME_TYPE)); c.close(); Log_OC.d(TAG, "Local path: " + localPath); return handleNewMediaFile(fileName, localPath, mimeType, true, configuration, context); }
From source file:com.breadwallet.presenter.activities.MainActivity.java
private void setUrlHandler(Intent intent) { Uri data = intent.getData();/*from w w w . j a v a 2 s . com*/ if (data == null) return; String scheme = data.getScheme(); if (scheme != null && (scheme.startsWith("bitcoin") || scheme.startsWith("bitid"))) { String str = intent.getDataString(); RequestHandler.processRequest(this, str); } }
From source file:com.coinblesk.client.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPrefUtils.initDefaults(this, R.xml.settings_pref, false); final AppConfig appConfig = ((CoinbleskApp) getApplication()).getAppConfig(); try {/*from ww w . j a v a 2s.c o m*/ AdditionalServiceUtils.setSessionID(this, null); } catch (Exception e) { Log.e(TAG, "Could not set sessionID: ", e); } UpgradeUtils upgradeUtils = new UpgradeUtils(); upgradeUtils.checkUpgrade(this, appConfig.getNetworkParameters()); startWalletService(false); setContentView(R.layout.activity_main); initToolbar(); initNavigationView(); initViewPager(); final Intent intent = getIntent(); final String scheme = intent.getScheme(); if (scheme != null && scheme.equals(appConfig.getNetworkParameters().getUriScheme())) { final String uri = intent.getDataString(); try { BitcoinURI bitcoinURI = new BitcoinURI(uri); SendDialogFragment.newInstance(bitcoinURI.getAddress(), bitcoinURI.getAmount()) .show(getFragmentManager(), "send-dialog"); } catch (BitcoinURIParseException e) { Log.w(TAG, "Could not parse Bitcoin URI: " + uri); } } ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, FINE_LOCATION_PERMISSION_REQUEST); checkVersionCompatibility(appConfig); }
From source file:net.eledge.android.europeana.gui.activity.RecordActivity.java
private void handleIntent(Intent intent) { String id = null;/*from w ww .j a v a2 s . com*/ if (intent != null) { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present id = new String(msg.getRecords()[0].getPayload()); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { id = StringUtils.defaultIfBlank(intent.getDataString(), intent.getStringExtra(RECORD_ID)); } if (StringUtils.contains(id, "europeana.eu/")) { Uri uri = Uri.parse(id); List<String> paths = uri.getPathSegments(); if ((paths != null) && (paths.size() == 4)) { String collectionId = paths.get(paths.size() - 2); String recordId = StringUtils.removeEnd(paths.get(paths.size() - 1), ".html"); id = StringUtils.join("/", collectionId, "/", recordId); } else { // invalid url/id, cancel opening record id = null; } } if (StringUtils.isNotBlank(id)) { openRecord(id); } } }
From source file:org.openremote.android.console.AppSettingsActivity.java
/** * Received custom server from AddServerActivity, add prefix "http://" before it. * Add the result in custom server list and set it as current server. * /* w w w . j a v a2s .c om*/ * @see android.app.Activity#onActivityResult(int, int, android.content.Intent) */ @SuppressWarnings("unchecked") @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { String result = data.getDataString(); if (Constants.REQUEST_CODE == requestCode && !TextUtils.isEmpty(result)) { if (Constants.RESULT_CONTROLLER_URL == resultCode) { currentServer = "http://" + result; ArrayAdapter<String> customeListAdapter = (ArrayAdapter<String>) customListView.getAdapter(); customeListAdapter.add(currentServer); customListView.setItemChecked(customeListAdapter.getCount() - 1, true); AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer); writeCustomServerToFile(); requestPanelList(); checkAuthentication(); requestAccess(); } } } }
From source file:com.google.plus.samples.photohunt.ThemeViewActivity.java
@Override public void onActivityResult(int requestCode, int responseCode, Intent intent) { super.onActivityResult(requestCode, responseCode, intent); switch (requestCode) { case REQUEST_CODE_IMAGE_CAPTURE: if (responseCode == RESULT_OK) { sendImage(Intents.getPhotoImageUri().getPath(), mTheme.id); }//from ww w . j av a 2s .c o m break; case REQUEST_CODE_IMAGE_SELECT: if (responseCode == RESULT_OK && intent != null && intent.getData() != null) { String imageUriString = intent.getDataString(); Uri imageUri = intent.getData(); if ("content".equals(imageUri.getScheme())) { Cursor cursor = getContentResolver().query(imageUri, new String[] { Media.DATA }, null, null, null); int column_index = cursor.getColumnIndexOrThrow(Media.DATA); cursor.moveToFirst(); imageUriString = cursor.getString(column_index); } sendImage(imageUriString, mTheme.id); } break; } }