gpt4 book ai didi

Cordova:调整相机插件会使应用程序和相机崩溃

转载 作者:行者123 更新时间:2023-12-02 03:54:55 24 4
gpt4 key购买 nike

我试图调整 camera plugin查找我的设备可以支持的相机分辨率。以下是 CameraLauncher.java 的 takePicture 函数,其中包含我的调整:

/**
* Take a picture with the camera.
* When an image is captured or the camera view is cancelled, the result is returned
* in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult.
*
* The image can either be returned as a base64 string or a URI that points to the file.
* To display base64 string in an img tag, set the source to:
* img.src="data:image/jpeg;base64,"+result;
* or to display URI in an img tag
* img.src=result;
*
* @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
* @param returnType Set the type of image to return.
*/
public void takePicture(int returnType, int encodingType) {



// **********TWEAK************* //

camera = Camera.open(0);
Camera.Parameters params = camera.getParameters();
List<Camera.Size> sizes = params.getSupportedPictureSizes();
Camera.Size result = null;

for (int i=0;i<sizes.size();i++){
result = sizes.get(i);
Log.i("*********PictureSize************", "Supported Size. Width: " + result.width + "height : " + result.height);
}


// ********TWEAK ENDS********* //



// Save the number of images currently on disk for later
this.numPics = queryImgDB(whichContentStore()).getCount();

// Display camera
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

// Specify file so that large image is captured and returned
File photo = createCaptureFile(encodingType);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));

this.imageUri = Uri.fromFile(photo);

if (this.cordova != null) {
this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
}
else
LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}

我的调整成功了。它列出了我的设备支持的所有可能的分辨率。但是,当相机打开拍照时,相机(和我的应用程序)崩溃并显示“相机故障”的警报消息。此消息因不同设备而异。例如,在 Karbonn 平板电脑(中国硬件)上,消息显示“不幸的是,相机崩溃了”。我不知道发生了什么事。当我删除调整后,相机工作得很好。

请帮忙。

这是 Logcat 控制台:

