Android Question ZXingLib black panel when i try to call.

Paolo Pini

Member
Licensed User
Longtime User
I Downloaded the ZXingLib and all example and they works well.
If I create a new project and insert the lib and code like the example when call zx.BeginScan("myzx") I receive a splitter black screen, then after the timeout return to main screen.

I copied the Manifest from example but the problem still the same.

What am I doing wrong?

Many thanks.

Paolo
 

Paolo Pini

Member
Licensed User
Longtime User
Thanks for your reply.
this is my Manifest.

Manifest.xml:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)

'Important
SetApplicationAttribute(android:usesCleartextTraffic,"true")
AddPermission(android.permission.DOWNLOAD_WITHOUT_NOTIFICATION)
'---------------------
'Camera Permissions
AddPermission(android.permission.CAMERA)
AddPermission(android.permission.RECORD_AUDIO)
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
AddPermission(android.permission.MICROPHONE)
AddPermission("android.hardware.camera")
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)
'---------------------

'Geolocation Permissions
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddPermission(android.permission.ACCESS_BACKGROUND_LOCATION)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
'------------------------

AddManifestText(<uses-permission
   android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="26" />
)

AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
<activity android:name="ice.zxing.CaptureActivity"
            android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden">
        </activity> 
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)
'End of default text.

And this is the code, cut and pasted from an example:

Codice:
Private Sub BtnScan_Click
    zx.isportrait = True
    zx.useFrontCam = False
    'change these factors between 0 and 1
    'the library will limit the minimum size to 240 x 240 pixels and the maximum to (screen width) x (screen height pixels)
    zx.theViewFinderXfactor = 0.7
    zx.theViewFinderYfactor = 0.5
    
    zx.theFrameColor = Colors.Blue
    zx.theLaserColor = Colors.Yellow
    zx.theMaskColor = Colors.argb(95, 0, 0, 255)
    zx.theResultColor = Colors.Green
    zx.theResultPointColor = Colors.White
    
    'set the prompt messages
    zx.theTopPromptMessage = "This was done......"
    zx.theTopPromptTextSize = 5%y                            'text size in pixels
    zx.topPromptColor = Colors.Red
    zx.topPromptDistanceFromTop = 1%y                        'pixel distance from top
    
    zx.theBottomPromptMessage = "Just for fun......"
    zx.theBottomPromptTextSize = 5%y                         'text size in pixels
    zx.bottomPromptColor = Colors.Blue
    zx.bottomPromptDistanceFromBottom = 5%y                  'pixel distance from top
    
    zx.BeginScan("myzx")
End Sub

Sub myzx_result(atype As String,Values As String,image As Bitmap)
    Log("type:" & atype &  "Values:" & Values)
    'Msgbox(Values,"type:" & atype)
    MsgboxAsync(Values,"type:" & atype)
End Sub

Mainly I dont'understand why the example works well and mine not.

Regards
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Thanks for your reply.
this is my Manifest.

Manifest.xml:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)

'Important
SetApplicationAttribute(android:usesCleartextTraffic,"true")
AddPermission(android.permission.DOWNLOAD_WITHOUT_NOTIFICATION)
'---------------------
'Camera Permissions
AddPermission(android.permission.CAMERA)
AddPermission(android.permission.RECORD_AUDIO)
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
AddPermission(android.permission.MICROPHONE)
AddPermission("android.hardware.camera")
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)
'---------------------

'Geolocation Permissions
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddPermission(android.permission.ACCESS_BACKGROUND_LOCATION)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
'------------------------

AddManifestText(<uses-permission
   android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="26" />
)

AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
<activity android:name="ice.zxing.CaptureActivity"
            android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden">
        </activity>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)
'End of default text.

And this is the code, cut and pasted from an example:

Codice:
Private Sub BtnScan_Click
    zx.isportrait = True
    zx.useFrontCam = False
    'change these factors between 0 and 1
    'the library will limit the minimum size to 240 x 240 pixels and the maximum to (screen width) x (screen height pixels)
    zx.theViewFinderXfactor = 0.7
    zx.theViewFinderYfactor = 0.5
 
    zx.theFrameColor = Colors.Blue
    zx.theLaserColor = Colors.Yellow
    zx.theMaskColor = Colors.argb(95, 0, 0, 255)
    zx.theResultColor = Colors.Green
    zx.theResultPointColor = Colors.White
 
    'set the prompt messages
    zx.theTopPromptMessage = "This was done......"
    zx.theTopPromptTextSize = 5%y                            'text size in pixels
    zx.topPromptColor = Colors.Red
    zx.topPromptDistanceFromTop = 1%y                        'pixel distance from top
 
    zx.theBottomPromptMessage = "Just for fun......"
    zx.theBottomPromptTextSize = 5%y                         'text size in pixels
    zx.bottomPromptColor = Colors.Blue
    zx.bottomPromptDistanceFromBottom = 5%y                  'pixel distance from top
 
    zx.BeginScan("myzx")
End Sub

Sub myzx_result(atype As String,Values As String,image As Bitmap)
    Log("type:" & atype &  "Values:" & Values)
    'Msgbox(Values,"type:" & atype)
    MsgboxAsync(Values,"type:" & atype)
End Sub

Mainly I dont'understand why the example works well and mine not.

Regards
You must add RuntimePermission for the camera in your code for SDK > 26

 
Last edited:
Upvote 0

Paolo Pini

Member
Licensed User
Longtime User
HI see that the apps works only if I use:
XML:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
in the Manifest, perhaps exist an updated library?
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
As @Johan Schoeman wrote before
You must add RuntimePermission for the camera in your code for SDK > 26
Did you request the user the permission to use the camera in your code?

And (this is more a question from me) it's this line correct in this way?
B4X:
AddPermission("android.hardware.camera")
It look strange to me.
 
Upvote 0
Top