If File.Exists(File.SDCard, "")Then
Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
Private Jo As JavaObject
Jo.InitializeContext
Dim SdCardExist As Boolean = Jo.RunMethod("sdExist", Null)
Log ("SD card exist: " & SdCardExist)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#If JAVA
import android.os.Environment;
public boolean sdExist() {
Boolean isSDPresent = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
Boolean isStorageRemovable = Environment.isExternalStorageRemovable();
if(isStorageRemovable && isSDPresent) {
return true;
}
else {
return false;
}
}
#End If
Code below is not tested as I don't have device with SD Card
B4X:Sub Process_Globals End Sub Sub Globals End Sub Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Layout") Private Jo As JavaObject Jo.InitializeContext Dim SdCardExist As Boolean = Jo.RunMethod("sdExist", Null) Log ("SD card exist: " & SdCardExist) End Sub Sub Activity_Resume End Sub Sub Activity_Pause (UserClosed As Boolean) End Sub [/QUOTE] [QUOTE="Pendrush, post: 849160, member: 31308"] #If JAVA import android.os.Environment; public boolean sdExist() { Boolean isSDPresent = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); Boolean isStorageRemovable = Environment.isExternalStorageRemovable(); if(isStorageRemovable && isSDPresent) { return true; } else { return false; } } #End If
Logger connected to: samsung SM-A705YN
--------- beginning of main
--------- beginning of system
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 1252)
java.lang.RuntimeException: Method: sdExist not found in: horsetrailer.B4A.AntennaBearingTool.main
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
at horsetrailer.B4A.AntennaBearingTool.main._activity_create(main.java:1252)
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
If SDExists Then
Log("SD exists")
Else
Log("SD does not exist")
End If
End Sub
Private Sub SDExists As Boolean
Dim jo As JavaObject
jo.InitializeStatic("android.os.Environment")
Dim ExternalStorageState As String = jo.RunMethod("getExternalStorageState", Null)
Dim ExternalStorageRemovable As Boolean = jo.RunMethod("isExternalStorageRemovable", Null)
Return ExternalStorageState = "mounted" And ExternalStorageRemovable
End Sub
Try so:
B4X:Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Layout") If SDExists Then Log("SD exists") Else Log("SD does not exist") End If End Sub Private Sub SDExists As Boolean Dim jo As JavaObject jo.InitializeStatic("android.os.Environment") Dim ExternalStorageState As String = jo.RunMethod("getExternalStorageState", Null) Dim ExternalStorageRemovable As Boolean = jo.RunMethod("isExternalStorageRemovable", Null) Return ExternalStorageState = "mounted" And ExternalStorageRemovable End Sub
Why? Why not let the user choose their Google Drive and similar other services?If the App can accurately determine if a SD Card is NOT available it can then warn or block these functions.
Good point. I somewhere gained the impression that everything should go in and out from the SD Card. A quick check and I can't see where I Gained that idea. I'll rewrite the instructions.Why? Why not let the user choose their Google Drive and similar other services?
View attachment 119081
Perhaps the problem is that we passed Null as the Path parameter.
I can't but I would try passing:
B4X:Array("/") ' or Array("/*.*")
Dim ExternalStorageState As String = jo.RunMethod("getExternalStorageState", Array("/"))
Dim ExternalStorageRemovable As Boolean = jo.RunMethod("isExternalStorageRemovable", Array("/"))
Logger connected to: samsung SM-A705YN
--------- beginning of main
--------- beginning of system
** Activity (main) Create, isFirst = true **
main_sdexists (java line: 8995)
java.lang.RuntimeException: Method: getExternalStorageState not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at horsetrailer.B4A.AntennaBearingTool.main._sdexists(main.java:8995)
at horsetrailer.B4A.AntennaBearingTool.main._activity_create(main.java:1247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at horsetrailer.B4A.AntennaBearingTool.main.afterFirstLayout(main.java:105)
at horsetrailer.B4A.AntennaBearingTool.main.access$000(main.java:17)
at horsetrailer.B4A.AntennaBearingTool.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1139)
java.lang.RuntimeException: Method: getExternalStorageState not matched.
Dim ExternalStorageState As String = jo.RunMethod("getExternalStorageState", Array("/*.*"))
Dim ExternalStorageRemovable As Boolean = jo.RunMethod("isExternalStorageRemovable", Array("/*.*"))
** Activity (main) Create, isFirst = true **
main_sdexists (java line: 8995)
java.lang.RuntimeException: Method: getExternalStorageState not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at horsetrailer.B4A.AntennaBearingTool.main._sdexists(main.java:8995)
at horsetrailer.B4A.AntennaBearingTool.main._activity_create(main.java:1247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at horsetrailer.B4A.AntennaBearingTool.main.afterFirstLayout(main.java:105)
at horsetrailer.B4A.AntennaBearingTool.main.access$000(main.java:17)
at horsetrailer.B4A.AntennaBearingTool.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
"You" should try passing it something like this:
It's Java; I don't know how do it using JavaObject (Erel?).B4X:final File file = new File("foo");
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?