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

hi all

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


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();
        }
    }
}

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

Kf

Also check 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

no , there is no error …

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

thanx

@basher24 Can you try to import once?

import android.content.Intent;

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

@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)

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();
        }
    }
}
1 Like