Example usage for android.content Intent getData

List of usage examples for android.content Intent getData

Introduction

In this page you can find the example usage for android.content Intent getData.

Prototype

public @Nullable Uri getData() 

Source Link

Document

Retrieve data this intent is operating on.

Usage

From source file:com.amazonaws.cognito.sync.demo.MainActivity.java

void retrieveTwitterCredentials(Intent intent) {

    final Uri uri = intent.getData();
    String callbackUrl = "callback://" + getString(R.string.twitter_callback_url);
    if (uri == null || !uri.toString().startsWith(callbackUrl)) {
        Log.e(TAG, "This is not our Twitter callback");
        return;/*from   ww  w  .  jav  a 2s.  co  m*/
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                // Get token and secret
                String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);
                mOauthProvider.retrieveAccessToken(mOauthConsumer, verifier);
                String token = mOauthConsumer.getToken();
                String tokenSecret = mOauthConsumer.getTokenSecret();

                setTwitterSession(token, tokenSecret);

            } catch (Exception e) {
                Log.e("Exception", e.getMessage());
                e.printStackTrace();
            }
        }
    }).start();

}

From source file:fr.bde_eseo.eseomega.profile.ViewProfileFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == INTENT_GALLERY_ID && resultCode == RESULT_OK && data != null) {

        Uri profPicture = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getActivity().getContentResolver().query(profPicture, filePathColumn, null, null, null);
        if (cursor != null) {
            cursor.moveToFirst();/*w  ww .  j  a v a  2  s  .  c  om*/
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            if (profile != null) { // cas impossible, mais au cas o ...
                profile.setPicturePath(picturePath);
                profile.registerProfileInPrefs(getActivity());
                setImageView();
                mOnUserProfileChange.OnUserProfileChange(profile);
            }
        } else {
            Toast.makeText(getActivity(), "Erreur lors du traitement de l'image.", Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.amytech.android.library.views.imagechooser.api.BChooser.java

protected boolean wasVideoSelected(Intent data) {
    if (data == null) {
        return false;
    }/*from  w w  w  .  j  a  v  a2  s .  co m*/

    if (data.getType() != null && data.getType().startsWith("video")) {
        return true;
    }

    ContentResolver cR = getContext().getContentResolver();
    String type = cR.getType(data.getData());
    if (type != null && type.startsWith("video")) {
        return true;
    }

    return false;
}

From source file:cc.metapro.openct.myclass.ClassActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == FILE_SELECT_CODE && resultCode == AppCompatActivity.RESULT_OK) {
        Uri uri = data.getData();
        PrefHelper.putString(this, R.string.pref_background, uri.toString());
        Glide.with(this).load(uri).centerCrop().into(mBackground);
    }/*from   w w w . ja v  a  2  s  . co  m*/
}

From source file:com.antew.redditinpictures.library.service.RESTService.java

@Override
protected void onHandleIntent(Intent intent) {
    Uri action = intent.getData();
    Bundle extras = intent.getExtras();/*from   ww w. j a  va 2 s  . co m*/

    if (extras == null || action == null) {
        Ln.e("You did not pass extras or data with the Intent.");
        return;
    }

    // We default to GET if no verb was specified.
    int verb = extras.getInt(EXTRA_HTTP_VERB, GET);
    RequestCode requestCode = (RequestCode) extras.getSerializable(EXTRA_REQUEST_CODE);
    Bundle params = extras.getParcelable(EXTRA_PARAMS);
    String cookie = extras.getString(EXTRA_COOKIE);
    String userAgent = extras.getString(EXTRA_USER_AGENT);

    // Items in this bundle are simply passed on in onRequestComplete
    Bundle passThrough = extras.getBundle(EXTRA_PASS_THROUGH);

    HttpEntity responseEntity = null;
    Intent result = new Intent(Constants.Broadcast.BROADCAST_HTTP_FINISHED);
    result.putExtra(EXTRA_PASS_THROUGH, passThrough);
    Bundle resultData = new Bundle();

    try {
        // Here we define our base request object which we will
        // send to our REST service via HttpClient.
        HttpRequestBase request = null;

        // Let's build our request based on the HTTP verb we were
        // given.
        switch (verb) {
        case GET: {
            request = new HttpGet();
            attachUriWithQuery(request, action, params);
        }
            break;

        case DELETE: {
            request = new HttpDelete();
            attachUriWithQuery(request, action, params);
        }
            break;

        case POST: {
            request = new HttpPost();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary. Note: some REST APIs
            // require you to POST JSON. This is easy to do, simply use
            // postRequest.setHeader('Content-Type', 'application/json')
            // and StringEntity instead. Same thing for the PUT case
            // below.
            HttpPost postRequest = (HttpPost) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                postRequest.setEntity(formEntity);
            }
        }
            break;

        case PUT: {
            request = new HttpPut();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary.
            HttpPut putRequest = (HttpPut) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                putRequest.setEntity(formEntity);
            }
        }
            break;
        }

        if (request != null) {
            DefaultHttpClient client = new DefaultHttpClient();

            // GZip requests
            // antew on 3/12/2014 - Disabling GZIP for now, need to figure this CloseGuard error:
            // 03-12 21:02:09.248    9674-9683/com.antew.redditinpictures.pro E/StrictMode A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
            //         java.lang.Throwable: Explicit termination method 'end' not called
            // at dalvik.system.CloseGuard.open(CloseGuard.java:184)
            // at java.util.zip.Inflater.<init>(Inflater.java:82)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
            // at com.antew.redditinpictures.library.service.RESTService$GzipDecompressingEntity.getContent(RESTService.java:346)
            client.addRequestInterceptor(getGzipRequestInterceptor());
            client.addResponseInterceptor(getGzipResponseInterceptor());

            if (cookie != null) {
                request.addHeader("Cookie", cookie);
            }

            if (userAgent != null) {
                request.addHeader("User-Agent", Constants.Reddit.USER_AGENT);
            }

            // Let's send some useful debug information so we can monitor things
            // in LogCat.
            Ln.d("Executing request: %s %s ", verbToString(verb), action.toString());

            // Finally, we send our request using HTTP. This is the synchronous
            // long operation that we need to run on this thread.
            HttpResponse response = client.execute(request);

            responseEntity = response.getEntity();
            StatusLine responseStatus = response.getStatusLine();
            int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;

            if (responseEntity != null) {
                resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity));
                resultData.putSerializable(EXTRA_REQUEST_CODE, requestCode);
                resultData.putInt(EXTRA_STATUS_CODE, statusCode);
                result.putExtra(EXTRA_BUNDLE, resultData);

                onRequestComplete(result);
            } else {
                onRequestFailed(result, statusCode);
            }
        }
    } catch (URISyntaxException e) {
        Ln.e(e, "URI syntax was incorrect. %s %s ", verbToString(verb), action.toString());
        onRequestFailed(result, 0);
    } catch (UnsupportedEncodingException e) {
        Ln.e(e, "A UrlEncodedFormEntity was created with an unsupported encoding.");
        onRequestFailed(result, 0);
    } catch (ClientProtocolException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } catch (IOException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } finally {
        if (responseEntity != null) {
            try {
                responseEntity.consumeContent();
            } catch (IOException ignored) {
            }
        }
    }
}

