Closed yogithesymbian closed 3 years ago
its similar on https://github.com/amitshekhariitbhu/Fast-Android-Networking/issues/255
using these code on .upload
.addMultipartParameter("message",body.get("message").toString()) // .addMultipartFile("file_message", file) // if i enable this line
i always get exception :
com.androidnetworking.error.ANError: com.androidnetworking.error.ANError: java.io.FileNotFoundException: /storage/emulated/0/pdf/DUMMY12-11-2021-091046.pdf: open failed: EACCES (Permission denied)
my manifest file
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:requestLegacyExternalStorage="true" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyTesting" android:usesCleartextTraffic="true" tools:targetApi="m">
and i using library for handle permission
GlobalScope.launch { val permissionResult = TedPermission.create() .setPermissions( Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.MANAGE_EXTERNAL_STORAGE ) .check() }
and already check on details application ( permission is already allowed ) , storage allowed.
i load document with these code
var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> if (result.resultCode == Activity.RESULT_OK) { // There are no request codes val data: Intent? = result.data openFileToUpload(data, _bindingIs.txtDisplayUploadName) } } _bindingIs.btnUpload.setOnClickListener { try { val intent = Intent() intent.action = Intent.ACTION_OPEN_DOCUMENT intent.type = "application/pdf" resultLauncher.launch(intent) } catch (e: Exception) { Log.e("ERROR", "exception : $e") } }
and already use cursor and helperclass to get real path and i can consume or get the filename , etc.
this my helper class for URIPathHelper https://gist.github.com/yogithesymbian/09b63e7530e5f7dc0d1a04baa4ac5345
openFileToUpload() .
private fun openFileToUpload(data: Intent?, txtDisplayUploadName: AppCompatTextView) { try { val uri: Uri? = data?.data var initFile: String ? = null if (uri != null) { initFile = URIPathHelper().getPathFromUri(this, uri) // output : /storage/emulated/0/pdf/DUMMY12-11-2021-091046.pdf } }
sorry for bad explained... thanks in advance ...
ah my bad against... in application i only allow access to media only, solve by allow management of all files, i dunno if i click storage (allowed) would to open choosing more spesific.
its similar on https://github.com/amitshekhariitbhu/Fast-Android-Networking/issues/255
using these code on .upload
i always get exception :
my manifest file
and i using library for handle permission
and already check on details application ( permission is already allowed ) , storage allowed.
i load document with these code
and already use cursor and helperclass to get real path and i can consume or get the filename , etc.
this my helper class for URIPathHelper https://gist.github.com/yogithesymbian/09b63e7530e5f7dc0d1a04baa4ac5345
openFileToUpload() .
sorry for bad explained... thanks in advance ...