# Public void onActivityResult(int requestCode, int resultCode, Intent data)

**URL:** <https://discourse.processing.org/t/public-void-onactivityresult-int-requestcode-int-resultcode-intent-data/831>\
**Category:** Processing for Android\
**Created:** [June 10, 2018, 8:30am UTC](https://discourse.processing.org/t/public-void-onactivityresult-int-requestcode-int-resultcode-intent-data/831 "2018-06-10T08:30:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![basher24](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@basher24](https://discourse.processing.org/u/basher24)\
**Post date:** [June 10, 2018, 8:30am UTC](https://discourse.processing.org/t/public-void-onactivityresult-int-requestcode-int-resultcode-intent-data/831/1 "2018-06-10T08:30:21Z")

</div>

hi all

why the " public void onActivityResult(int requestCode, int resultCode, Intent data) "  
not working ?

```auto

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.util.Date;
import java.text.SimpleDateFormat;
import android.os.Looper; 
import android.widget.Toast;
import android.app.Activity; 
 
 
private static final int IMAGE_CAPTURE = 102;

 
public void setup(){
  
  final Activity act = this.getActivity();  
  orientation(LANDSCAPE);  
  Intent intent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);   
  act.startActivityForResult(intent, IMAGE_CAPTURE);  
}

public void draw(){
 
}

@Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
  
  println("hhhhhhhhhhhhh");
  super.onActivityResult(requestCode, resultCode, data);
  
 final Activity act = this.getActivity();   
 
      
  if (requestCode == IMAGE_CAPTURE) {
    if (resultCode == Activity.RESULT_OK) {
      PImage jj = (PImage)data.getExtras().get("data"); //(MediaStore.EXTRA_OUTPUT, imageUri);
      
       Toast.makeText(act.getApplicationContext(), "Image saved to:\n" +
                 data.getData(), Toast.LENGTH_LONG).show();
    } else if (resultCode == Activity.RESULT_CANCELED) {
        Toast.makeText(act.getApplicationContext(), "Image cancelled.", 
                     Toast.LENGTH_LONG).show();
    } else {
       Toast.makeText(act.getApplicationContext(), "Failed to take Image", 
                     Toast.LENGTH_LONG).show();
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 10, 2018, 5:54pm UTC](https://discourse.processing.org/t/public-void-onactivityresult-int-requestcode-int-resultcode-intent-data/831/2 "2018-06-10T17:54:46Z")

</div>

Is this related to this current issue in GH? [https://github.com/processing/processing-android/issues/452](https://github.com/processing/processing-android/issues/452)

Kf

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 10, 2018, 5:58pm UTC](https://discourse.processing.org/t/public-void-onactivityresult-int-requestcode-int-resultcode-intent-data/831/3 "2018-06-10T17:58:16Z")

</div>

Also check [https://forum.processing.org/two/search?Search=MediaStore.ACTION\_IMAGE\_CAPTURE](https://forum.processing.org/two/search?Search=MediaStore.ACTION_IMAGE_CAPTURE)

Related to your current code, can you describe what happens? Do you get any errors?

Kf

---

<div class="post-metadata">

**Author:** ![basher24](https://avatars.discourse-cdn.com/v4/letter/b/ee7513/32.png) [@basher24](https://discourse.processing.org/u/basher24)\
**Post date:** [June 10, 2018, 6:54pm UTC](https://discourse.processing.org/t/public-void-onactivityresult-int-requestcode-int-resultcode-intent-data/831/4 "2018-06-10T18:54:43Z")

</div>

no , there is no error …

its seems that the function “public void onActivityResult” not valid or startActivityForResult not valid

thanx

---

<div class="post-metadata">

**Author:** ![Nikhil](https://avatars.discourse-cdn.com/v4/letter/n/b782af/32.png) [@Nikhil](https://discourse.processing.org/u/Nikhil)\
**Post date:** [November 25, 2020, 8:48am UTC](https://discourse.processing.org/t/public-void-onactivityresult-int-requestcode-int-resultcode-intent-data/831/5 "2020-11-25T08:48:14Z")

</div>

@basher24 Can you try to import once?

import android.content.Intent;

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 25, 2020, 8:53am UTC](https://discourse.processing.org/t/public-void-onactivityresult-int-requestcode-int-resultcode-intent-data/831/6 "2020-11-25T08:53:20Z")

</div>

> [@Nikhil](#):
>
> Can you try to import once?

What do you mean?  
Are you referring to the code above?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [November 28, 2020, 4:35pm UTC](https://discourse.processing.org/t/public-void-onactivityresult-int-requestcode-int-resultcode-intent-data/831/7 "2020-11-28T16:35:43Z")

</div>

@basher24 === as for me this code (with some modifs) runs fine, supposing that you have also the required permissions, and commenting the part of the code which is not related to the problem, but fires an error (because the data is not defined here)

```auto
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.util.Date;
import java.text.SimpleDateFormat;
import android.os.Looper; 
import android.widget.Toast;
import android.app.Activity; 
 
 
private static final int IMAGE_CAPTURE = 102;
Activity act ;   

 
public void setup(){
  
  act = this.getActivity();  
  orientation(LANDSCAPE);  
  Intent intent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);   
  act.startActivityForResult(intent, IMAGE_CAPTURE);  
}

public void draw(){
 
}

@Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   println("hhhhhhhhhhhhh"+ requestCode);
///// PRINTED
  
  super.onActivityResult(requestCode, resultCode, data);
  println("hhhhhhhhhhhhh");
////PRINTED
  
  
 //final Activity act = this.getActivity();   
 
      
  if (requestCode == IMAGE_CAPTURE) {
    if (resultCode == Activity.RESULT_OK) {
      println("image capturée");
///PRINTED
      //PImage jj = (PImage)data.getExtras().get("data"); //(MediaStore.EXTRA_OUTPUT, imageUri);
      
       //Toast.makeText(act.getApplicationContext(), "Image saved to:\n" +
                 //data.getData(), Toast.LENGTH_LONG).show();
    } else if (resultCode == Activity.RESULT_CANCELED) {
        Toast.makeText(act.getApplicationContext(), "Image cancelled.", 
                     Toast.LENGTH_LONG).show();
    } else {
       Toast.makeText(act.getApplicationContext(), "Failed to take Image", 
                     Toast.LENGTH_LONG).show();
        }
    }
}

```
