Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在 fragment 頁面 使用時,請求權限完成後無法掃描 #468

Closed
voarlese opened this issue Oct 21, 2019 · 2 comments
Closed

在 fragment 頁面 使用時,請求權限完成後無法掃描 #468

voarlese opened this issue Oct 21, 2019 · 2 comments

Comments

@voarlese
Copy link

voarlese commented Oct 21, 2019

Hi
我在fragment 使用 ZBarView, 進入頁面後

這時候他會跑
onRresume -> 請求權限 -> onPause : stopCamera -> 彈出對話筐 點允許權限 -> onPermissionsGranted -> onResume : startSpot .

startSpot 會執行 startCamera 這時候 CameraPreview 沒有觸發 surfaceCreated , 導致 mSurfaceCreated = false , 所以setOneShotPreviewCallback 無法設定 callback 導致 掃描都不會有回應

正常流程 :
2019-10-21 17:14:03.724 4708-4708/com.hodwa.lifismart.dev E/test: onAttachFragment: QrCodeFragment{61808b6 #0 id=0x7f08005c com.hodwa.lifismart.view.fragment.verify.QrCodeFragment}
2019-10-21 17:14:03.754 4708-4708/com.hodwa.lifismart.dev E/QrCodeFragment: finishCreateView
2019-10-21 17:14:03.757 4708-4708/com.hodwa.lifismart.dev E/QrCodeFragment: hasPermissions
2019-10-21 17:14:04.190 4708-4708/com.hodwa.lifismart.dev E/QrCodeFragment: setCamera: android.hardware.Camera@2120b66
2019-10-21 17:14:04.233 4708-4708/com.hodwa.lifismart.dev E/QrCodeFragment: surfaceCreated:
2019-10-21 17:14:04.248 4708-4708/com.hodwa.lifismart.dev E/QrCodeFragment: setOneShotPreviewCallback:

要求權限的流程 :
2019-10-21 17:14:33.915 5170-5170/com.hodwa.lifismart.dev E/test: onAttachFragment: QrCodeFragment{61808b6 #0 id=0x7f08005c com.hodwa.lifismart.view.fragment.verify.QrCodeFragment}
2019-10-21 17:14:33.946 5170-5170/com.hodwa.lifismart.dev E/QrCodeFragment: finishCreateView
2019-10-21 17:14:33.948 5170-5170/com.hodwa.lifismart.dev E/QrCodeFragment: 無權限 要求權限
2019-10-21 17:14:37.225 5170-5170/com.hodwa.lifismart.dev E/QrCodeFragment: onPermissionsGranted: 取得permiss成功
2019-10-21 17:14:37.263 5170-5170/com.hodwa.lifismart.dev E/QrCodeFragment: hasPermissions
2019-10-21 17:14:37.877 5170-5170/com.hodwa.lifismart.dev E/QrCodeFragment: setCamera: android.hardware.Camera@465d752

setCamera 後 因為無執行 surfaceCreated 所以不會setCallback 了

@voarlese
Copy link
Author

發現 因為 ZBarView 已經被創立了 所以不會再創建第二次 但有沒有方法可以讓 CameraPreview 重新再再產生一次呢

@voarlese
Copy link
Author

voarlese commented Oct 21, 2019

我在猜 是否是因為
沒有權限時 SurfaceView 不可被建立, 所以surfaceCreated callback 不會被呼叫, 導致 mSurfaceCreated 無法被設為 true,
我在 surfaceChanged 加入了 mSurfaceCreated = true; 當我同意權限後重新startCamera 觸發 surfaceCreated 就可以了.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant