2017-12-25 17 views
0

저는 1 주일 이상 특별한 사안으로 싸우고 있습니다. 내 PicturesApp/파일 탐색기에서 내 응용 프로그램으로 이미지를 공유하고 개인 서버에 게시 할 수 있기를 원합니다. MultiImage Selector Library를 사용하여 갤러리 내부를 탐색 할 때 이미 이미지가 게시됩니다. 나는 FileUtils 클래스를 포함하여 아무런 문제없이 여기에 나온 모든 대답을 시도했다. here 내 연구 과정에서 나는 애플 리케이션에서 데이터를 다루는 측면에서 많은 회색 영역이 있다는 것을 발견했다. 이 점에서 문서화의 간결함 (궁극적으로 모호함을 야기 함)과 이에 대한 답이없는 힙.내 응용 프로그램의 갤러리에서 이미지 업로드 중입니까?

<provider 
     android:name="android.support.v4.content.FileProvider" 
     tools:replace= "android:authorities" 
     android:authorities="com.myapp.PhotoViewerActivity" 
     android:exported="false" 
     android:grantUriPermissions="true"> 
     <meta-data 
      android:name="android.support.FILE_PROVIDER_PATHS" 
      tools:replace= "android:resource" 
      android:resource="@xml/file_paths" /> 
    </provider> 

      <activity 
     android:name="com.myapp.activity.AppActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.SEND" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="image/*" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.intent.action.SEND_MULTIPLE" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="image/*" /> 
     </intent-filter> 
     </activity> 

매니페스트 일부 코드에 이제 내가 그 콘텐츠를 읽을 수있는 나의 능력 덮어 쓰는 경우 알고 싶어 나는이 파일 공급자를 포함

: // URI를하거나 뭔가를 ..

전 의도를 다룬다.

  final Intent shareIntent = getIntent(); 
      if (shareIntent.getAction()!=null) { 
       final String intentAction = shareIntent.getAction(); 
       final String intentFileType = shareIntent.getType(); 

         if (intentAction.equals(Intent.ACTION_SEND)) { 
           if (intentFileType.startsWith("image/")) { 
            byte[] imageBytes = null; 
            Uri uri = (Uri) shareIntent.getParcelableExtra(Intent.EXTRA_STREAM); 
            try { 
             InputStream inputStream = getContentResolver().openInputStream(uri); 
             imageBytes= getBytes(inputStream); 
            } catch (FileNotFoundException e) { 
             e.printStackTrace(); 
            } catch (IOException e) { 
             e.printStackTrace(); 
            } 

            RequestBody requestFile = RequestBody.create(MediaType.parse("image/*"), imageBytes); 
            image1 = MultipartBody.Part.createFormData("image1", "new_image", requestFile); 
     } 
    } 
    } 
    public byte[] getBytes(InputStream is) throws IOException{ 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    int buffSize =1024; 
    byte[] buff = new byte[buffSize]; 
    int len=0; 
    while((len = is.read(buff))!= -1){ 
     baos.write(buff,0,len); 
    } 
    return baos.toByteArray(); 
} 

활동

시 : 나는 이미 권한을 처리했다. 마찬가지로 나는 애플 리케이션에서 사진을 게시 할 수 있다고 말했다. 서버는 다음과 같이 말한다이 특정 기능에 대한 갤러리 버튼의 클릭에

답변

0

를 "파일이 존재하지 않습니다"에 startActivityForResult를 시작

startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), GET_FROM_GALLERY); 

확인이 링크

How to upload image from gallery in android

+0

를 내가 앱 내부에서 갤러리로 이동하지 않아야합니다. 안드로이드 갤러리 앱의 공유 버튼을 사용하여 갤러리 또는 사진 앱에서 내 앱으로 이동합니다. 답변 주셔서 감사합니다. – Itoooo