将照片编辑AVIORY API与相机应用集成

时间:2016-02-09 14:41:13

标签: android api android-fragments android-camera android-camera-intent

我想将第三方照片编辑AVIORY api与我正在开发的原生相机应用程序集成,但我无法做到这一点。拍摄照片后,api可以正常工作。请让我知道如何实现此AVIORY API。这是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);
    }
}

1 个答案:

答案 0 :(得分:0)

如果您正在使用“原生”相机应用程序,并通过意图与之通信,那么您首先需要定义Uri,相机应用程序将存储拍摄的图像。您必须在意图内将此Uri提供给相机应用程序:

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

在这种情况下,在onActivityResult(int requestCode, int resultCode, Intent data)回调期间,您必须将相同的Uri传递给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);
    }