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.ccxt.whl.activity.SettingsFragmentCopy.java

/**
 * onActivityResult/*  ww  w  .j a v a 2 s . c o  m*/
 */
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == USERPIC_REQUEST_CODE_CAMERA) { // ??
        if (cameraFile != null && cameraFile.exists()) {
            //sendPicture(cameraFile.getAbsolutePath());
            Log.d("log", "cameraFile" + cameraFile.getAbsolutePath());
            //?uri imageUri = Uri.fromFile(cameraFile);
            imageUri = Uri.fromFile(cameraFile);
            cropImageUri(imageUri, 200, 200, USERPIC_REQUEST_CODE_CUT);

        }
    } else if (requestCode == USERPIC_REQUEST_CODE_LOCAL) { // ??
        if (data != null) {
            Uri selectedImage = data.getData();
            if (selectedImage != null) {
                //?uri imageUri = selectedImage;
                sendPicByUri(selectedImage);
                //Log.d("log","selectedImage"+cameraFile.getAbsolutePath());
            }
        }
    } else if (requestCode == USERPIC_REQUEST_CODE_CUT) {//?
        // ?  
        if (data != null) {

            Log.d("log", "imageUribundle==>" + imageUri);
            iv_user_photo.setImageURI(imageUri);
            RequestParams params = new RequestParams();
            final String contentType = RequestParams.APPLICATION_OCTET_STREAM;
            File file = Uritofile(imageUri);
            //File file = new File(imageUri.getPath());
            if (file.exists()) {
                try {
                    params.put("headurl", file, "image/jpeg");
                    params.put("user", DemoApplication.getInstance().getUser());
                    params.put("param", "headurl");
                    HttpRestClient.post(Constant.UPDATE_USER_URL, params, responseHandler);
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else {
                Toast toast = Toast.makeText(getActivity(), "?SD??",
                        Toast.LENGTH_SHORT);
            }

            //params.put(key, file, )

            //**??data
            //Bitmap bitmap = data.getParcelableExtra("data");
            // Bitmap bitmap = data.getExtras().getParcelable("data");

            /*
            // ByteArrayOutputStream out = new ByteArrayOutputStream(); 
            // bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);  
            */

            //this.iv_image.setImageBitmap(bitmap);  
        } else {
            Toast toast = Toast.makeText(getActivity(), "?SD??",
                    Toast.LENGTH_SHORT);

        }

        /*  try {  
           //   
          // tempFile.delete();  
        } catch (Exception e) {  
           e.printStackTrace();  
        }  */

        RequestParams params = new RequestParams();
        final String contentType = RequestParams.APPLICATION_OCTET_STREAM;
        // params.put(key, file, contentType)
        //HttpRestClient.post(url, params, responseHandler)
    }
}

From source file:co.taqat.call.ChatFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
        String fileToUploadPath = null;

        if (data != null && data.getData() != null) {
            fileToUploadPath = getRealPathFromURI(data.getData());
        } else if (imageToUploadUri != null) {
            fileToUploadPath = imageToUploadUri.getPath();
        }// w  ww  . j  a  v  a2 s .  c o m

        if (fileToUploadPath != null) {
            //showPopupMenuAskingImageSize(fileToUploadPath);
            sendImageMessage(fileToUploadPath, 0);
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:android_network.hetnet.vpn_service.ActivitySettings.java

private void handleExport(final Intent data) {
    new AsyncTask<Object, Object, Throwable>() {
        @Override//from  www. j av a 2s.c  om
        protected Throwable doInBackground(Object... objects) {
            OutputStream out = null;
            try {
                Uri target = data.getData();
                if (data.hasExtra("org.openintents.extra.DIR_PATH"))
                    target = Uri.parse(target + "/netguard_"
                            + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml");
                Log.i(TAG, "Writing URI=" + target);
                out = getContentResolver().openOutputStream(target);
                xmlExport(out);
                return null;
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                return ex;
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    }
            }
        }

        @Override
        protected void onPostExecute(Throwable ex) {
            if (running) {
                if (ex == null)
                    Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
                else
                    Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
            }
        }
    }.execute();
}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    switch (requestCode) {
    case Constants.ACTIVITY_PICK_SUBREDDIT:
        if (resultCode == Activity.RESULT_OK) {
            Matcher redditContextMatcher = REDDIT_PATH_PATTERN.matcher(intent.getData().getPath());
            if (redditContextMatcher.matches()) {
                new MyDownloadThreadsTask(redditContextMatcher.group(1)).execute();
            }// ww  w  .j  a  v  a  2s.  c  o  m
        }
        break;
    default:
        break;
    }
}

From source file:android_network.hetnet.vpn_service.ActivitySettings.java

private void handleImport(final Intent data) {
    new AsyncTask<Object, Object, Throwable>() {
        @Override/* ww  w.  j  a v  a2s.c o  m*/
        protected Throwable doInBackground(Object... objects) {
            InputStream in = null;
            try {
                Log.i(TAG, "Reading URI=" + data.getData());
                ContentResolver resolver = getContentResolver();
                String[] streamTypes = resolver.getStreamTypes(data.getData(), "*/*");
                String streamType = (streamTypes == null || streamTypes.length == 0 ? "*/*" : streamTypes[0]);
                AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(data.getData(),
                        streamType, null);
                in = descriptor.createInputStream();
                xmlImport(in);
                return null;
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                return ex;
            } finally {
                if (in != null)
                    try {
                        in.close();
                    } catch (IOException ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    }
            }
        }

        @Override
        protected void onPostExecute(Throwable ex) {
            if (running) {
                if (ex == null) {
                    Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
                    ServiceSinkhole.reloadStats("import", ActivitySettings.this);
                    // Update theme, request permissions
                    recreate();
                } else
                    Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
            }
        }
    }.execute();
}

From source file:com.lewa.crazychapter11.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    switch (requestCode) {
    case PICK_CONTACT:
        if (resultCode == Activity.RESULT_OK) {
            Uri contactData = intent.getData();
            CursorLoader cursorLoader = new CursorLoader(this, contactData, null, null, null, null);

            Cursor cursor = cursorLoader.loadInBackground();
            if (cursor != null && cursor.moveToFirst()) {
                Log.i("algerheContact", " comhere 111");
                String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cursor
                        .getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
                String phoneNumber = "????";

                Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId, null, null);
                if (phones == null) {
                    return;
                }/*from   w  ww.j  a  v a2s.co m*/
                // Log.i("algerheContact"," comhere 222 phones.moveToFirst()="+phones.moveToFirst());
                if (phones.moveToFirst()) {
                    phoneNumber = phones
                            .getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                }

                phones.close();
                EditText show = (EditText) findViewById(R.id.show);

                show.setText(name);
                EditText phone = (EditText) findViewById(R.id.phone);
                phone.setText(phoneNumber);

                show.setVisibility(View.GONE);
                phone.setVisibility(View.GONE);
            }
            cursor.close();
        }
        break;
    }

    if (requestCode == 0 && resultCode == 0 && intent != null) {
        Bundle data = intent.getExtras();
        if (data == null) {
            return;
        }
        String resultArms = data.getString("armType");
        String showArms = "?" + resultArms;
        show_txt = (EditText) findViewById(R.id.show_txt);
        if (resultArms != null && show_txt != null) {
            show_txt.setText(showArms);
        }
    }
}

