Search code examples
androidapiandroid-fragmentsandroid-cameraandroid-camera-intent

integrate photo editing AVIORY API with camera app


I want to integrate 3rd party photo editing AVIORY api with the native camera app I am developing but I am not able to do that. The api works after capturing the photo. Please let me know how can I implement this AVIORY API. This is the link to api: https://developers.aviary.com

 enter code here
 void takePicturePressed() {
    if( MyDebug.LOG )
        Log.d(TAG, "takePicturePressed");
    if( camera == null ) {
        if( MyDebug.LOG )
            Log.d(TAG, "camera not opened!");
        /*is_taking_photo_on_timer = false;
        is_taking_photo = false;*/
        this.phase = PHASE_NORMAL;
        return;
    }
    if( !this.has_surface ) {
        if( MyDebug.LOG )
            Log.d(TAG, "preview surface not yet available");
        /*is_taking_photo_on_timer = false;
        is_taking_photo = false;*/
        this.phase = PHASE_NORMAL;
        return;
    }
    //if( is_taking_photo_on_timer ) {
    if( this.isOnTimer() ) {
        takePictureTimerTask.cancel();
        takePictureTimerTask = null;
        if( beepTimerTask != null ) {
            beepTimerTask.cancel();
            beepTimerTask = null;
        }
        /*is_taking_photo_on_timer = false;
        is_taking_photo = false;*/
        this.phase = PHASE_NORMAL;
        if( MyDebug.LOG )
            Log.d(TAG, "cancelled camera timer");
        showToast(take_photo_toast, R.string.cancelled_timer);
        return;
    }
    //if( is_taking_photo ) {
    if( this.phase == PHASE_TAKING_PHOTO ) {
        if( is_video ) {
            if( !video_start_time_set || System.currentTimeMillis() - video_start_time < 500 ) {
                // if user presses to stop too quickly, we ignore
                // firstly to reduce risk of corrupt video files when stopping too quickly (see RuntimeException we have to catch in stopVideo),
                // secondly, to reduce a backlog of events which slows things down, if user presses start/stop repeatedly too quickly
                if( MyDebug.LOG )
                    Log.d(TAG, "ignore pressing stop video too quickly after start");
            }
            else {
                stopVideo(false);
            }
        }
        else {
            if( MyDebug.LOG )
                Log.d(TAG, "already taking a photo");
        }
        return;
    }

    // make sure that preview running (also needed to hide trash/share icons)
    this.startCameraPreview();

    //is_taking_photo = true;
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getContext());
    String timer_value = sharedPreferences.getString("preference_timer", "0");
    long timer_delay = 0;
    try {
        timer_delay = Integer.parseInt(timer_value) * 1000;
    }
    catch(NumberFormatException e) {
        if( MyDebug.LOG )
            Log.e(TAG, "failed to parse preference_timer value: " +    timer_value);
        e.printStackTrace();
        timer_delay = 0;
    }

    String burst_mode_value =      sharedPreferences.getString("preference_burst_mode", "1");
    try {
        n_burst = Integer.parseInt(burst_mode_value);
        if( MyDebug.LOG )
            Log.d(TAG, "n_burst: " + n_burst);
    }
    catch(NumberFormatException e) {
        if( MyDebug.LOG )
            Log.e(TAG, "failed to parse preference_burst_mode value: " +     burst_mode_value);
        e.printStackTrace();
        n_burst = 1;
    }
    remaining_burst_photos = n_burst-1;

    if( timer_delay == 0 ) {
        takePicture();
    }
    else {
        takePictureOnTimer(timer_delay, false);
    }
}

Solution

  • If you are using "native" camera app, and communicate with it through intents, then you need first define the Uri, where camera app will store taken image. You'll have to supply this Uri to camera app within intent :

    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);    
    cameraImageUri = FileUtils.getOutputMediaFileUriFromCamera(FileUtils.MEDIA_TYPE_IMAGE);
                            if (cameraImageUri != null) {
                                cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraImageUri);
                                getActivity().startActivityForResult(cameraIntent, CAMERA_CODE);
    }
    

    In this case, during onActivityResult(int requestCode, int resultCode, Intent data) callback you'll have to pass the same Uri to the Aviary Activity:

    public void startAviaryForImageEdit(Uri imageUri) {
            Intent aviaryIntent = new Intent(getActivity(), FeatherActivity.class);
            aviaryIntent.putExtra(Constants.EXTRA_IN_API_KEY_SECRET, getString(R.string.aviary_key));
            aviaryIntent.setData(imageUri);
            getActivity().startActivityForResult(aviaryIntent, AVIARY_CODE);
        }