26/9/23 - Commit inicial.

This commit is contained in:
2023-09-26 04:27:09 -06:00
parent 9955ef26ea
commit 1e9f3958e5
5 changed files with 153 additions and 25 deletions

79
ManageExternalStorage.bas Normal file
View File

@@ -0,0 +1,79 @@
B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=10.7
@EndOfDesignText@
' Version 1.00
#Event: StorageAvailable
Sub Class_Globals
Private ion As Object
Private mCallback As Object
Private mEventName As String
End Sub
' This pretty trivial class is modeled on (plagiarised from!) Erel's ExternalStorage class
' It applies to devices implementing SDK30 and later
' It allows apps to access the internal 'external' storage as was possible on earlier Android versions ussing traditional file I/O
' You must manually add 'AddPermission(android.permission.MANAGE_EXTERNAL_STORAGE)' to the manifest
' You must ensure that you provide the package name of your app in Sub GetPermission
' This class uses the MANAGE_APP_ALL_FILES_ACCESS_PERMISSION intent action to direct users to a system settings page
' They must enable the option on that page to give permission
'Initializes the object
Public Sub Initialize (Callback As Object, EventName As String)
mCallback = Callback
mEventName = EventName
End Sub
' Determine if the app already has MANAGE_EXTERNAL_STORAGE call Environment.isExternalStorageManager()
' Return True if this app already has MANAGE_EXTERNAL_STORAGE permission
Public Sub HasPermission As Boolean
Dim has As Boolean
Dim jo As JavaObject
jo.InitializeStatic("android.os.Environment")
has = jo.RunMethod("isExternalStorageManager", Null)
Return has
End Sub
' Check whether this app has MANAGE_EXTERNAL_STORAGE permission
' If not show the user a dialog to enable MANAGE_EXTERNAL_STORAGE permission for this app
' Raises the StorageAvailable event in the calling activity when complete
Public Sub GetPermission
If HasPermission Then
RaiseEvent
Return
End If
Dim in As Intent
' Be sure to reference your app package name in "pakageg:xxx"
in.Initialize("android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION", $"package:${Application.PackageName}"$)
StartActivityForResult(in)
End Sub
Private Sub RaiseEvent
Log("Calling : " & mEventName & "_StorageAvailable")
CallSubDelayed(mCallback, mEventName & "_StorageAvailable")
End Sub
Private Sub ion_Event (MethodName As String, Args() As Object) As Object
RaiseEvent
Return Null
End Sub
Private Sub StartActivityForResult(i As Intent)
Dim jo As JavaObject = GetBA
ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub
Private Sub GetBA As Object
Dim jo As JavaObject = Me
Return jo.RunMethod("getBA", Null)
End Sub

View File

@@ -1,19 +1,27 @@
Build1=Default,b4a.example
File1=Layout.bal
Build1=Default,kms_helperSubs.keymon.lat
File1=kmt.db
File2=main.bal
File3=manifest.txt
FileGroup1=Default Group
FileGroup2=Default Group
FileGroup3=Default Group
Group=Default Group
Library1=core
Library2=xui
Library3=sql
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~CreateResourceFromFile(Macro, Themes.LightTheme)~\n~'End of default text.~\n~
Library2=javaobject
Library3=phone
Library4=sql
Library5=xui
Library6=runtimepermissions
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~CreateResourceFromFile(Macro, Themes.LightTheme)~\n~'End of default text.~\n~AddPermission("android.permission.MANAGE_EXTERNAL_STORAGE")~\n~SetApplicationAttribute(android:allowBackup, "false")
Module1=kms_helperSubs
NumberOfFiles=1
NumberOfLibraries=3
NumberOfModules=1
Module2=ManageExternalStorage
NumberOfFiles=3
NumberOfLibraries=6
NumberOfModules=2
Version=12.5
@EndOfDesignText@
#Region Project Attributes
#ApplicationLabel: B4A Example
#ApplicationLabel: kms_helpeSubs
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
@@ -27,7 +35,7 @@ Version=12.5
'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=github&Args=..\..\
'###########################################################################################################
'###################### PUSH TORTOISE GIT #########################################################
'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=TortoiseGitProc&Args=/command:commit&Args=/path:"./../../"&Args=/closeonend:2
'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=TortoiseGitProc&Args=/command:commit&Args=/path:"./../"&Args=/closeonend:2
'###########################################################################################################
#End Region
@@ -43,4 +51,10 @@ End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Dim ks As kms_helperSubs
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
ks.Initialize(Me, "ks")
End Sub

