According to the documentation
https://developer.android.com/training/data-storage/manage-all-files#operations-allowed-manage-external-storage, MANAGE_EXTERNAL_STORAGE permission grant access to root directory of the USB (OTG) drive.
val sm = application.getSystemService(Context.STORAGE_SERVICE) as StorageManager
val sv = sm.storageVolumes
sv.forEach{
val curVolStats = StatFs(it.directory.toString())
}
The above code works well for Primary Storage and SDCARD. For the USB OTG drive, this return below error message:
2022-09-14 11:03:28.456 14141-14141/com.starsolutions.starfilemanager E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.starsolutions.starfilemanager, PID: 14141
java.lang.IllegalArgumentException: Invalid path: /mnt/media_rw/7ACF-B2AD
at android.os.StatFs.doStat(StatFs.java:53)
at android.os.StatFs.<init>(StatFs.java:43)
at com.starsolutions.starfilemanager.data.ExplorerDataSource.getVolumes(ExplorerDataSource.kt:36)
at com.starsolutions.starfilemanager.data.ExplorerRepository$getVolumeDetails$2.invokeSuspend(ExplorerRepository.kt:20)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}#d17c76f, Dispatchers.Main.immediate]
Caused by: android.system.ErrnoException: statvfs failed: EACCES (Permission denied)
Please help me where is my mistake?
I reported this in
Google issue tracker.
They are replied issue is fixed in S build.
Related
I am trying to make a File List from my SMB Shared Folder with Android Studio.
I want to press a Button in my Android App and then get the List stored as *.txt in my root or SD Card Root.
I am using Android Studio API Version Level 30 and SMBJ Library.
But I'm failing in connection for my SMB Share.
When I press the button with the code its crashing without giving a Message on my Samsung Galaxy S20.
I found that the crash happens on following 2 lines:
AuthenticationContext ac = new AuthenticationContext("admin", "password123".toCharArray(),null);
Session session = connection.authenticate(ac);
I am not sure if I need the domain.
I have no domain installed and tried some different things.
SMBClient client = new SMBClient();
try {
Connection connection = client.connect("192.168.1.75");
AuthenticationContext ac = new AuthenticationContext("admin", "password123".toCharArray(),null);
Session session = connection.authenticate(ac);
//DiskShare share = (DiskShare) session.connectShare("Intel");
} catch (Exception e) {
txt.setText(e.toString());
}
The following is from the SMBJ Website on GIT:
https://github.com/hierynomus/smbj
SMBClient client = new SMBClient();
try (Connection connection = client.connect("SERVERNAME")) {
AuthenticationContext ac = new AuthenticationContext("USERNAME", "PASSWORD".toCharArray(), "DOMAIN");
Session session = connection.authenticate(ac);
// Connect to Share
try (DiskShare share = (DiskShare) session.connectShare("SHARENAME")) {
for (FileIdBothDirectoryInformation f : share.list("FOLDER", "*.TXT")) {
System.out.println("File : " + f.getFileName());
}
}
}
This is the error log I get:
2022-04-25 11:45:27.475 22865-22865/com.example.filme E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.filme, PID: 22865
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
at com.hierynomus.smbj.SMBClient.<clinit>(SMBClient.java:119)
at com.example.filme.MainActivity$1.onClick(MainActivity.java:36)
at android.view.View.performClick(View.java:7792)
at android.widget.TextView.performClick(TextView.java:16112)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7769)
at android.view.View.access$3800(View.java:910)
at android.view.View$PerformClick.run(View.java:30213)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.slf4j.LoggerFactory" on path: DexPathList[[dex file "/data/data/com.example.filme/code_cache/.overlay/base.apk/classes3.dex", dex file "/data/data/com.example.filme/code_cache/.overlay/base.apk/classes.dex", zip file "/data/app/~~SMMMBpkYv1Fu0fT2H1M_sA==/com.example.filme-ovE-fLeCY69AhQvQzyn1cA==/base.apk"],nativeLibraryDirectories=[/data/app/~~SMMMBpkYv1Fu0fT2H1M_sA==/com.example.filme-ovE-fLeCY69AhQvQzyn1cA==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.hierynomus.smbj.SMBClient.<clinit>(SMBClient.java:119)
at com.example.filme.MainActivity$1.onClick(MainActivity.java:36)
at android.view.View.performClick(View.java:7792)
at android.widget.TextView.performClick(TextView.java:16112)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7769)
at android.view.View.access$3800(View.java:910)
at android.view.View$PerformClick.run(View.java:30213)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
2022-04-25 11:45:27.518 22865-22865/com.example.filme I/Process: Sending signal. PID: 22865 SIG: 9
tried to install library slf4j-android-1.7.9.jar
but dont works for now.
Edit 12:46 o clock:
I added now many libraries and now its going close to work but not fully.
No library is missing but the following error occurs:
android.os.NetworkOnMainThreadException error
I read that I must do asynchronous processing.
But I'm too stupid to write this asynchronous code.. can anyone help?
Now its working.
I needed following LIBRARIES:
asn-one-0.6.0.jar
bcprov-jdk15on-1.70.jar
mbassador-1.3.2.jar
slf4j-api-1.7.9.jar
slf4j-nop-1.7.9.jar
smbj-0.11.5.jar
I'm trying to implement the sample code of dji developer for android but i can't start the app, i add my com.dji.sdk.API_KEY and when i launch the app i get this errors:
2020-04-03 19:44:10.734 5567-5607/com.dji.sdk.sample E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.dji.sdk.sample, PID: 5567
java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String dji.midware.natives.SDKRelativeJNI.native_getUsbAccessoryAttachedString() (tried Java_dji_midware_natives_SDKRelativeJNI_native_1getUsbAccessoryAttachedString and Java_dji_midware_natives_SDKRelativeJNI_native_1getUsbAccessoryAttachedString__)
at dji.midware.natives.SDKRelativeJNI.native_getUsbAccessoryAttachedString(Native Method)
at dji.sdk.sdkmanager.DJISDKManager.<clinit>(Unknown Source:32)
at dji.sdk.sdkmanager.DJISDKManager.getInstance(Unknown Source:0)
at com.dji.sdk.sample.internal.controller.MainActivity$5.run(:241)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
If you need code of any thing i can post it too. Thanks.
EDIT:
I can do it with an hardware Samsung, not in virtual device.
I'm using an emulator, but the MSDK doesn't support it.
It only works with a real device.
I am developing my android App with MongoDB Stitch, which has a pre-requisite that I need to install MongoDB Mobile Tarball.Installation Structure
After installation I run the program, getting this exception:
08-09 13:01:34.308 20251-20278/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: io.datats.datatungshing.app, PID: 20251
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: com.mongodb.embedded.client.MongoClientEmbeddedException: Failed to load the mongodb library: 'mongo_embedded_capi'.
Native library (com/sun/jna/android-x86/libjnidispatch.so) not found in resource path (.)
Please set the library location by either:
- Adding it to the classpath.
- Setting 'jna.library.path' system property
- Configuring it in the 'MongoEmbeddedSettings.builder().libraryPath' method.
at com.mongodb.embedded.client.MongoDBCAPIHelper.init(MongoDBCAPIHelper.java:60)
at com.mongodb.embedded.client.MongoClients.init(MongoClients.java:38)
at com.mongodb.stitch.core.services.mongodb.local.internal.CoreLocalMongoDbService.getClient(CoreLocalMongoDbService.java:36)
at com.mongodb.stitch.android.services.mongodb.local.LocalMongoDbService.access$000(LocalMongoDbService.java:35)
at com.mongodb.stitch.android.services.mongodb.local.LocalMongoDbService$1.getClient(LocalMongoDbService.java:50)
at com.mongodb.stitch.android.services.mongodb.local.LocalMongoDbService$1.getClient(LocalMongoDbService.java:41)
at com.mongodb.stitch.android.core.internal.StitchAppClientImpl.getServiceClient(StitchAppClientImpl.java:105)
at io.datats.datatungshing.forboledts.SecondActivity$getTrendFromDB.doInBackground(SecondActivity.java:57)
at io.datats.datatungshing.forboledts.SecondActivity$getTrendFromDB.doInBackground(SecondActivity.java:37)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
... 4 more
Caused by: java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-x86/libjnidispatch.so) not found in resource path (.)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:962)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:922)
at com.sun.jna.Native.<clinit>(Native.java:190)
at com.sun.jna.Native.loadLibrary(Native.java:544)
at com.mongodb.embedded.client.MongoDBCAPIHelper.init(MongoDBCAPIHelper.java:58)
... 14 more
The highlighted code is in my AsyncTask, which is just creating a MongoClient in my java program:
final StitchAppClient client =
Stitch.initializeDefaultAppClient("APP-ID");
final MongoClient mobileClient =
client.getServiceClient(LocalMongoDbService.clientFactory);
MongoCollection<Document> localCollection =
mobileClient.getDatabase(databaseName).getCollection("CollectionName");
/*Document doc = localCollection.find().first();
this.keywordList = (List<String>) doc.get("list");*/
return true;
I have also created and included a jniLibs directory in my src/main/, which contains the following components:
jniLibs
In my jniLibs I also have the file libjnidispatch.io included. Please help me on this strange bug. The emulator I used is Nexus 6 API 28. Thank you!!!
I am trying to move file from internal phone memory to sd card.
val oldFile = File(oldPath) //oldPath is string
val newFile = File(newPath) //newPath is string
if(newFile.exists()) {
newFile.delete()
}
newFile.parentFile.mkdirs()
newFile.createNewFile() //crashes here
// copy file code
Paths are absolute.
Old file path is:
/storage/emulated/0/Android/data/com.package/files/2ec37ce3-ca72-4a35-a6e6-2d7f8e864c6c
New file path is:
/storage/48EE-C144/chosenDirectory/2ec37ce3-ca72-4a35-a6e6-2d7f8e864c6c
where 2ec37ce3-ca72-4a35-a6e6-2d7f8e864c6c is file.
Paths are proper and the new file path is chosen manually by user with external directory picker library which works fine.
Of course app asks user for permissions and does not shall pass user to app until permissions are not granted.
int perm = this.checkSelfPermission(permission.WRITE_EXTERNAL_STORAGE);
int perm2 = this.checkSelfPermission(permission.READ_EXTERNAL_STORAGE);
if (perm != PackageManager.PERMISSION_GRANTED || perm2 != PackageManager.PERMISSION_GRANTED) {
/*ask for permissions and show explain dialog*/
}
Parmissions in manifest are added too.
Application crashes while calling newFile.createNewFile() with exception log:
05-07 13:02:14.995 14004-14004/com.packagename E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.packagename, PID: 14004
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
Caused by: java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively0(Native Method)
at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:280)
at java.io.File.createNewFile(File.java:948)
at com.packagename.backend.localApi.changePath.PathChanger.changePath(PathChanger.kt:29)
at com.packagename.backend.localApi.changePath.PathChangeService$changePath$1.onSelect(PathChangeService.kt:49)
at com.codekidlabs.storagechooser.fragments.ChooserDialogFragment$1.onItemClick(ChooserDialogFragment.java:169)
at android.widget.AdapterView.performItemClick(AdapterView.java:343)
at android.widget.AbsListView.performItemClick(AbsListView.java:1665)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:4075)
at android.widget.AbsListView$10.run(AbsListView.java:6552)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6816)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
Need to add permission in AndroidManifest.xml file.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Solution for me was stop using java classes and migrate to Storage Access Framework
I am using Crashlytics version 2.6.8 for my Android app. I have configured Crashlytics in base feature following answer here. Crashlystics is initialized with Fabric using following code snippet
Fabric.with(context, crashlyticsKit);
Crashlytics Answers throws this exception on startup of Android instant apps
E/Answers: Failed to enable events
java.io.IOException: ftruncate failed: EACCES (Permission denied)
at java.io.RandomAccessFile.setLength(RandomAccessFile.java:630)
at io.fabric.sdk.android.services.common.QueueFile.initialize(QueueFile.java:213)
at io.fabric.sdk.android.services.common.QueueFile.<init>(QueueFile.java:130)
at io.fabric.sdk.android.services.events.QueueFileEventStorage.<init>(QueueFileEventStorage.java:58)
at io.fabric.sdk.android.services.events.GZIPQueueFileEventStorage.<init>(GZIPQueueFileEventStorage.java:32)
at com.crashlytics.android.answers.AnswersFilesManagerProvider.getAnalyticsFilesManager(AnswersFilesManagerProvider.java:44)
at com.crashlytics.android.answers.AnswersEventsHandler$4.run(AnswersEventsHandler.java:121)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at io.fabric.sdk.android.services.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:75)
at io.fabric.sdk.android.services.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:30)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: ftruncate failed: EACCES (Permission denied)
at libcore.io.Posix.ftruncate(Native Method)
at libcore.io.BlockGuardOs.ftruncate(BlockGuardOs.java:148)
at java.io.RandomAccessFile.setLength(RandomAccessFile.java:628)
Is it caused due to storage access? If so, Is it possible to configure Crashlytics from accessing storage in case of Instant apps?
It doesn't seem like you are initializing Answers itself, only Crashlytics?
Try something like this if you want Crashlytics and Answers from Fabric:
final Fabric fabric = new Fabric.Builder(this)
.kits(new Crashlytics(), new Answers())
.debuggable(true)
.build();
Fabric.with(fabric);