0

I am creating an android library and doing the Unit testing using instrument test.And I use Android Studio 3.0.

This is my code ( controller class )

File file = new File("/storage/emulated/0/DCIM/Facebook/FB_IMG_1496146656900.jpg");

RequestBody reqFile = RequestBody.create(MediaType.parse("image/jpeg"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), reqFile);
RequestBody name = RequestBody.create(MediaType.parse("text/plain"), noteId);
String notebookId = getNotebookId(projectId);
if (isSessionAvailable(notebookId)) {
    String session = getNotebookSession(notebookId);
    Call<ResponseBody> call = mApiNotes.requestNotesAttachments(session, name, body);
    call.enqueue(new NoteAttachmentCallBacks.AddNoteAttachmentCallback(assetUploadCallbacks));
}

And the retrofit interface is

@Multipart
@POST("/NotebookAsset")
Call<ResponseBody> requestNotesAttachments(@Header("Cookie") String notebookSession, @Part("note_id") RequestBody noteId, @Part MultipartBody.Part image);

But when I run the code this is not working. After call to the retrofit interface class the test just browsing and not even end.It continuously run the test but never ending.seems the asset is not uploading.

Roughly I thought,
there is a problem with authority to access resources in the device. so I added permissions to manifest file.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

But it is not the solution.The result is same.

Can you please look this problem?. I have completely blocked with this issue.

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42

1 Answers1

0

Ok, I found the solution. This happens because of the Marshmallows version. version 23 onward to read files from the Android device, need runtime permissions.

When I tried with a device which is with Jelly Bean, the code is working nicely.

Anyway, to the check the version for this issue, we can follow this solution Storage permission error in Marshmallow