- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Glass GDK 应用程序中获取相机时出现间歇性错误。该应用程序是一个简单的应用程序,它:
11-29 19:38:16.344: E/Camera(4551): Received CAMERA_MSG_RELEASE
11-29 19:38:16.493: D/Camera-JNI(4551): android_hardware_Camera_release - context->decStrong(thiz)
11-29 19:38:16.524: E/Camera(4551): Unknown message type 8192
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testcamera"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.example.testcamera.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger" />
</activity>
<activity
android:name="com.example.testcamera.CameraActivity"
android:label="@string/app_name" />
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="@string/glass_voice_trigger">
<constraints
camera="true"
network="true"
microphone="true" />
</trigger>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TestCamera</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="glass_voice_trigger">test the camera</string>
<!-- Menu item strings. -->
<string name="stop">Done</string>
<string name="tapforoptions">Tap for options</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<ImageView
android:id="@+id/bgPhoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/black_bg"
android:alpha="0.5" />
<LinearLayout android:id="@+id/queryLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_marginLeft="2dp"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#FFFFFF"
android:text="@string/hello_world" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_marginLeft="2dp"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#FFFFFF"
android:text="@string/hello_world" />
</LinearLayout>
<LinearLayout
android:id="@+id/resultLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/titleOfWork"
android:layout_width="wrap_content"
android:layout_marginLeft="2dp"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:text="@string/hello_world" />
<TextView
android:id="@+id/Singer"
android:layout_width="wrap_content"
android:layout_marginLeft="2dp"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#FFFFFF"
android:textSize="36sp"
android:textStyle="bold"
android:text="@string/hello_world" />
</LinearLayout>
<ProgressBar
android:id="@+id/my_progressBar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:layout_gravity="bottom"
android:layout_margin="10dp"
/>
<TextView
android:id="@+id/tap_instruction"
android:layout_width="fill_parent"
android:layout_marginLeft="2dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="bottom"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:textStyle="bold"
android:layout_margin="20dp"
android:text="@string/tapforoptions" />
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SurfaceView
android:id="@+id/surfaceView"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
package com.example.testcamera;
import java.io.File;
import com.google.android.glass.touchpad.Gesture;
import com.google.android.glass.touchpad.GestureDetector;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends Activity {
// App responds to voice trigger "test the camera", takes a picture with CameraActivity and then returns.
private static final String TAG = MainActivity.class.getSimpleName();
private static final int TAKE_PHOTO_CODE = 1;
private static final int PROGRESS_TIMEOUT = 30000; // in ms --> 10s
private static final String IMAGE_FILE_NAME = "/sdcard/ImageTest.jpg";
private boolean picTaken = false; // flag to indicate if we just returned from the picture taking intent
private String theImageFile = ""; // this holds the name of the image that was returned by the camera
private TextView text1;
private TextView text2;
private ProgressBar myProgressBar;
protected boolean mbActive;
private String inputQueryString;
private String queryCategory;
final Handler myHandler = new Handler(); // handles looking for the returned image file
private int numberOfImageFileAttempts = 0;
private String responseBody = "";
private TextToSpeech mSpeech;
private boolean readyForMenu = false;
private boolean gotImageMatch = false;
private GestureDetector mGestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v(TAG,"creating activity");
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
text1 = (TextView) findViewById(R.id.text1);
text2 = (TextView) findViewById(R.id.text2);
text1.setText("");
text2.setText("");
myProgressBar = (ProgressBar) findViewById(R.id.my_progressBar);
LinearLayout llResult = (LinearLayout) findViewById(R.id.resultLinearLayout);
TextView tvResult = (TextView) findViewById(R.id.tap_instruction);
llResult.setVisibility(View.INVISIBLE);
tvResult.setVisibility(View.INVISIBLE);
myProgressBar.setVisibility(View.INVISIBLE);
// Even though the text-to-speech engine is only used in response to a menu action, we
// initialize it when the application starts so that we avoid delays that could occur
// if we waited until it was needed to start it up
mSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// Do nothing.
}
});
mGestureDetector = createGestureDetector(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
protected void onResume() {
super.onResume();
if (!picTaken) {
Intent intent = new Intent(this, CameraActivity.class);
intent.putExtra("imageFileName",IMAGE_FILE_NAME);
startActivityForResult(intent,1);
}
else {
// do nothing
}
}
/*
* Send generic motion events to the gesture detector
*/
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
if (mGestureDetector != null) {
return mGestureDetector.onMotionEvent(event);
}
return false;
}
private GestureDetector createGestureDetector(Context context) {
GestureDetector gestureDetector = new GestureDetector(context);
//Create a base listener for generic gestures
gestureDetector.setBaseListener( new GestureDetector.BaseListener() {
@Override
public boolean onGesture(Gesture gesture) {
if (gesture == Gesture.TAP) {
// do something on tap
Log.v(TAG,"tap");
//if (readyForMenu) {
openOptionsMenu();
//}
return true;
} else if (gesture == Gesture.TWO_TAP) {
// do something on two finger tap
return true;
} else if (gesture == Gesture.SWIPE_RIGHT) {
// do something on right (forward) swipe
return true;
} else if (gesture == Gesture.SWIPE_LEFT) {
// do something on left (backwards) swipe
return true;
}
return false;
}
});
gestureDetector.setFingerListener(new GestureDetector.FingerListener() {
@Override
public void onFingerCountChanged(int previousCount, int currentCount) {
// do something on finger count changes
}
});
gestureDetector.setScrollListener(new GestureDetector.ScrollListener() {
@Override
public boolean onScroll(float displacement, float delta, float velocity) {
// do something on scrolling
return false;
}
});
return gestureDetector;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.stop:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
picTaken = true;
switch(requestCode) {
case (1) : {
if (resultCode == Activity.RESULT_OK) {
// TODO Extract the data returned from the child Activity.
Log.v(TAG,"onActivityResult");
File f = new File(IMAGE_FILE_NAME);
if (f.exists()) {
Log.v(TAG,"image file from camera was found");
Bitmap b = BitmapFactory.decodeFile(IMAGE_FILE_NAME);
Log.v(TAG,"bmp width=" + b.getWidth() + " height=" + b.getHeight());
ImageView image = (ImageView) findViewById(R.id.bgPhoto);
image.setImageBitmap(b);
text1 = (TextView) findViewById(R.id.text1);
text2 = (TextView) findViewById(R.id.text2);
text1.setText("Got a picture.");
text2.setText("\nSaved successfully to " + IMAGE_FILE_NAME);
LinearLayout llResult = (LinearLayout) findViewById(R.id.resultLinearLayout);
llResult.setVisibility(View.VISIBLE);
TextView line1 = (TextView) findViewById(R.id.titleOfWork);
TextView line2 = (TextView) findViewById(R.id.Singer);
TextView tap = (TextView) findViewById(R.id.tap_instruction);
line1.setText("");
line2.setText("");
tap.setVisibility(View.VISIBLE);
}
}
else {
Log.v(TAG,"onActivityResult returned bad result code");
finish();
}
break;
}
}
}
@Override
protected void onDestroy() {
//Close the Text to Speech Library
if(mSpeech != null) {
mSpeech.stop();
mSpeech.shutdown();
mSpeech = null;
Log.d(TAG, "TTS Destroyed");
}
super.onDestroy();
}
}
package com.example.testcamera;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.CompressFormat;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.ImageView;
public class CameraActivity extends Activity implements SurfaceHolder.Callback
{
private static final String TAG = CameraActivity.class.getSimpleName();
public static final int BUFFER_SIZE = 1024 * 8;
String imageFileName = "";
//a variable to store a reference to the Image View at the main.xml file.
private ImageView iv_image;
//a variable to store a reference to the Surface View at the main.xml file
private SurfaceView sv;
//a bitmap to display the captured image
private Bitmap bmp;
//Camera variables
//a surface holder
private SurfaceHolder sHolder;
//a variable to control the camera
private Camera mCamera;
//the camera parameters
private Parameters parameters;
@Override
public void onCreate(Bundle savedInstanceState)
{
Log.v(TAG,"onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
//get the Image View at the main.xml file
iv_image = (ImageView) findViewById(R.id.imageView);
sv = (SurfaceView) findViewById(R.id.surfaceView);
//Get a surface
sHolder = sv.getHolder();
sHolder.addCallback(this);
Bundle extras = getIntent().getExtras();
// get the image file name from the caller to save the 640x360 image
imageFileName = extras.getString("imageFileName");
}
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3)
{
Log.v(TAG,"surfaceChanged");
//get camera parameters
try {
parameters = mCamera.getParameters();
Log.v(TAG,"got parms");
//set camera parameters
parameters.setPreviewSize(640,360);
parameters.setPictureSize(1280,720);
//Camera.Parameters params = mCamera.getParameters();
parameters.setPreviewFpsRange(30000, 30000);
Log.v(TAG,"parms were set");
mCamera.setParameters(parameters);
mCamera.startPreview();
Log.v(TAG,"preview started");
//sets what code should be executed after the picture is taken
Camera.PictureCallback mCall = new Camera.PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
Log.v(TAG,"pictureTaken");
Log.v(TAG,"data bytes=" + data.length);
//decode the data obtained by the camera into a Bitmap
Bitmap bmp = decodeSampledBitmapFromData(data,640,360);
Log.v(TAG,"bmp width=" + bmp.getWidth() + " height=" + bmp.getHeight());
FileOutputStream outStream = null;
try{
FileOutputStream fos = new FileOutputStream(imageFileName);
final BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER_SIZE);
bmp.compress(CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
fos.close();
} catch (FileNotFoundException e){
Log.v(TAG, e.getMessage());
} catch (IOException e){
Log.v(TAG, e.getMessage());
}
Intent resultIntent = new Intent();
// TODO Add extras or a data URI to this intent as appropriate.
resultIntent.putExtra("testString","here is my test");
setResult(Activity.RESULT_OK, resultIntent);
finish();
}
};
Log.v(TAG,"set callback");
mCamera.takePicture(null, null, mCall);
}
catch (Exception e) {
try {
mCamera.release();
Log.e(TAG,"released the camera");
}
catch (Exception ee) {
// do nothing
Log.e(TAG,"error releasing camera");
Log.e(TAG,"Exception encountered relerasing camera, exiting:" + ee.getLocalizedMessage());
}
Log.e(TAG,"Exception encountered, exiting:" + e.getLocalizedMessage());
mCamera = null;
Intent resultIntent = new Intent();
setResult(Activity.RESULT_CANCELED, resultIntent);
finish();
}
}
public static Bitmap decodeSampledBitmapFromData(byte[] data,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length,options);
options.inSampleSize = 2; // saved image will be one half the width and height of the original (image captured is double the resolution of the screen size)
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeByteArray(data, 0, data.length,options);
}
public void surfaceCreated(SurfaceHolder holder)
{
Log.v(TAG,"surfaceCreated");
// The Surface has been created, acquire the camera and tell it where
// to draw the preview.
try {
mCamera = Camera.open();
Log.v(TAG,"acquired the camera");
mCamera.setPreviewDisplay(holder);
Log.v(TAG,"set surface holder for preview");
}
catch (Exception e) {
try {
mCamera.release();
Log.v(TAG,"released the camera");
}
catch (Exception ee) {
// do nothing
Log.e(TAG,"Exception encountered releasing camera, exiting:" + ee.getLocalizedMessage());
}
Log.e(TAG,"Exception encountered, exiting:" + e.getLocalizedMessage());
mCamera = null;
Intent resultIntent = new Intent();
setResult(Activity.RESULT_CANCELED, resultIntent);
finish();
}
}
public void surfaceDestroyed(SurfaceHolder holder)
{
Log.v(TAG,"surfaceDestroyed");
if (mCamera != null) {
mCamera.stopPreview();
//release the camera
mCamera.release();
//unbind the camera from this object
mCamera = null;
}
}
@Override
public void onPause()
{
Log.v(TAG,"onPause");
super.onPause();
if (mCamera != null) {
mCamera.stopPreview();
//release the camera
mCamera.release();
//unbind the camera from this object
mCamera = null;
}
}
@Override
public void onDestroy()
{
Log.v(TAG,"onDestroy");
super.onDestroy();
if (mCamera != null) {
mCamera.stopPreview();
//release the camera
mCamera.release();
//unbind the camera from this object
mCamera = null;
}
}
}
最佳答案
实际上,我刚刚查看了 Google Glass API 错误报告,并看到了其他人遇到的完全相同的问题:
https://code.google.com/p/google-glass-api/issues/detail?id=259
我确实注意到同样的事情,这与语音触发器有关。当我从滑动菜单中选择项目时,我没有看到相同的错误。
这可能可以关闭
* 后来 * 刚更新这个。我编写了一个小示例应用程序,可以重复尝试获取相机。项目在这里:https://github.com/dazza222/GlassCameraSnapshot
关于google-glass - 获取 Google Glass 相机时出现间歇性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20295479/
我的应用程序从一个有 5 个选项卡的选项卡栏 Controller 开始。一开始,第一个出现了它的名字,但其他四个没有名字,直到我点击它们。然后根据用户使用的语言显示名称。如何在选项卡栏出现之前设置选
我有嵌套数组 json 对象(第 1 层、第 2 层和第 3 层)。我的问题是数据表没有出现。任何相关的 CDN 均已导入。该表仅显示部分。我引用了很多网站,但都没有解决我的问题。 之前我使用标准表来
我正在尝试设置要显示的 Parse PFLoginViewController。这是我的一个 View Controller 的类。 import UIKit import Parse import
我遇到了这个问题,我绘制的对象没有出现在 GUI 中。我知道它正在被处理,因为数据被推送到日志文件。但是,图形没有出现。 这是我的一些代码: public static void main(Strin
我有一个树状图,其中包含出现这样的词...... TreeMap occurrence = new TreeMap (); 字符串 = 单词 整数 = 出现次数。 我如何获得最大出现次数 - 整数,
因此,我提示用户输入变量。如果变量小于 0 且大于 10。如果用户输入 10,我想要求用户再次输入数字。我问时间的时候输入4,它说你输入错误。但在第二次尝试时效果很好。例如:如果我输入 25,它会打印
我已经用 css overflow 属性做了一个例子。在这个例子中我遇到了一个溢出滚动的问题。滚动条出现了,但没有工作意味着每当将光标移动到滚动条时,在这个滚动条不活动的时间。我对此一无所知,所以请帮
我现在正在做一个元素。当您单击一个元素时,会出现以下信息,我想知道如何在您单击下一个元素而不重新单击同一元素时使其消失....例如,我的元素中有披萨,我想单击肉披萨看到浇头然后点击奶酪披萨看到浇头和肉
我有一个路由器模块,它将主题与正则表达式进行比较,并将出现的事件与一致的键掩码链接起来。 (它是一个简单的 url 路由过滤,如 symfony http://symfony.com/doc/curr
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: mysql_fetch_array() expects parameter 1 to be resource, bo
我在底部有一个带有工具栏的 View ,我正在使用 NavigationLink 导航到该 View 。但是当 View 出现时,工具栏显示得有点太低了。大约半秒钟后,它突然跳到位。它只会在应用程序启
我试图在我的应用程序上为背景音乐添加一个 AVAudioPlayer,我正在主屏幕上启动播放器,尝试在应用程序打开时开始播放但出现意外行为... 它播放并立即不断创建新玩家并播放这些玩家,因此同时播放
这是获取一个数字,获取其阶乘并将其加倍,但是由于基本情况,如果您输入 0,它会给出 2 作为答案,因此为了绕过它,我使用了 if 语句,但收到错误输入“if”时解析错误。如果你们能提供帮助,我真的很感
暂停期间抛出异常 android.os.DeadObjectException 在 android.os.BinderProxy.transactNative( native 方法) 在 androi
我已经为猜词游戏编写了一些代码。它从用户输入中读取字符并在单词中搜索该字符;根据字符是否在单词中,程序返回并控制一些变量。 代码如下: import java.util.Random; import
我是自动化领域的新手。这是我的简单 TestNG 登录代码,当我以 TestNG 身份运行该代码时,它会出现 java.lang.NullPointerException,双击它会突出显示我导航到 U
我是c#程序员,我习惯了c#的封装语法和其他东西。但是现在,由于某些原因,我应该用java写一些东西,我现在正在练习java一天!我要创建一个为我自己创建一个虚拟项目,以便让自己更熟悉 Java 的
我正在使用 Intellij,我的源类是 main.com.coding,我的资源文件是 main.com.testing。我将 spring.xml 文件放入资源文件中。 我的测试类位于 test.
我想要我的tests folder separate到我的应用程序代码。我的项目结构是这样的 myproject/ myproject/ myproject.py moduleon
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 6 年前。 因此,我尝试比较 2 个值,一个
我是一名优秀的程序员,十分优秀!