Android Question CreateResource Problem

Discussion in 'Android Questions' started by fabio borges, Jul 11, 2019.

Similar threads

B4A Code Snippet Theme Colors
B4A Code Snippet Full Screen Theme
Other B4A v5.80 BETA is released!
B4A Code Snippet Version safe themes
B4A Tutorial TabStripViewPager - Better ViewPager
B4A Library [class] FileProvider - share files
  1. fabio borges

    fabio borges Member Licensed User

    When i create a resource in the manifest using CreateResource my app crash with this error:

    Trying to use:
    CreateResource(xml, provider_paths,
    <external-path name="name" path="" />
    )

    ERROR:
    ** Service (httputils2service) Start **
    ** Activity (main) Pause, UserClosed = false **
    ** Activity (utilsatualizaversao) Create, isFirst = true **
    utilsatualizaversao_carregaactionbar (java line: 618)
    android.content.res.Resources$NotFoundException: Resource ID #0x7f08001c
    at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
    at android.content.res.Resources.getDimension(Resources.java:657)
    at de.amberhome.SimpleActionBar.ActionBar.<init>(ActionBar.java:312)
    at de.amberhome.SimpleActionBar.ActionBarWrapper.innerInitialize(ActionBarWrapper.java:86)
    at anywheresoftware.b4a.objects.ViewWrapper.Initialize(ViewWrapper.java:67)
    at de.amberhome.SimpleActionBar.ActionBarWrapper.Initialize2(ActionBarWrapper.java:79)
    at de.amberhome.SimpleActionBar.ActionBarWrapper.Initialize(ActionBarWrapper.java:63)
    at dmuller.comercial.utilsatualizaversao._carregaactionbar(utilsatualizaversao.java:618)
    at

    In my project I use AHActionBar Lib, apparently this is the problem but I cant solve.

    Any suggest?

    Fabio
     
  2. DonManfred

    DonManfred Expert Licensed User

    what is at this code line in the generated java source?
     
  3. DonManfred

    DonManfred Expert Licensed User

    i don´t think the error is related to this CreateResource. The CreateResource you are using because you are implementing Fileprovider but the error has another reason.

    Best is to upload a small project which shows the issue.
     
  4. fabio borges

    fabio borges Member Licensed User

    Its the procedure that load AHActionBar.

    Code:
    #Region Module Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
    #End Region

    Sub Process_Globals
        
    Dim vSQLCnx             As SQL   
    End Sub

    Sub Globals
        
    Private acb                 As AHActionBar
        
    Private HomeIcon             As BitmapDrawable
        
    Private vReceber             As Boolean = False
        
    Private vBtConecta             As Button
        
    Private vCursorCnx             As Cursor
        
    Private vLabelVersaoAtual    As Label
        
    Private vLabelNovaVersao    As Label
        
    Private Label_Titulo         As Label
        
    Private vProgresso             As ProgressBar
        
    Private vEndAcesso            As String
        
    Private phone                 As Phone
        
    Private vNomePacote            As String = "dmuller.apk"
       
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    Dim vTamABC                As Int

          
    Activity.Color=Colors.White
       
        Label_Titulo.Initialize(
    "")
        vProgresso.Initialize(
    "")
       
        vSQLCnx.Initialize(Starter.vPathDB, 
    "Database.db3"False)   

        vCursorCnx=vSQLCnx.ExecQuery(
    "SELECT * FROM CONFIGURACOES")
        vCursorCnx.Position=
    0
        
    If vCursorCnx.GetString("ID_AMBIENTE")="N" Then
            vEndAcesso    = vCursorCnx.GetString(
    "END_VERSAO").Trim
        
    Else
            vEndAcesso    = vCursorCnx.GetString(
    "END_VERSAO_HOMOLOGACAO").Trim
        
    End If
        vCursorCnx.Close
       
        CarregaActionBar
       
        vTamABC = acb.Top+acb.Height
       
        vLabelVersaoAtual.Initialize(
    "")
        vLabelVersaoAtual.Text = 
    "Versão Atual: "&Starter.vAppVersao
        
    Activity.AddView(vLabelVersaoAtual, 5dip, vTamABC+5dip100%x20dip)
       
        vLabelNovaVersao.Initialize(
    "")
        vLabelNovaVersao.Text = 
    "Versão Disponível: N/A"
        
    Activity.AddView(vLabelNovaVersao, 5dip, vTamABC+20dip100%x20dip)
       
        vBtConecta.Initialize(
    "Conecta")
        vBtConecta.Text=
    "Atualizar"
        vBtConecta.TextSize=
    16 * Starter.vFontSize
        vBtConecta.Typeface=
    Typeface.DEFAULT_BOLD
        
    Activity.AddView(vBtConecta,1dip,140dip,100%x-2dip,60dip)   
       
        Label_Titulo.Gravity=
    Gravity.CENTER_HORIZONTAL
        Label_Titulo.TextSize=
    18 * Starter.vFontSize

        
    Activity.AddView(Label_Titulo,050%y100%x,30dip)

        
    Dim j As HttpJob

        j.Initialize(
    "", Me)
        j.GetRequest.Timeout=
    150000
        j.PostString(vEndAcesso & 
    "Android.VerificarVersao","")
        
    Wait For (j) JobDone(j As HttpJob)
       
        
    If j.Success Then
            
    Dim vResposta As String = j.GetString
            vLabelNovaVersao.Text = 
    "Versão Disponível: "&vResposta.Replace(".apk","")
           
            
    If vResposta.Replace(".apk","") > Starter.vAppVersao Then
                vReceber = 
    True
            
    Else
                vReceber = 
    False
            
    End If
        
    Else
            
    Log("Verificando versão: " & j.GetString)
        
    End If
        j.Release
    End Sub


    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub ACB_ItemClicked(ItemID As Int)
        
    Select ItemID
            
    Case Starter.ID_ACTION_HOME
                vSQLCnx.Close
                
    Activity.Finish
        
    End Select
    End Sub

    Sub CarregaActionBar
        HomeIcon.Initialize(        
    LoadBitmap(File.DirAssets, "Home_48.png"))
       
        acb.Initialize(
    "ACB")
        acb.Title=
    ""
        
    Activity.Title="Atualiza Versão"
        acb.ActionWidth = 
    58dip
        acb.addHomeAction(Starter.ID_ACTION_HOME, HomeIcon)
        acb.Background=Utils.abColor(
    Null)
        
    Activity.AddView(acb, 00100%x60dip)
    End Sub

    Sub Conecta_Click
        
    If vReceber Then
            Label_Titulo.Text=
    "[ Conectando Servidor ]"
           
            
    ProgressDialogShow2("Fazendo download da aplicação...",False)
           
            acb.RemoveView
            vBtConecta.RemoveView
           
            
    Dim j As HttpJob

            j.Initialize(
    "", Me)
            j.GetRequest.Timeout=
    150000
            j.Download(vEndAcesso&
    "Android.BuscarVersao")
           
            
    Wait For (j) JobDone(j As HttpJob)
       
            
    If j.Success Then
                
    If File.Exists(File.DirInternalCache ,vNomePacote)=True Then
                    
    File.Delete(File.DirInternalCache,vNomePacote)
                
    End If

                
    Try
                    
    Dim MyStream As OutputStream
                    MyStream = 
    File.OpenOutput(File.DirInternalCache, vNomePacote, False)
                    
    File.Copy2(j.GetInputStream,MyStream) ' save the file
                    MyStream.Close
               
                    
    If File.Exists(File.DirInternalCache,vNomePacote) Then
                        SendInstallIntent
                        
    ExitApplication
                        
    Activity.Finish
                    
    End If
                
    Catch
                    
    Log(LastException.Message)
                    
    Msgbox("Erro no recebimento da versão, verifique se existe espaço no cartão de memória...","Atenção")
                    j.Release
                    
    Activity.Finish
                
    End Try
            
    End If
            j.Release
        
    End If
    End Sub


    Private Sub SendInstallIntent
        
    Dim i As Intent
        
    If phone.SdkVersion >= 24 Then
            i.Initialize(
    "android.intent.action.INSTALL_PACKAGE", CreateFileProviderUri(File.DirInternalCache, vNomePacote))
            i.Flags = 
    Bit.Or(i.Flags, 1'FLAG_GRANT_READ_URI_PERMISSION
        Else
            i.Initialize(i.ACTION_VIEW, 
    "file://" & File.Combine(File.DirInternalCache, vNomePacote))
            i.SetType(
    "application/vnd.android.package-archive")
        
    End If
        
    StartActivity(i)
    End Sub

    Sub CreateFileProviderUri (Dir As String, FileName As StringAs Object
        
    Dim FileProvider As JavaObject
        
    Dim context As JavaObject
        context.InitializeContext
        FileProvider.InitializeStatic(
    "android.support.v4.content.FileProvider")
        
    Dim f As JavaObject
        f.InitializeNewInstance(
    "java.io.File"Array(Dir, FileName))
        
    Return FileProvider.RunMethod("getUriForFile"Array(context, Application.PackageName & ".provider", f))   'ERROR HERE
    End Sub
     
    abilio486software likes this.
  5. fabio borges

    fabio borges Member Licensed User

    The problem is about CreateResource becouse I remove the apk works fine.
     
  6. DonManfred

    DonManfred Expert Licensed User

    What B4A are you using?

    Again: Please upload a project which shows the issue. Do not think i can get the same error with the codesnippet you posted...
     
  7. asales

    asales Well-Known Member Licensed User

  8. DonManfred

    DonManfred Expert Licensed User

    Good point. Possible.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice