示例#1
0
  @Override
  protected void onActivityResult(
      int requestCode,
      int resultCode,
      Intent
          data) { // requestcode is constant passed to determine which activity we hering back from
    // result code is code the activity we called executed ok or refuse
    // intent data is any data that result return
    super.onActivityResult(requestCode, resultCode, data);
    try {
      // When an Image is picked
      if (requestCode == RESULT_LOAD_IMG
          && resultCode
              == RESULT_OK /// everything processes successfully  and we are hearing back from image
                           // gallery
          && null != data) {
        // Get the Image from data

        Bundle extras = data.getExtras();
        // get the cropped bitmap
        final Bitmap thePic = extras.getParcelable("data");

        ImageView imgView = (ImageView) findViewById(R.id.imgView);
        imgView.setImageBitmap(thePic);
        final EditText editText = (EditText) findViewById(R.id.etcaption);
        editText.setOnClickListener(
            (new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                editText.setText("");
              }
            }));
        // Set the Image in ImageView after decoding the String
        // imgView.setImageBitmap(BitmapFactory  //BitmapFactory to convert it to the Bimap
        // object.//get the bitmap from the stream
        //        .decodeFile(imgDecodableString));
        Button button = (Button) findViewById(R.id.btnupload1);
        button.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                SharePhoto photo =
                    new SharePhoto.Builder()
                        .setBitmap(thePic)
                        .setCaption(editText.getText().toString())
                        .build();

                SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
                // shareDialog.show(content);
                ShareApi.share(content, null);
                Toast.makeText(Second.this, "Photo uploaded successfully", Toast.LENGTH_SHORT)
                    .show();
              }
            });

      } else {
        Toast.makeText(this, "You haven't picked Image", Toast.LENGTH_LONG).show();
      }
    } catch (Exception e) {
      Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
    }
  }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
 }