View File

@@ -1,9 +1,12 @@
ModuleBookmarks0=
ModuleBookmarks1=
ModuleBookmarks2=
ModuleBreakpoints0=
ModuleBreakpoints1=
ModuleBreakpoints2=
ModuleClosedNodes0=
ModuleClosedNodes1=
NavigationStack=Visual Designer,Layout.bal,-100,1,kms_helperSubs,Class_Globals,0,0,kms_helperSubs,guardaAppInfo,363,0,Main,Globals,32,0,Main,Process_Globals,24,4
ModuleClosedNodes1=4
ModuleClosedNodes2=
NavigationStack=Main,Globals,31,0,Visual Designer,main.bal,-100,3,kms_helperSubs,Class_Globals,12,6,ManageExternalStorage,Class_Globals,16,0,Main,Activity_Create,34,6,kms_helperSubs,initRKMT,58,0,kms_helperSubs,dbInit,101,0,kms_helperSubs,Initialize,24,6,ManageExternalStorage,RaiseEvent,51,0,kms_helperSubs,obtenPermisosAlmacenamientoExterno,57,6
SelectedBuild=0
VisibleModules=1
VisibleModules=1,2

View File

@@ -14,16 +14,58 @@ Sub Class_Globals
Dim safePath As String
Dim fechaHoy As String
Dim skmtAttached As Boolean = False
Dim MES1 As ManageExternalStorage
Dim device As Phone
Dim rp As RuntimePermissions
End Sub
'You can add more parameters here.
Public Sub Initialize (vCallback As Object, vEventName As String) As Object
EventName = vEventName
CallBack = vCallback
obtenPermisosAlmacenamientoExterno
dbInit
' Log("************************** " & safePath)
If MES1.HasPermission Then initRKMT
Return Me
End Sub
'This event will be called once, before the page becomes visible.
'Private Sub B4XPage_Created (Root1 As B4XView)
' Root = Root1
' 'load the layout to Root
'End Sub
'Obtenemos permisos de escritura para el almacenamiento externo.
Sub obtenPermisosAlmacenamientoExterno
' Log("Permisos MES")
MES1.Initialize(Me, "MES1")
' get the device SDK version
Dim SdkVersion As Int = device.SdkVersion
' Choose which permission to request in order to access external storgage
If SdkVersion < 30 Then
' Log("SDK = " & SdkVersion & " : Requesting WRITE_EXTERNAL_STORAGE permission")
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE) ' Implicit read capability if granted
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
' Log($"PERMISSION_WRITE_EXTERNAL_STORAGE = ${Result}"$)
Else
' Log("SDK = " & SdkVersion & " : Requesting MANAGE_EXTERNAL_STORAGE permission")
' Log("On Entry MANAGE_EXTERNAL_STORAGE = " & MES1.HasPermission)
If Not(MES1.HasPermission) Then
MsgboxAsync("This app requires access to all files, please enable the option", "Manage All Files")
Wait For Msgbox_Result(Res As Int)
' Log("Getting permission")
MES1.GetPermission
Wait For MES1_StorageAvailable
End If
End If
End Sub
'Inicializamos la base de datos de respaldoDiario.
Sub initRKMT
Dim Dirp As String = File.DirRootExternal
Dim Dir As String
' Dim Dir2 As String
Try
File.MakeDir(Dirp,"/kmts")
Dir = "/kmts"
@@ -37,7 +79,7 @@ Public Sub Initialize (vCallback As Object, vEventName As String) As Object
skmt.Initialize(File.DirInternal,"kmt.db", False)
' rkmt.ExecNonQuery($"create table if not exists pedidos (pe_folio NUMERIC, pe_desc NUMERIC, pe_costo_sin TEXT, pe_ruta TEXT, pe_cedis TEXT, pe_costo_tot NUMERIC, pe_costou NUMERIC, pe_cant NUMERIC, pe_pronombre TEXT, pe_proid TEXT, pe_cliente TEXT, pe_fecha TEXT, pe_usuario TEXT, pe_envio_ok TEXT)"$)
' rkmt.ExecNonQuery($"create table if not exists inventarios (cat_gp_iniciativa TEXT, cat_gp_tipoprod TEXT, cat_gp_dev TEXT, cat_gp_almacen NUMERIC, cat_gp_id TEXT, cat_gp_nombre TEXT, cat_gp_imp1 TEXT, cat_gp_imp2 TEXT, cat_gp_precio TEXT, cat_gp_clasif TEXT, cat_gp_sts TEXT, cat_gp_tipo TEXT, cat_gp_subtipo TEXT, cat_gp_tipoprod2 TEXT, fecha TEXT)"$)
'' rkmt.ExecNonQuery($"create table if not exists inventarios2 (cat_gp_iniciativa TEXT, cat_gp_tipoprod TEXT, cat_gp_dev TEXT, cat_gp_almacen NUMERIC, cat_gp_id TEXT, cat_gp_nombre TEXT, cat_gp_imp1 TEXT, cat_gp_imp2 TEXT, cat_gp_precio TEXT, cat_gp_clasif TEXT, cat_gp_sts TEXT, cat_gp_tipo TEXT, cat_gp_subtipo TEXT, cat_gp_tipoprod2 TEXT, fecha TEXT)"$)
'' rkmt.ExecNonQuery($"create table if not exists inventarios2 (cat_gp_iniciativa TEXT, cat_gp_tipoprod TEXT, cat_gp_dev TEXT, cat_gp_almacen NUMERIC, cat_gp_id TEXT, cat_gp_nombre TEXT, cat_gp_imp1 TEXT, cat_gp_imp2 TEXT, cat_gp_precio TEXT, cat_gp_clasif TEXT, cat_gp_sts TEXT, cat_gp_tipo TEXT, cat_gp_subtipo TEXT, cat_gp_tipoprod2 TEXT, fecha TEXT)"$)
' rkmt.ExecNonQuery($"create table if not exists paquetes (cat_dp_precio_simptos TEXT, cat_dp_precio TEXT, cat_dp_almacen TEXT, cat_dp_id TEXT, cat_dp_idprod TEXT, cat_dp_tipo TEXT, cat_dp_pzas TEXT, cat_dp_usuario TEXT, cat_dp_fecha TEXT, cat_dp_regalo TEXT, cat_dp_clasif TEXT, fecha TEXT)"$)
If chkIfTableExists(skmt, "PEDIDO") Then rkmt.ExecNonQuery($"create table if not exists PEDIDO (${getTableColumnList(skmt, "PEDIDO")}, FECHA TEXT)"$)
If chkIfTableExists(skmt, "CAT_DETALLES_PAQ") Then rkmt.ExecNonQuery($"create table if not exists CAT_DETALLES_PAQ (${getTableColumnList(skmt, "CAT_DETALLES_PAQ")}, FECHA TEXT)"$)
@@ -46,15 +88,8 @@ Public Sub Initialize (vCallback As Object, vEventName As String) As Object
DateTime.DateFormat = "MM/dd/yyyy"
fechaHoy = DateTime.Date(DateTime.Now)
revisaSkmtAttached
Return Me
End Sub
'This event will be called once, before the page becomes visible.
'Private Sub B4XPage_Created (Root1 As B4XView)
' Root = Root1
' 'load the layout to Root
'End Sub
'Revisa si esta montada "kmt.db" como "skmt1" y si no, la monta
'Para que "rkmt" vea a "skmt", es necesario montarla (attach).
Sub revisaSkmtAttached

View File

@@ -1,3 +0,0 @@
Version=1.0
Supported Platforms=B4A
B4A.DependsOn=SQL