Why I can't access camera service in android instant app -


i trying develop camera instant app, posts crash when open camera manager.opencamera(cameraid, mstatecallback, null);:

09-10 21:00:55.333 9472-9472/com.pixelslab.stickerpe i/cameramanager: using legacy camera hal. 09-10 21:00:55.340 1402-1914/? i/cameraservice: cameraservice::connect call (pid -1 "com.pixelslab.stickerpe", camera id 0) hal version default , camera api version 1 09-10 21:00:55.340 1402-1914/? w/servicemanager: permission failure: android.permission.camera uid=10088 pid=9472 09-10 21:00:55.340 1402-1914/? e/cameraservice: permission denial: can't use camera pid=9472, uid=10088 09-10 21:00:55.345 9472-9472/com.pixelslab.stickerpe d/androidruntime: shutting down vm 09-10 21:00:55.348 9472-9472/com.pixelslab.stickerpe e/androidruntime: fatal exception:       main process: com.pixelslab.stickerpe, pid: 9472      java.lang.securityexception: lacking privileges access camera service      @ android.hardware.camera2.cameramanager.throwaspublicexception(cameramanager.java:643)      @ android.hardware.camera2.cameramanager.opencameradeviceuserasync(cameramanager.java:340)      @ android.hardware.camera2.cameramanager.opencameraforuid(cameramanager.java:466)      @ android.hardware.camera2.cameramanager.opencamera(cameramanager.java:430)      @ com.gomo.minivideo.camera2.camera2videofragment.opencamera(camera2videofragment.java:378)      @ com.gomo.minivideo.camera2.camera2videofragment.access$000(camera2videofragment.java:65)      @ com.gomo.minivideo.camera2.camera2videofragment$1.onsurfacetextureavailable(camera2videofragment.java:120)      @ android.view.textureview.gethardwarelayer(textureview.java:390)      @ android.view.textureview.draw(textureview.java:339)      @ android.view.view.updatedisplaylistifdirty(view.java:18069)      @ android.view.view.draw(view.java:18847)      @ android.view.viewgroup.drawchild(viewgroup.java:4214)      @ android.view.viewgroup.dispatchdraw(viewgroup.java:4000)      @ android.view.view.updatedisplaylistifdirty(view.java:18060)      @ android.view.view.draw(view.java:18847)      @ android.view.viewgroup.drawchild(viewgroup.java:4214)      @ android.view.viewgroup.dispatchdraw(viewgroup.java:4000)      @ android.view.view.updatedisplaylistifdirty(view.java:18060)      @ android.view.view.draw(view.java:18847)      @ android.view.viewgroup.drawchild(viewgroup.java:4214)      @ android.view.viewgroup.dispatchdraw(viewgroup.java:4000)      @ android.view.view.updatedisplaylistifdirty(view.java:18060)      @ android.view.view.draw(view.java:18847)      @ android.view.viewgroup.drawchild(viewgroup.java:4214)      @ android.view.viewgroup.dispatchdraw(viewgroup.java:4000)      @ android.view.view.updatedisplaylistifdirty(view.java:18060)      @ android.view.view.draw(view.java:18847)      @ android.view.viewgroup.drawchild(viewgroup.java:4214)      @ android.view.viewgroup.dispatchdraw(viewgroup.java:4000)      @ android.view.view.updatedisplaylistifdirty(view.java:18060)      @ android.view.view.draw(view.java:18847)      @ android.view.viewgroup.drawchild(viewgroup.java:4214)      @ android.view.viewgroup.dispatchdraw(viewgroup.java:4000)      @ android.view.view.updatedisplaylistifdirty(view.java:18060)      @ android.view.view.draw(view.java:18847)      @ android.view.viewgroup.drawchild(viewgroup.java:4214)      @ android.view.viewgroup.dispatchdraw(viewgroup.java:4000)      @ android.view.view.updatedisplaylistifdirty(view.java:18060)      @ android.view.view.draw(view.java:18847)      @ android.view.viewgroup.drawchild(viewgroup.java:4214)      @ android.view.viewgroup.dispatchdraw(viewgroup.java:4000)      @ android.view.view.draw(view.java:19122)      @ com.android.internal.policy.decorview.draw(decorview.java:785)      @ android.view.view.updatedisplaylistifdirty(view.java:18069)      @ android.view.threadedrenderer.updateviewtreedisplaylist(threadedrenderer.java:643)      @ android.view.threadedrenderer.updaterootdisplaylist(threadedrenderer.java:649)      @ android.view.threadedrenderer.draw(threadedrenderer.java:757)      @ android.view.viewrootimpl.draw(viewrootimpl.java:2980)      @ android.view.viewrootimpl.performdraw(viewrootimpl.java:2794)      @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:2347)      @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1386)      @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:6733)      @ android.view.choreographer$callbackrecord.run(choreographer.java:911)      @ android.view.choreographer.docallbacks(choreographer.java:723)      @ android.view.choreographer.doframe(choreographer.java:658)      @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:897)      @ android.os.handler.handlecallback(handler.java:789)      @ android.os.handler.dispatchmessage(handler.java:98)      @ android.os.looper.loop(looper.java:164)      @ android.app.activitythread.main(activitythread.java:6541) 09-10 21:00:55.349 9472-9472/com.pixelslab.stickerpe e/androidruntime:      @ java.lang.reflect.method.invoke(native method)      @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240)      @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767)        caused by: android.os.servicespecificexception: lacking privileges access camera service (code 1)      @ android.hardware.camera2.legacy.legacyexceptionutils.throwonserviceerror(legacyexceptionutils.java:132)      @ android.hardware.camera2.legacy.cameradeviceusershim.connectbindershim(cameradeviceusershim.java:374)      @ android.hardware.camera2.cameramanager.opencameradeviceuserasync(cameramanager.java:317)      ... 61 more 

however, sure have camera-permission granted, because same code run in installed version.

can solve this? thank you!

here code went crash:

// camerafragment.java private textureview.surfacetexturelistener msurfacetexturelistener         = new textureview.surfacetexturelistener() {      @override     public void onsurfacetextureavailable(surfacetexture surfacetexture,                                           int width, int height) {         opencamera(width, height);     }      @override     public void onsurfacetexturesizechanged(surfacetexture surfacetexture,                                             int width, int height) {         configuretransform(width, height);     }      @override     public boolean onsurfacetexturedestroyed(surfacetexture surfacetexture) {         return true;     }      @override     public void onsurfacetextureupdated(surfacetexture surfacetexture) {     }  };  private void opencamera(int width, int height) {     final activity activity = getactivity();     if (null == activity || activity.isfinishing()) {         return;     }     cameramanager manager = (cameramanager) activity.getsystemservice(context.camera_service);     try {         log.d(tag, "tryacquire");         if (!mcameraopencloselock.tryacquire(2500, timeunit.milliseconds)) {             throw new runtimeexception("time out waiting lock camera opening.");         }         string cameraid = manager.getcameraidlist()[0];          cameracharacteristics characteristics = manager.getcameracharacteristics(cameraid);         streamconfigurationmap map = characteristics                 .get(cameracharacteristics.scaler_stream_configuration_map);         msensororientation = characteristics.get(cameracharacteristics.sensor_orientation);         if (map == null) {             throw new runtimeexception("cannot available preview/video sizes");         }         mvideosize = choosevideosize(map.getoutputsizes(mediarecorder.class));         mpreviewsize = chooseoptimalsize(map.getoutputsizes(surfacetexture.class),                 width, height, mvideosize);          int orientation = getresources().getconfiguration().orientation;         if (orientation == configuration.orientation_landscape) {             mtextureview.setaspectratio(mpreviewsize.getwidth(), mpreviewsize.getheight());         } else {             mtextureview.setaspectratio(mpreviewsize.getheight(), mpreviewsize.getwidth());         }         configuretransform(width, height);         mmediarecorder = new mediarecorder();         manager.opencamera(cameraid, mstatecallback, null); // here crash!!!     } catch (cameraaccessexception e) {         toast.maketext(activity, "cannot access camera.", toast.length_short).show();         activity.finish();     } catch (nullpointerexception e) {         errordialog.newinstance(getstring(r.string.camera_error))                 .show(getchildfragmentmanager(), fragment_dialog);     } catch (interruptedexception e) {         throw new runtimeexception("interrupted while trying lock camera opening.");     } } 

and here how camera permission:

// mainactivity.java private void requestcamerapermission() {     if (activitycompat.shouldshowrequestpermissionrationale(this,             manifest.permission.camera)) {         snackbar.make(mrootview, r.string.permission_camera_rationale,                 snackbar.length_indefinite)                 .setaction(r.string.ok, new view.onclicklistener() {                     @override                     public void onclick(view view) {                         activitycompat.requestpermissions(mainactivity.this,                                 new string[]{manifest.permission.camera, manifest.permission.record_audio}, request_camera);                     }                 })                 .show();     } else {         activitycompat.requestpermissions(this, new string[]{manifest.permission.camera,                 manifest.permission.internet, manifest.permission.record_audio}, request_camera);     } }  @override public void onrequestpermissionsresult(int requestcode, @nonnull string[] permissions, @nonnull int[] grantresults) {     super.onrequestpermissionsresult(requestcode, permissions, grantresults);     if (requestcode == request_camera) {         if (grantresults.length >= 1 && grantresults[0] == packagemanager.permission_granted) {             getsupportfragmentmanager().begintransaction().replace(r.id.content_layout, camera2videofragment.newinstance()).commitallowingstateloss();             //getsupportfragmentmanager().begintransaction().replace(r.id.content_layout, new camerafragment()).commitallowingstateloss();         }     } } 

and here full manifest file:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.pixelslab.stickerpe">      <supports-screens         android:anydensity="true"         android:largescreens="true"         android:normalscreens="true"         android:smallscreens="true"         android:xlargescreens="true" />      <uses-permission android:name="android.permission.internet" />     <uses-permission android:name="android.permission.record_audio" />     <uses-permission android:name="android.permission.record_video" />     <uses-permission android:name="android.permission.camera" />      <application         android:name="com.gomo.minivideo.cameraapp"         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:roundicon="@mipmap/ic_launcher_round"         android:supportsrtl="true"         android:theme="@style/cameratheme">         <activity             android:name="com.gomo.minivideo.mainactivity"             android:configchanges="orientation|screensize|keyboardhidden"             android:launchmode="singletop"             android:screenorientation="portrait">             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>             <meta-data                 android:name="default-url"                 android:value="https://hugo775128583.github.io/main" />              <intent-filter android:order="1" android:autoverify="true">                 <action android:name="android.intent.action.view" />                  <category android:name="android.intent.category.default" />                 <category android:name="android.intent.category.browsable" />                  <data                     android:scheme="https"                     android:host="hugo775128583.github.io"                     android:pathprefix="/main" />             </intent-filter>             <intent-filter android:order="1" android:autoverify="true">                 <action android:name="android.intent.action.view" />                  <category android:name="android.intent.category.default" />                 <category android:name="android.intent.category.browsable" />                  <data                     android:scheme="http"                     android:host="hugo775128583.github.io"                     android:pathprefix="/main" />             </intent-filter>         </activity>          <service android:name="com.jb.zcamera.camera.processvideoservice" />          <activity android:name="com.gomo.minivideo.camera.shareactivity" />         <activity android:name="com.gomo.minivideo.camera.videoviewactivity" />     </application>  </manifest> 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -