Example usage for android.content Intent getExtras

List of usage examples for android.content Intent getExtras

Introduction

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

Prototype

public @Nullable Bundle getExtras() 

Source Link

Document

Retrieves a map of extended data from the intent.

Usage

From source file:com.sim2dial.dialer.ChatFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
        if (data != null && data.getExtras() != null && data.getExtras().get("data") != null) {
            Bitmap bm = (Bitmap) data.getExtras().get("data");
            showPopupMenuAskingImageSize(null, bm);
        } else if (data != null && data.getData() != null) {
            String filePath = getRealPathFromURI(data.getData());
            showPopupMenuAskingImageSize(filePath, null);
        } else if (imageToUploadUri != null) {
            String filePath = imageToUploadUri.getPath();
            showPopupMenuAskingImageSize(filePath, null);
        } else {//  w  w  w  .j  av a  2s . c  o  m
            File file = new File(Environment.getExternalStorageDirectory(),
                    getString(R.string.temp_photo_name));
            if (file.exists()) {
                imageToUploadUri = Uri.fromFile(file);
                String filePath = imageToUploadUri.getPath();
                showPopupMenuAskingImageSize(filePath, null);
            }
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:com.onebus.view.MainActivity.java

/**
 * /* ww  w .  j a  v a 2s. c o  m*/
 */

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        onResults(data.getExtras());
    }
}

From source file:com.layer.atlas.messenger.AtlasMessagesScreen.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (debug)//from w  w w  .  j av  a 2 s  . com
        Log.w(TAG,
                "onActivityResult() requestCode: " + requestCode + ", resultCode: " + resultCode + ", uri: "
                        + (data == null ? "" : data.getData()) + ", data: "
                        + (data == null ? "" : MessengerApp.toString(data.getExtras())));

    if (resultCode != Activity.RESULT_OK)
        return;

    final LayerClient layerClient = ((MessengerApp) getApplication()).getLayerClient();

    switch (requestCode) {
    case REQUEST_CODE_CAMERA:

        if (photoFile == null) {
            if (debug)
                Log.w(TAG, "onActivityResult() taking photo, but output is undefined... ");
            return;
        }
        if (!photoFile.exists()) {
            if (debug)
                Log.w(TAG, "onActivityResult() taking photo, but photo file doesn't exist: "
                        + photoFile.getPath());
            return;
        }
        if (photoFile.length() == 0) {
            if (debug)
                Log.w(TAG, "onActivityResult() taking photo, but photo file is empty: " + photoFile.getPath());
            return;
        }

        try {
            // prepare original
            final File originalFile = photoFile;
            FileInputStream fisOriginal = new FileInputStream(originalFile) {
                public void close() throws IOException {
                    super.close();
                    boolean deleted = originalFile.delete();
                    if (debug)
                        Log.w(TAG, "close() original file is" + (!deleted ? " not" : "") + " removed: "
                                + originalFile.getName());
                    photoFile = null;
                }
            };
            final MessagePart originalPart = layerClient.newMessagePart(Atlas.MIME_TYPE_IMAGE_JPEG, fisOriginal,
                    originalFile.length());
            File tempDir = getCacheDir();

            MessagePart[] previewAndSize = Atlas.buildPreviewAndSize(originalFile, layerClient, tempDir);
            if (previewAndSize == null) {
                Log.e(TAG, "onActivityResult() cannot build preview, cancel send...");
                return;
            }
            Message msg = layerClient.newMessage(originalPart, previewAndSize[0], previewAndSize[1]);
            if (debug)
                Log.w(TAG, "onActivityResult() sending photo... ");
            preparePushMetadata(msg);
            conv.send(msg);
        } catch (Exception e) {
            Log.e(TAG, "onActivityResult() cannot insert photo" + e);
        }
        break;
    case REQUEST_CODE_GALLERY:
        if (data == null) {
            if (debug)
                Log.w(TAG, "onActivityResult() insert from gallery: no data... :( ");
            return;
        }
        // first check media gallery
        Uri selectedImageUri = data.getData();
        // TODO: Mi4 requires READ_EXTERNAL_STORAGE permission for such operation
        String selectedImagePath = getGalleryImagePath(selectedImageUri);
        String resultFileName = selectedImagePath;
        if (selectedImagePath != null) {
            if (debug)
                Log.w(TAG, "onActivityResult() image from gallery selected: " + selectedImagePath);
        } else if (selectedImageUri.getPath() != null) {
            if (debug)
                Log.w(TAG,
                        "onActivityResult() image from file picker appears... " + selectedImageUri.getPath());
            resultFileName = selectedImageUri.getPath();
        }

        if (resultFileName != null) {
            String mimeType = Atlas.MIME_TYPE_IMAGE_JPEG;
            if (resultFileName.endsWith(".png"))
                mimeType = Atlas.MIME_TYPE_IMAGE_PNG;
            if (resultFileName.endsWith(".gif"))
                mimeType = Atlas.MIME_TYPE_IMAGE_GIF;

            // test file copy locally
            try {
                // create message and upload content
                InputStream fis = null;
                File fileToUpload = new File(resultFileName);
                if (fileToUpload.exists()) {
                    fis = new FileInputStream(fileToUpload);
                } else {
                    if (debug)
                        Log.w(TAG, "onActivityResult() file to upload doesn't exist, path: " + resultFileName
                                + ", trying ContentResolver");
                    fis = getContentResolver().openInputStream(data.getData());
                    if (fis == null) {
                        if (debug)
                            Log.w(TAG, "onActivityResult() cannot open stream with ContentResolver, uri: "
                                    + data.getData());
                    }
                }

                String fileName = "galleryFile" + System.currentTimeMillis() + ".jpg";
                final File originalFile = new File(
                        getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES), fileName);

                OutputStream fos = new FileOutputStream(originalFile);
                int totalBytes = Tools.streamCopyAndClose(fis, fos);

                if (debug)
                    Log.w(TAG,
                            "onActivityResult() copied " + totalBytes + " to file: " + originalFile.getName());

                FileInputStream fisOriginal = new FileInputStream(originalFile) {
                    public void close() throws IOException {
                        super.close();
                        boolean deleted = originalFile.delete();
                        if (debug)
                            Log.w(TAG, "close() original file is" + (!deleted ? " not" : "") + " removed: "
                                    + originalFile.getName());
                    }
                };
                final MessagePart originalPart = layerClient.newMessagePart(mimeType, fisOriginal,
                        originalFile.length());
                File tempDir = getCacheDir();

                MessagePart[] previewAndSize = Atlas.buildPreviewAndSize(originalFile, layerClient, tempDir);
                if (previewAndSize == null) {
                    Log.e(TAG, "onActivityResult() cannot build preview, cancel send...");
                    return;
                }
                Message msg = layerClient.newMessage(originalPart, previewAndSize[0], previewAndSize[1]);
                if (debug)
                    Log.w(TAG, "onActivityResult() uploaded " + originalFile.length() + " bytes");
                preparePushMetadata(msg);
                conv.send(msg);
            } catch (Exception e) {
                Log.e(TAG, "onActivityResult() cannot upload file: " + resultFileName, e);
                return;
            }
        }
        break;

    default:
        break;
    }
}

From source file:com.layer8apps.CalendarHandler.java

/************
 *  PURPOSE: Handles the primary thread in the service
 *  ARGUMENTS: Intent intent//  ww w .  ja v a  2  s.  c o m
 *  RETURNS: VOID
 *  AUTHOR: Devin Collins <agent14709@gmail.com>
 *************/
@Override
protected void onHandleIntent(Intent intent) {
    // Get our stored data from the intent
    username = intent.getStringExtra("username");
    password = intent.getStringExtra("password");
    messenger = (Messenger) intent.getExtras().get("handler");
    calID = intent.getIntExtra("calendarID", -1);

    String url = getApplicationContext().getResources().getString(R.string.url);

    // Create variables to be used through the application
    List<String[]> workDays = null;
    ConnectionManager conn = ConnectionManager.newConnection();

    /************
     * Once we verify that we have a valid token, we get the actual schedule
     *************/
    updateStatus("Logging in...");
    String tempToken = conn.getData(url + "/etm/login.jsp");
    if (tempToken != null) {
        loginToken = parseToken(tempToken);
    } else {
        showError("Error connecting to MyTLC, make sure you have a valid network connection");
        return;
    }

    String postResults = null;
    // This creates our login information
    List<NameValuePair> parameters = createParams();
    if (loginToken != null) {
        // Here we send the information to the server and login
        postResults = conn.postData(url + "/etm/login.jsp", parameters);
    } else {
        showError("Error retrieving your login token");
        return;
    }

    if (postResults != null && postResults.toLowerCase().contains("etmmenu.jsp")
            && !postResults.toLowerCase().contains("<font size=\"2\">")) {
        updateStatus("Retrieving schedule...");
        postResults = conn.getData(url + "/etm/time/timesheet/etmTnsMonth.jsp");
    } else {
        String error = parseError(postResults);
        if (error != null) {
            showError(error);
        } else {
            showError("Error logging in, please verify your username and password");
        }
        return;
    }

    // If we successfully got the information, then parse out the schedule to read it properly
    String secToken = null;
    if (postResults != null) {
        updateStatus("Parsing schedule...");
        workDays = parseSchedule(postResults);
        secToken = parseSecureToken(postResults);
        wbat = parseWbat(postResults);
    } else {
        showError("Could not obtain user schedule");
        return;
    }

    if (secToken != null) {
        parameters = createSecondParams(secToken);
        postResults = conn.postData(url + "/etm/time/timesheet/etmTnsMonth.jsp", parameters);
    } else {
        String error = parseError(postResults);
        if (error != null) {
            showError(error);
        } else {
            showError("Error retrieving your security token");
        }
        return;
    }

    List<String[]> secondMonth = null;
    if (postResults != null) {
        secondMonth = parseSchedule(postResults);
    } else {
        showError("Could not obtain user schedule");
        return;
    }

    if (secondMonth != null) {
        if (workDays == null) {
            workDays = secondMonth;
        } else {
            workDays.addAll(secondMonth);
        }
        finalDays = workDays;
    } else {
        String error = parseError(postResults);
        if (error != null) {
            showError(error);
        } else {
            showError("There was an error retrieving your schedule");
        }
        return;
    }

    // Add our shifts to the calendar
    updateStatus("Adding shifts to calendar...");
    int numShifts = addDays();

    if (finalDays != null && numShifts > -1) {
        // Report back that we're successful!
        Message msg = Message.obtain();
        Bundle b = new Bundle();
        b.putString("status", "DONE");
        b.putInt("count", numShifts);
        msg.setData(b);
        try {
            messenger.send(msg);
        } catch (Exception e) {
            // Nothing
        }
    } else {
        showError("Couldn't add your shifts to your calendar");
    }
}

From source file:com.example.ridemedriver.SignupStepTwoActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    Log.i("WWQQ", "in onActivityResult()");
    switch (requestCode) {
    case 1:/*from  ww w.j a  v a  2  s  .co  m*/
        if (resultCode == RESULT_OK) {
            cropPhoto(data.getData());//?
        }
        break;
    case 2:
        if (resultCode == RESULT_OK) {
            File temp = new File(Environment.getExternalStorageDirectory() + "/head.jpg");
            cropPhoto(Uri.fromFile(temp));//?
        }
        break;
    case 3:
        if (data != null) {
            Bundle extras = data.getExtras();
            avatar_pic = extras.getParcelable("data");
            if (avatar_pic != null) {
                FileOutputStream b = null;
                File file = new File(path);
                file.mkdirs();// 
                String fileName = path + "upload_avata";//??
                try {
                    b = new FileOutputStream(fileName);
                    avatar_pic.compress(Bitmap.CompressFormat.JPEG, 100, b);// ?
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                    try {
                        //?
                        b.flush();
                        b.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                signup_steptwo_avatar_imgview.setImageBitmap(avatar_pic);//ImageView?
            }
        }
        break;
    default:
        break;

    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.towson.wavyleaf.Sighting.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == EDIT_REQUEST && resultCode == RESULT_OK) {
        editedCoordinatesInOtherActivitySoDontGetGPSLocation = true;
        Location fixedLocation = data.getExtras().getParcelable("location");

        // Current marker is expired, remove that crap
        mMap.clear();// w w  w. j a  va 2  s .  c o  m
        mapHasMarker = !mapHasMarker;
        setUpMapIfNeeded();
        updateUILocation(fixedLocation);

        // Update location to be send with JSON sighting
        currentEditableLocation.setLatitude(fixedLocation.getLatitude());
        currentEditableLocation.setLongitude(fixedLocation.getLongitude());
        // Since user edited their coordinates, they obviously know it's right
        cb.setChecked(true);

        Toast.makeText(getApplicationContext(), "New position set", Toast.LENGTH_SHORT).show();
    }

    // http://stackoverflow.com/a/15432979/1097170
    else if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {

        // Set global string (_64bitencoding) immediately
        Bitmap bm = (Bitmap) data.getExtras().get("data");
        ib.setImageBitmap(bm);

        // Encode
        _64BitEncoding = Base64.encodeToString(encodeInBase64(bm), Base64.DEFAULT);

        //         Toast.makeText(getApplicationContext(), _64BitEncoding, Toast.LENGTH_SHORT).show();

    } //else if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK) {
    //         Uri selectedImage = data.getData();
    //         InputStream imageStream = null;
    //         
    //         try {
    //            imageStream = getContentResolver().openInputStream(selectedImage);
    //         } catch (FileNotFoundException e) {}
    //         
    //         Bitmap img = BitmapFactory.decodeStream(imageStream);
    //         ib.setImageBitmap(img);
}

From source file:com.librelio.products.ui.ProductsBillingActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, requestCode + " " + resultCode);
    Log.d(TAG, "data = " + data.getExtras().getString("INAPP_PURCHASE_DATA"));
    Log.d(TAG, "signature = " + data.getExtras().getString("INAPP_DATA_SIGNATURE"));

    if (requestCode == CALLBACK_CODE) {
        String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");

        if (resultCode == RESULT_OK && purchaseData != null) {
            try {
                JSONObject jo = new JSONObject(purchaseData);
                String sku = jo.getString("productId");
                String dataResponse = data.getExtras().getString("INAPP_PURCHASE_DATA");
                String signatureResponse = data.getExtras().getString("INAPP_DATA_SIGNATURE");
                Log.d(TAG, "You have bought the " + sku + ". Excellent choice, adventurer!");
                if (getIntent().getExtras() != null) {
                    onDownloadAction(dataResponse, signatureResponse);
                } else {
                    Toast.makeText(this, "Purchase successful", Toast.LENGTH_LONG).show();
                }//  ww w . ja  v a2  s  .c o  m
            } catch (JSONException e) {
                Log.e(TAG, "Failed to parse purchase data.", e);
            }
        } else {
            finish();
        }
    } else {
        finish();
    }
}

From source file:br.com.arlsoft.pushclient.PushClientModule.java

private void checkForExtras() {
    Activity activity = TiApplication.getAppRootOrCurrentActivity();
    if (activity != null) {
        Intent intent = activity.getIntent();
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null && !extras.isEmpty() && extras.containsKey(PROPERTY_EXTRAS)) {
                extras = extras.getBundle(PROPERTY_EXTRAS);
                HashMap data = PushClientModule.convertBundleToHashMap(extras);
                data.put("prev_state", "stopped");
                PushClientModule.sendMessage(data, PushClientModule.MODE_CLICK);
                intent.removeExtra(PROPERTY_EXTRAS);
            }//from   w  w  w.j a va2 s . co  m
        }
    }
}

From source file:com.kyleshaver.minuteofangle.util.IabHelper.java

int getResponseCodeFromIntent(Intent i) {
        Object o = i.getExtras().get(RESPONSE_CODE);
        if (o == null) {
            logError("Intent with no response code, assuming OK (known issue)");
            return BILLING_RESPONSE_RESULT_OK;
        } else if (o instanceof Integer)
            return ((Integer) o).intValue();
        else if (o instanceof Long)
            return (int) ((Long) o).longValue();
        else {// w  ww. j  a v  a  2 s  .  c  om
            logError("Unexpected type for intent response code.");
            logError(o.getClass().getName());
            throw new RuntimeException("Unexpected type for intent response code: " + o.getClass().getName());
        }
    }

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");
        // ??//from w  w  w .  j  ava2 s .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) {
        }
    }
}