From source file:gc.david.dfm.ui.MainActivity.java

/**
 * Handles a send intent with position data.
 *
 * @param intent Input intent with position data.
 *//*www  .j  a va  2 s  .  c  o m*/
private void handleViewPositionIntent(final Intent intent) throws Exception {
    Mint.leaveBreadcrumb("MainActivity::handleViewPositionIntent");
    final Uri uri = intent.getData();
    Mint.addExtraData("queryParameter", uri.toString());

    final String uriScheme = uri.getScheme();
    if (uriScheme.equals("geo")) {
        final String schemeSpecificPart = uri.getSchemeSpecificPart();
        final Matcher matcher = getMatcherForUri(schemeSpecificPart);
        if (matcher.find()) {
            if (matcher.group(1).equals("0") && matcher.group(2).equals("0")) {
                if (matcher.find()) { // Manage geo:0,0?q=lat,lng(label)
                    setDestinationPosition(matcher);
                } else { // Manage geo:0,0?q=my+street+address
                    String destination = Uri.decode(uri.getQuery()).replace('+', ' ');
                    destination = destination.replace("q=", "");

                    // TODO check this ugly workaround
                    new SearchPositionByName().execute(destination);
                    mustShowPositionWhenComingFromOutside = true;
                }
            } else { // Manage geo:latitude,longitude or geo:latitude,longitude?z=zoom
                setDestinationPosition(matcher);
            }
        } else {
            final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                    "Error al obtener las coordenadas. Matcher = " + matcher.toString());
            Mint.logException(noSuchFieldException);
            throw noSuchFieldException;
        }
    } else if ((uriScheme.equals("http") || uriScheme.equals("https"))
            && (uri.getHost().equals("maps.google.com"))) { // Manage maps.google.com?q=latitude,longitude

        final String queryParameter = uri.getQueryParameter("q");
        if (queryParameter != null) {
            final Matcher matcher = getMatcherForUri(queryParameter);
            if (matcher.find()) {
                setDestinationPosition(matcher);
            } else {
                final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                        "Error al obtener las coordenadas. Matcher = " + matcher.toString());
                Mint.logException(noSuchFieldException);
                throw noSuchFieldException;
            }
        } else {
            final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                    "Query sin parmetro q.");
            Mint.logException(noSuchFieldException);
            throw noSuchFieldException;
        }
    } else {
        final Exception exception = new Exception("Imposible tratar la query " + uri.toString());
        Mint.logException(exception);
        throw exception;
    }
}

From source file:au.org.ala.fielddata.mobile.CollectSurveyData.java

/**
 * Callback made to this activity after the camera, gallery or map activity
 * has finished./*from   w w w  .j a v a 2 s .co m*/
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == SELECT_LOCATION_REQUEST) {
        if (resultCode == RESULT_OK) {
            Location location = (Location) data.getExtras().get(LocationSelectionActivity.LOCATION_BUNDLE_KEY);
            surveyViewModel.setLocation(location);
        }
    } else if (requestCode == SELECT_POLYGON_LOCATION_REQUEST) {
        if (resultCode == RESULT_OK) {

            WayPoints result = (WayPoints) data.getExtras().get(WayPointActivity.WAY_POINTS_KEY);
            result.setPhotoPointAttribute(data.getIntExtra(WayPointActivity.ATTRIBUTE_ID_KEY, -1));
            surveyViewModel.setWayPoints(result);
        }
    } else if (requestCode == TAKE_PHOTO_REQUEST) {
        if (resultCode == RESULT_OK) {
            surveyViewModel.persistTempValue();
        } else {
            surveyViewModel.clearTempValue();
        }
    } else if (requestCode == SELECT_FROM_GALLERY_REQUEST) {
        TempValue value = surveyViewModel.clearTempValue();
        if (resultCode == RESULT_OK) {
            Uri selected = data.getData();
            if (selected != null) {
                surveyViewModel.setValue(value.getAttribute(), selected.toString());
            } else {
                Log.e("CollectSurveyData", "Null data returned from gallery intent!" + data);
            }
        }
    }
}

