B4A=true Group=Default Group ModulesStructureVersion=1 Type=Class Version=12.8 @EndOfDesignText@ ' ==================================================================================== ' CLASE: C_ImportaBD ' DESCRIPCION: Gestor aislado para atrapar Intents (ej. compartir desde WhatsApp) ' y poner la BD en la ruta interna de la app como "kmt.db". ' ==================================================================================== ' INSTRUCCIONES (En cualquier B4XPage, usualmente B4XMainPage): ' ' 1. En Class_Globals se declara la instancia: ' Private importador As C_ImportaBD ' ' 2. En B4XPage_Created se inicializa la clase: ' importador.Initialize ' ' 3. En B4XPage_Appear se captura el Intent padre y se procesa: ' Dim in As Intent = B4XPages.GetNativeParent(Me).GetStartingIntent ' ' If importador.ProcesarIntent(in) Then ' ' Si entra aquí, la BD ya se copió exitosamente a File.DirInternal con el nombre "kmt.db" ' ToastMessageShow("BD importada correctamente", False) ' ' ' (Opcional) Identificar si el origen fue WhatsApp: ' If importador.EsDeWhatsapp(in) Then ' B4XPages.SetTitle(Me, "BD cargada desde Whatsapp") ' End If ' ' ' --> AQUI DEBES REINICIALIZAR TU CONEXION SQL <-- ' ' Ej: skmt.Initialize(File.DirInternal, "kmt.db", True) ' End If ' 4. Agregar esta sccion al manifiesto de la aplicacion ' 'Para que se registre para abrir bases de datos ' AddActivityText(Main, ' ' ' ' ' ' ) ' ==================================================================================== Sub Class_Globals Private intentUsado As Boolean = False End Sub Public Sub Initialize intentUsado = False End Sub ' Procesa el intent. Retorna True si efectivamente copió una base de datos. Public Sub ProcesarIntent(in As Intent) As Boolean If intentUsado Or in = Null Then Return False If Not(in.IsInitialized) Then Return False intentUsado = True ' Sellamos para que no vuelva a procesar el mismo intent If in.GetData <> Null Then Dim XmlData As String = in.GetData Log("Intent recibido: " & XmlData) Try Dim OutStr As OutputStream = File.OpenOutput(File.DirInternal, "kmt.db", False) Dim InStr As InputStream = File.OpenInput("ContentDir", XmlData) File.Copy2(InStr, OutStr) OutStr.Close LogColor("BD copiada a interna.", Colors.Blue) Return True Catch Log("Error al copiar BD desde Intent: " & LastException) Return False End Try End If Return False End Sub ' Método auxiliar para revisar el origen Public Sub EsDeWhatsapp(in As Intent) As Boolean If in <> Null And in.IsInitialized Then If in.As(String).Contains("whatsapp") Then Return True End If Return False End Sub