From source file:com.drunkenhamster.facerecognitionfps.SnapFaceActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    if (calledACTION_GET_CONTENT_) {
        if (resultCode == RESULT_OK && data != null) {
            Uri uri = data.getData();
            Intent intent = new Intent();
            intent.setData(uri);/*from  w  ww  .j  av a 2 s  .c  o  m*/
            setResult(RESULT_OK, intent);
            tracker_.trackEvent(getString(R.string.GA_CAT_ACT), getString(R.string.GA_ACT_GET_CONTENT),
                    getString(R.string.GA_LBL_SUCCEED), 1);
        }
        setResult(resultCode);
        finish();
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.microsoft.projectoxford.visionsample.AnalyzeInDomainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("AnalyzeInDomainActivity", "onActivityResult");
    switch (requestCode) {
    case REQUEST_SELECT_IMAGE:
        if (resultCode == RESULT_OK) {
            // If image is selected successfully, set the image URI and bitmap.
            mImageUri = data.getData();

            mBitmap = ImageHelper.loadSizeLimitedBitmapFromUri(mImageUri, getContentResolver());
            if (mBitmap != null) {
                // Show the image on screen.
                ImageView imageView = (ImageView) findViewById(R.id.selectedImage);
                imageView.setImageBitmap(mBitmap);

                // Add detection log.
                Log.d("AnalyzeInDomainActivity", "Image: " + mImageUri + " resized to " + mBitmap.getWidth()
                        + "x" + mBitmap.getHeight());

                doAnalyze();//  ww  w.j av a 2s. c  o  m
            }
        }
        break;
    default:
        break;
    }
}

From source file:edu.mit.mobile.android.locast.sync.AbsLocastAccountSyncService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Bundle extras = intent.getExtras();//  w ww  . j  a  v  a 2s  . c  o m
    if (extras == null) {
        extras = new Bundle();
    }
    extras.putString(EXTRA_SYNC_URI, intent.getData().toString());

    final Account account = extras.getParcelable(EXTRA_ACCOUNT);

    // TODO make this shortcut the Android sync system.
    ContentResolver.requestSync(account, getAuthority(), extras);

    return START_NOT_STICKY;
}

From source file:com.example.android.wifidirect.DeviceDetailFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    // User has picked an image. Transfer it to group owner i.e peer using
    // FileTransferService.
    Uri uri = data.getData();
    TextView statusText = (TextView) mContentView.findViewById(R.id.status_text);
    statusText.setText("Sending: " + uri);
    Log.d(WiFiDirectActivity.TAG, "Intent----------- " + uri);
    Intent serviceIntent = new Intent(getActivity(), FileTransferService.class);
    serviceIntent.setAction(FileTransferService.ACTION_SEND_FILE);
    serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH, uri.toString());
    serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS,
            info.groupOwnerAddress.getHostAddress());
    serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_PORT, 8988);
    getActivity().startService(serviceIntent);

}

From source file:com.cbtec.eliademy.EliademyLms.java

/**
 * Called when an activity you launched exits, giving you the requestCode
 * you started it with, the resultCode it returned, and any additional data
 * from it./*  w ww .  j a  va 2s. 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 data
 *            An Intent, which can return result data to the caller (various
 *            data can be attached to Intent "extras").
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    switch (requestCode) {
    case submitFileCode:
        if (resultCode == Activity.RESULT_OK) {
            Uri uri = intent.getData();
            if (uri.getScheme().toString().compareTo("content") == 0) {
                Cursor cursor = cordova.getActivity().getApplicationContext().getContentResolver().query(uri,
                        null, null, null, null);
                if (cursor.moveToFirst()) {
                    int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
                    uri = Uri.parse(cursor.getString(column_index));
                }
            }
            if (this.mCallbackContext != null) {
                this.mCallbackContext.success(uri.toString());
                return;
            } else {
                Log.i("HLMS", "callback context is null");
            }
        }
        break;
    }
    if (this.mCallbackContext != null) {
        this.mCallbackContext.error(resultCode);
    } else {
        Log.i("HLMS", "callback context is null");
    }
}