04-30 15:57:05.815: D/dalvikvm(2598): Late-enabling CheckJNI
04-30 15:57:06.115: I/CordovaLog(2598): Changing log level to DEBUG(3)
04-30 15:57:06.115: I/CordovaLog(2598): Found start page location: index.html
04-30 15:57:06.115: D/Whitelist(2598): Unlimited access to network resources
04-30 15:57:06.125: D/CordovaActivity(2598): CordovaActivity.onCreate()
04-30 15:57:06.155: I/dalvikvm(2598): Could not find method org.apache.cordova.CordovaWebView.setWebContentsDebuggingEnabled, referenced from method org.apache.cordova.CordovaWebView.setup
04-30 15:57:06.155: W/dalvikvm(2598): VFY: unable to resolve static method 2439: Lorg/apache/cordova/CordovaWebView;.setWebContentsDebuggingEnabled (Z)V
04-30 15:57:06.155: D/dalvikvm(2598): VFY: replacing opcode 0x71 at 0x00be
04-30 15:57:06.265: D/CordovaWebView(2598): CordovaWebView is running on device made by: Karbonn
04-30 15:57:06.285: D/JsMessageQueue(2598): Set native->JS mode to 2
04-30 15:57:06.285: I/CordovaWebView(2598): Disabled addJavascriptInterface() bridge since Android version is old.
04-30 15:57:06.285: D/CordovaActivity(2598): CordovaActivity.init()
04-30 15:57:06.315: D/CordovaWebView(2598): >>> loadUrl(file:///android_asset/www/index.html)
04-30 15:57:06.315: D/PluginManager(2598): init()
04-30 15:57:06.365: D/CordovaWebView(2598): >>> loadUrlNow()
04-30 15:57:06.365: I/CordovaLog(2598): Changing log level to DEBUG(3)
04-30 15:57:06.365: I/CordovaLog(2598): Found start page location: index.html
04-30 15:57:06.365: D/Whitelist(2598): Unlimited access to network resources
04-30 15:57:06.365: D/CordovaActivity(2598): Resuming the App
04-30 15:57:06.365: D/CordovaActivity(2598): CB-3064: The errorUrl is null
04-30 15:57:06.385: D/ViewRootImpl(2598): pckname = com.jadesync.travelguide
04-30 15:57:06.395: I/dalvikvm(2598): threadid=3: reacting to signal 3
04-30 15:57:06.425: D/SoftKeyboardDetect(2598): Ignore this event
04-30 15:57:06.425: I/dalvikvm(2598): Wrote stack traces to '/data/anr/traces.txt'
04-30 15:57:06.485: D/libEGL(2598): loaded /system/lib/egl/libEGL_mali.so
04-30 15:57:06.555: D/libEGL(2598): loaded /system/lib/egl/libGLESv1_CM_mali.so
04-30 15:57:06.565: D/libEGL(2598): loaded /system/lib/egl/libGLESv2_mali.so
04-30 15:57:06.615: D/OpenGLRenderer(2598): Enabling debug mode 0
04-30 15:57:06.645: D/SoftKeyboardDetect(2598): Ignore this event
04-30 15:57:06.715: D/CordovaActivity(2598): onMessage(onPageStarted,file:///android_asset/www/index.html)
04-30 15:57:07.055: D/dalvikvm(2598): GC_CONCURRENT freed 124K, 3% free 6869K/7047K, paused 2ms+6ms
04-30 15:57:08.675: D/CordovaLog(2598): file:///android_asset/www/cordova.js: Line 966 : Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only.
04-30 15:57:08.675: I/Web Console(2598): Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only. at file:///android_asset/www/cordova.js:966
04-30 15:57:09.585: D/dalvikvm(2598): GC_CONCURRENT freed 24K, 3% free 7253K/7431K, paused 2ms+9ms
04-30 15:57:09.615: D/CordovaWebViewClient(2598): onPageFinished(file:///android_asset/www/index.html)
04-30 15:57:09.615: D/CordovaActivity(2598): onMessage(onPageFinished,file:///android_asset/www/index.html)
04-30 15:57:09.725: D/dalvikvm(2598): GC_FOR_ALLOC freed 11K, 3% free 7641K/7815K, paused 34ms
04-30 15:57:09.795: D/dalvikvm(2598): GC_FOR_ALLOC freed 9K, 3% free 8025K/8199K, paused 33ms
04-30 15:57:10.005: D/CordovaActivity(2598): onMessage(spinner,stop)
04-30 15:57:10.055: D/CordovaNetworkManager(2598): Connection Type: wifi
04-30 15:57:10.065: D/CordovaNetworkManager(2598): Connection Type: wifi
04-30 15:57:10.065: D/CordovaActivity(2598): onMessage(networkconnection,wifi)
04-30 15:57:11.625: D/CordovaActivity(2598): onMessage(spinner,stop)
04-30 15:57:19.155: D/CordovaWebViewClient(2598): onPageFinished(file:///android_asset/www/index.html#&ui-state=dialog)
04-30 15:57:19.155: D/CordovaActivity(2598): onMessage(onPageFinished,file:///android_asset/www/index.html#&ui-state=dialog)
04-30 15:57:24.555: D/SoftKeyboardDetect(2598): Ignore this event
04-30 15:57:25.455: D/SoftKeyboardDetect(2598): Ignore this event
04-30 15:57:28.465: D/SoftKeyboardDetect(2598): Ignore this event
04-30 15:57:31.005: D/SoftKeyboardDetect(2598): Ignore this event
04-30 15:57:31.105: W/webcoreglue(2598): updateFrameCache: pending style recalc, ignoring.
04-30 15:57:33.275: D/SoftKeyboardDetect(2598): Ignore this event
04-30 15:57:33.395: D/SoftKeyboardDetect(2598): Ignore this event
04-30 15:57:36.855: D/CordovaLog(2598): file:///android_asset/www/js/custom_script.js: Line 120 : success
04-30 15:57:36.855: I/Web Console(2598): success at file:///android_asset/www/js/custom_script.js:120
04-30 15:57:36.925: D/CordovaWebViewClient(2598): onPageFinished(file:///android_asset/www/index.html#/android_asset/www/index.html)
04-30 15:57:36.925: D/CordovaActivity(2598): onMessage(onPageFinished,file:///android_asset/www/index.html#/android_asset/www/index.html)
04-30 15:57:40.335: D/CordovaWebViewClient(2598): onPageFinished(file:///android_asset/www/index.html#view-my-packages)
04-30 15:57:40.335: D/CordovaActivity(2598): onMessage(onPageFinished,file:///android_asset/www/index.html#view-my-packages)
04-30 15:57:40.495: D/CordovaLog(2598): file:///android_asset/www/js/custom_script.js: Line 415 : [object Object]
04-30 15:57:40.495: I/Web Console(2598): [object Object] at file:///android_asset/www/js/custom_script.js:415
04-30 15:58:00.155: D/CordovaWebViewClient(2598): onPageFinished(file:///android_asset/www/index.html#view-my-packages&ui-state=dialog)
04-30 15:58:00.155: D/CordovaActivity(2598): onMessage(onPageFinished,file:///android_asset/www/index.html#view-my-packages&ui-state=dialog)
04-30 15:58:05.415: D/CordovaLog(2598): file:///android_asset/www/js/custom_script.js: Line 232 : Capture image
04-30 15:58:05.415: I/Web Console(2598): Capture image at file:///android_asset/www/js/custom_script.js:232
04-30 15:58:06.555: I/*********PictureSize************(2598): Supported Size. Width: 1280height : 1024
04-30 15:58:06.555: I/*********PictureSize************(2598): Supported Size. Width: 640height : 480
04-30 15:58:06.615: W/PluginManager(2598): THREAD WARNING: exec() call to Camera.takePicture blocked the main thread for 1192ms. Plugin should use CordovaInterface.getThreadPool().
04-30 15:58:06.625: D/CordovaActivity(2598): Paused the application!
04-30 15:58:06.625: D/CordovaWebView(2598): Handle the pause
04-30 15:58:06.705: D/OpenGLRenderer(2598): Flushing caches (mode 1)
04-30 15:58:06.735: D/OpenGLRenderer(2598): Flushing caches (mode 0)
04-30 15:58:07.555: D/CordovaActivity(2598): CordovaActivity.onDestroy()
04-30 15:58:07.625: D/CordovaWebView(2598): >>> loadUrlNow()
04-30 15:58:07.655: D/CordovaActivity(2598): onMessage(onPageStarted,about:blank)
04-30 15:58:07.695: D/CordovaWebViewClient(2598): onPageFinished(about:blank)
04-30 15:58:07.695: D/CordovaActivity(2598): onMessage(onPageFinished,about:blank)
04-30 15:58:07.695: D/CordovaActivity(2598): onMessage(exit,null)

最佳答案

解决了!!!

我犯了一个非常愚蠢的错误......我从未释放过相机。

这是正确的代码:

// **********TWEAK************* //

camera = Camera.open(0);
Camera.Parameters params = camera.getParameters();
List<Camera.Size> sizes = params.getSupportedPictureSizes();
Camera.Size result = null;

for (int i=0;i<sizes.size();i++){
result = sizes.get(i);
Log.i("*********PictureSize************", "Supported Size. Width: " + result.width + "height : " + result.height);
}

camera.release();


// ********TWEAK ENDS********* //

注意最后一个函数调用 - camera.release();

希望它能帮助别人:)

关于Cordova:调整相机插件会使应用程序和相机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23386045/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com