0

I am working on to capture image function through Intent call.

I have been successful in implementing startActivityforResult from non-Activity class. I am getting activity Context there.

Now, I want to receive onActivityResult in same java class. As I know it's compulsory to have Activity class to receive this method.

Will it be possible?

I tried to call with Java Proxy , InvocationHandler link but I didn't get success.

code:

public class NovusAPI {

    private Context mContext;
    private NativeActivity nativeactivity;
    static final int REQUEST_IMAGE_CAPTURE = 1;

    /**
     * Constructor. Save reference to NativeActivity object
     **/
    NovusAPI(NativeActivity ref) {

        nativeactivity = ref;
        Log.d(TAG, "NovusAPI constructor called");

    }

    public void captureImage(){
            Log.d(TAG, "Image Capture Call");
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, "novus");
            values.put(MediaStore.Images.Media.DESCRIPTION, "novus camera capture");

            // capture image camera
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            nativeactivity.startActivityForResult(intent,REQUEST_IMAGE_CAPTURE);

       }

EDIT:

PreferenceManager Class:
  public interface OnActivityResultListener {

        /**
         * See Activity's onActivityResult.
         * 
         * @return Whether the request code was handled (in which case
         *         subsequent listeners will not be called.
         */
        boolean onActivityResult(int requestCode, int resultCode, Intent data);
    }

OnActivityResultListener is interface for Android Preference class. So,I do to work on this to InvocationHanlder link.

NovusMobile
  • 1,813
  • 2
  • 21
  • 48
  • I think you can do it similarly a you called startActivityForResult. Though you will have to register a function with your event onActivityResult as you can't implement it here. – usamazf Feb 19 '16 at 06:16
  • See this answer if it helps: http://stackoverflow.com/a/21793981/2555668 – usamazf Feb 19 '16 at 06:20
  • NativeActivity & Activity. Please review my code again. – NovusMobile Feb 19 '16 at 06:27

1 Answers1

0

There are two option -

  1. You can create NovusBaseActivity that extends Activity, you'll not need to pass context. In NovusBaseActivity you can start intent and get result in onActivityResult. instead of passing activity context to NovusAPI, extends NovusBaseActivity.

  2. As suggested in the comment's answer - In activity's onActivityResult, call result handling method from NovusAPI using NovusAPI instance that you have created previously to call captureImage.

Pr38y
  • 1,565
  • 13
  • 21