From source file:com.anyonavinfo.commonuserregister.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1 && resultCode == RESULT_OK) {
        Bundle bundle = data.getExtras();
        String content = bundle.getString("result");
        // ??//  w  w w.j a va  2s.c om
        if (!StringUtils.isEmpty(content)) {
            edittext_userVin.setText(content);
        }
    } else if (requestCode == 2 && resultCode == RESULT_OK) {
        Bundle bundle = data.getExtras();
        String shopId = bundle.getString("ID");
        String shopName = bundle.getString("NAME");
        //Log.d("shopId", shopId);
        edittext_userOrgId.setText(shopName);
        orgId = shopId;
    } else if (requestCode == 3 && resultCode == RESULT_OK) {
        /**
         * ???
         */
        Uri uri = data.getData();
        Log.e("Sjj--->", "uri = " + uri);
        BitmapFactory.Options options = new BitmapFactory.Options();
        // options.inJustDecodeBoundstrue
        options.inJustDecodeBounds = true;
        options.inPreferredConfig = Bitmap.Config.RGB_565; // Bitmap.Config.ARGB_8888

        try {
            //????
            Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null,
                    options);
            // options.inJustDecodeBounds?false
            options.inJustDecodeBounds = false;
            int w = options.outWidth;
            int h = options.outHeight;
            Log.i("path", "" + w + "" + h);

            float hh = 800f;//800f
            float ww = 480f;//480f
            //????
            int be = 1;//be=1?
            if (w > h && w > ww) {//???
                be = (int) (options.outWidth / ww);
            } else if (w < h && h > hh) {//???
                be = (int) (options.outHeight / hh);
            }
            if (be <= 0)
                be = 1;
            options.inSampleSize = be;//
            Log.d("Size", be + "");

            //?
            Bitmap bitmapSize = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null,
                    options);
            Log.d("sizePic", bitmapSize.getWidth() + "" + bitmapSize.getHeight());

            /**
             * ???????
             * ?picPath=path,:???Uri?cursor
             * ?uri??url
             */
            Uri sizePicUrl = Uri
                    .parse(MediaStore.Images.Media.insertImage(getContentResolver(), bitmapSize, null, null));
            Log.d("sizePicUrl", sizePicUrl + "");

            String[] pojoSizePic = { MediaStore.Images.Media.DATA };
            Cursor cursorSizePic = managedQuery(sizePicUrl, pojoSizePic, null, null, null);
            if (cursorSizePic != null) {
                //ContentResolver cr = this.getContentResolver();
                int colunm_index = cursorSizePic.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursorSizePic.moveToFirst();
                String pathSizePic = cursorSizePic.getString(colunm_index);
                picPath = pathSizePic;
            }
            /*********************************************************************************************/
            String[] pojo = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(uri, pojo, null, null, null);
            if (cursor != null) {
                //ContentResolver cr = this.getContentResolver();
                int colunm_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToFirst();
                String path = cursor.getString(colunm_index);
                Log.d("path", path);
                /***
                 * ????
                 * ???? ????
                 */
                if (path.endsWith("jpg") || path.endsWith("png")) {
                    //picPath = path;
                    // Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
                    userPictureRight.setImageBitmap(bitmapSize);
                } else {
                    alert();
                }
            } else {
                alert();
            }
        } catch (Exception e) {
        }
    }
}

From source file:com.owncloud.android.ui.activity.FileDisplayActivity.java

private void requestSimpleUpload(Intent data, int resultCode) {
    String filepath = null;//from   w w  w.j a  va 2 s . c  o m
    try {
        Uri selectedImageUri = data.getData();

        String filemanagerstring = selectedImageUri.getPath();
        String selectedImagePath = getPath(selectedImageUri);

        if (selectedImagePath != null)
            filepath = selectedImagePath;
        else
            filepath = filemanagerstring;

    } catch (Exception e) {
        Log_OC.e(TAG, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);
        e.printStackTrace();

    } finally {
        if (filepath == null) {
            Log_OC.e(TAG, "Couldnt resolve path to file");
            Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content),
                    Toast.LENGTH_LONG);
            t.show();
            return;
        }
    }

    Intent i = new Intent(this, FileUploader.class);
    i.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
    String remotepath = new String();
    for (int j = mDirectories.getCount() - 2; j >= 0; --j) {
        remotepath += OCFile.PATH_SEPARATOR + mDirectories.getItem(j);
    }
    if (!remotepath.endsWith(OCFile.PATH_SEPARATOR))
        remotepath += OCFile.PATH_SEPARATOR;
    remotepath += new File(filepath).getName();

    i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);
    i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);
    i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
    if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)
        i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
    startService(i);
}