안드로이드 삼자 라이브러리 - TakePhoto와 융운IM의 카메라 호출 플래시

6141 단어 타사 네트워크
앱과 카메라나 앨범을 호출하여 서버에 이미지를 올리는 데는 가장 원시적인 쓰기 방법 외에 신기한 제3자 TakePhoto와 Boxing이 있다
1. 먼저 TakePhoto와 융운의 충돌로 인해 핸드폰 호출 카메라가 깜빡인다.
오류 메시지는 다음과 같습니다.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
사실 융운채팅에 가입하지 않았을 때 프로젝트는 정상적으로 카메라를 호출할 수 있었지만, 가입한 후에는 앨범만 호출할 수 있었고, 카메라는 호출하면 뒤로 물러났다. 한참을 찾아서야 파일 추가라는 것을 알았다paths.xml 파일 이후 압축에 실패했습니다. 사진 경로가 틀렸기 때문에 빈 바늘입니다.
a. 해결 방법 1:
새 RongFileProvider:
public class RongFileProvider extends android.support.v4.content.FileProvider {
}

네, 필요한 것은 위에 새로 만든 빈 클래스일 뿐입니다. FileProvider를 계승했습니다.
그리고 App 내 manifest 에서

            
        

이것이 첫 번째 방법이다.
b. 해결 방법 2:
APP에서 IMKit의 FileProvider를 인용하여 직접 주석을 달고takephoto의 xml/filepaths.xml은 다음과 같이 변경되었습니다.
root-path path="" name="camera_photos"
external-path name="rc_external_path" path="."

2. TakePhoto 소개:
사용 인원이 많고 사례가 풍부하다.
compile 'com.jph.takephoto:takephoto_library:4.0.3'

Fragment는TakePhotoFragment를 계승하고 세 가지 감청 방법을 계승한다. (주의:Tresult의getCompressPath는 압축을 사용해야만 얻을 수 있다. 그렇지 않으면null이다)
 /**
     * takePhoto     
     *
     * @param result
     */
    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        TImage image = result.getImage();

    }

초기화 구성:
//    TakePhoto       
            TakePhoto takePhoto = getTakePhoto();
            CropOptions.Builder builder = new CropOptions.Builder();
            builder.setAspectX(800).setAspectY(800);
            builder.setWithOwnCrop(true);
            File file = new File(Environment.getExternalStorageDirectory(),
                    "/temp/" + System.currentTimeMillis() + ".jpg");
            if (!file.getParentFile().exists()) {
                boolean mkdirs = file.getParentFile().mkdirs();
                if (!mkdirs) {
                    ToastUtil.showShort("        ");
                }
            }
            Uri imageUri = Uri.fromFile(file);
            CompressConfig config = new CompressConfig.Builder()
                    .setMaxSize(102400)
                    .setMaxPixel(400)
                    .enableReserveRaw(true)
                    .create();
            takePhoto.onEnableCompress(config, true);

앨범 시작하기
takePhoto.onPickFromDocumentsWithCrop(imageUri, builder.create());
 //         
            takePhoto.onPickFromCaptureWithCrop(imageUri, builderTake.create());
            //       
            //takePhoto.onPickFromCapture(uri);

카메라를 시작하려면:
takePhoto.onPickFromCaptureWithCrop(imageUri, builder.create());
 //  ,   
      takePhoto.onPickMultipleWithCrop(9, cropOptions);
      //  ,   
//      takePhoto.onPickMultiple(9);

두 개의 인터페이스 구현: TakePhoto.TakeResultListener,InvokeListener
onCreate, onActivityResult, onSaveInstanceState 방법에서TakePhoto 대용 방법을 호출합니다
@Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    getTakePhoto().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    getTakePhoto().onActivityResult(requestCode, resultCode, data);
    super.onActivityResult(requestCode, resultCode, data);
  }

  @Override
  protected void onSaveInstanceState(Bundle outState) {
    getTakePhoto().onSaveInstanceState(outState);
    super.onSaveInstanceState(outState);
  }

TpermissionType invoke(InvokeParam invokeParam) 메서드를 다시 쓰고 다음 코드를 추가합니다.
@Override
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    //       Android6.0、7.0      
    PermissionManager.TPermissionType type=PermissionManager.onRequestPermissionsResult(requestCode,permissions,grantResults);
    PermissionManager.handlePermissionsResult(this,type,invokeParam,this);
  }

  @Override
  public PermissionManager.TPermissionType invoke(InvokeParam invokeParam) {
    PermissionManager.TPermissionType type=PermissionManager.checkPermission(TContextWrap.of(this),invokeParam.getMethod());
    if(PermissionManager.TPermissionType.WAIT.equals(type)){
      this.invokeParam=invokeParam;
    }
    return type;
  }

카메라, 앨범, 다중 선택
flag = getIntent().getIntExtra("flag", 0);
    File file = new File(getExternalCacheDir(), System.currentTimeMillis() + ".png");
    Uri uri = Uri.fromFile(file);
    int size = Math.min(getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels);
    CropOptions cropOptions = new CropOptions.Builder().setOutputX(size).setOutputX(size).setWithOwnCrop(false).create();
    if (flag == 1) {
      //         
      takePhoto.onPickFromCaptureWithCrop(uri, cropOptions);
      //       
      //takePhoto.onPickFromCapture(uri);
    } else if (flag == 2) {
      //         
      takePhoto.onPickFromGalleryWithCrop(uri, cropOptions);
      //       
//      takePhoto.onPickFromGallery();
    } else if (flag == 3) {
      //  ,   
      takePhoto.onPickMultipleWithCrop(9, cropOptions);
      //  ,   
//      takePhoto.onPickMultiple(9);
    }

앞의 페이지에서 startActivityForResult를 호출하고 다른 방식을 호출하는 것을 판단하기 위해 표시를 보냅니다.

좋은 웹페이지 즐겨찾기