继续“应用程序无法在 Droid 中运行”调查:代码。有人能在这里看到任何明显的错误吗?
在我之前的问题中,我问过 System.currentTimeMillis()
在 Droid 中是否有错误,答案是否定的。
我认为我遇到的问题是在其他地方。当我等待我的 Droid 单独用户报告测试应用程序是否可以在他的手机上运行时,我想在这里发布一些相关代码。
请记住,我删除了代码中我认为不相关的所有内容(发布导致日志中第一个可疑行的代码)。我可能已经删除了有问题的代码,但我对此表示怀疑。它闻起来像是布局问题,而不是代码问题。我这样说是因为(参见最后一行,日志所在的位置)表面为 0。
谨致问候,Ari。
清单
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BeMeBB" android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="BeMeBBPref" android:label="@string/app_name">
</activity>
</application>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5" />
<supports-screens>
</supports-screens>
布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="0pt" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="bottom" android:background="#00000001">
<android.view.SurfaceView android:id="@+id/preview_LAND"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:keepScreenOn="true" android:layout_margin="0pt">
</android.view.SurfaceView>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:id="@+id/ACCELERATION_LINE" android:text="0 2 4 6 8 10 12 14 16 18 20 "
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:typeface="monospace" android:layout_weight="0"
android:textSize="20dp" android:textStyle="bold" android:textColor="@color/white"
android:layout_gravity="center_horizontal" android:paddingTop="0dp"
android:paddingLeft="0dp" android:background="#66000000" />
<TextView android:id="@+id/ACCELERATION" android:text="@string/Accelerometers"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:typeface="monospace" android:textStyle="bold"
android:layout_weight="0" android:textSize="20dp" android:textColor="@color/white"
android:layout_gravity="center_horizontal|top" android:paddingLeft="0dp"
android:background="#66000000" />
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:gravity="bottom" android:layout_weight="1">
<Button android:id="@+id/SAVE_LAND" android:text="@string/Save"
android:layout_width="wrap_content" android:gravity="left|bottom"
android:layout_height="wrap_content" android:layout_weight="0"
android:textSize="26dp" android:textColor="@color/black"
android:padding="20dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
代码
public class BeMeBB extends Activity implements OnClickListener, android.content.DialogInterface.OnClickListener, SensorEventListener {
private SurfaceView preview=null;
private SurfaceHolder previewHolder=null;
SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {
public void surfaceCreated(SurfaceHolder holder) {
DoRecording();
}
}; // End SurfaceHolder.Callback surfaceCallback
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main_land);
preview=(SurfaceView)findViewById(R.id.preview_LAND);
previewHolder=preview.getHolder();
previewHolder.addCallback(surfaceCallback);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
} // End OnCreate
private void DoRecording() {
m_worker.setSurfaceHolder(previewHolder);
} // End DoRecording
} // End class
在另一个类
public void setSurfaceHolder(SurfaceHolder previewHolder) {
m_previewHolder = previewHolder;
m_surface = m_previewHolder.getSurface();
Log.d("BeMeBB", "BeMeBBWorker m_surface=" + m_surface);
} //End setSurfaceHolder
日志中的结果(表面无效):< /强>
11-19 17:58:13.171 D/BeMeBB ( 1404): BeMeBBService m_surface=Surface(native-token=0)
In my previous question I asked if System.currentTimeMillis()
was buggy in Droid, and the answer was no.
I assume the problem I'm having is somewhere else. While I wait for my Droid lone-user to report if a test app works on his phone, I would like to post some relevant code here.
Please keep in mind that I removed everything in the code I thought would be irrelevant (posting the code leading to the first suspicious line in the log). I might have removed the code where the problem is, but I doubt it. It smells like a layout, not code, problem. I say this because (see last line, where the log is) the surface is 0.
Best regards, Ari.
MANIFEST
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BeMeBB" android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="BeMeBBPref" android:label="@string/app_name">
</activity>
</application>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5" />
<supports-screens>
</supports-screens>
LAYOUT
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="0pt" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="bottom" android:background="#00000001">
<android.view.SurfaceView android:id="@+id/preview_LAND"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:keepScreenOn="true" android:layout_margin="0pt">
</android.view.SurfaceView>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:id="@+id/ACCELERATION_LINE" android:text="0 2 4 6 8 10 12 14 16 18 20 "
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:typeface="monospace" android:layout_weight="0"
android:textSize="20dp" android:textStyle="bold" android:textColor="@color/white"
android:layout_gravity="center_horizontal" android:paddingTop="0dp"
android:paddingLeft="0dp" android:background="#66000000" />
<TextView android:id="@+id/ACCELERATION" android:text="@string/Accelerometers"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:typeface="monospace" android:textStyle="bold"
android:layout_weight="0" android:textSize="20dp" android:textColor="@color/white"
android:layout_gravity="center_horizontal|top" android:paddingLeft="0dp"
android:background="#66000000" />
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:gravity="bottom" android:layout_weight="1">
<Button android:id="@+id/SAVE_LAND" android:text="@string/Save"
android:layout_width="wrap_content" android:gravity="left|bottom"
android:layout_height="wrap_content" android:layout_weight="0"
android:textSize="26dp" android:textColor="@color/black"
android:padding="20dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
CODE
public class BeMeBB extends Activity implements OnClickListener, android.content.DialogInterface.OnClickListener, SensorEventListener {
private SurfaceView preview=null;
private SurfaceHolder previewHolder=null;
SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {
public void surfaceCreated(SurfaceHolder holder) {
DoRecording();
}
}; // End SurfaceHolder.Callback surfaceCallback
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main_land);
preview=(SurfaceView)findViewById(R.id.preview_LAND);
previewHolder=preview.getHolder();
previewHolder.addCallback(surfaceCallback);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
} // End OnCreate
private void DoRecording() {
m_worker.setSurfaceHolder(previewHolder);
} // End DoRecording
} // End class
IN ANOTHER CLASS
public void setSurfaceHolder(SurfaceHolder previewHolder) {
m_previewHolder = previewHolder;
m_surface = m_previewHolder.getSurface();
Log.d("BeMeBB", "BeMeBBWorker m_surface=" + m_surface);
} //End setSurfaceHolder
AND THE RESULT IN LOG (SURFACE IS NOT VALID):
11-19 17:58:13.171 D/BeMeBB ( 1404): BeMeBBService m_surface=Surface(native-token=0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在已确认,我的唯一 Droid 用户发回了 2 个日志文件:
使用 MediaRecorder.setPreviewDisplay (Surface sv) 的测试应用程序。它需要使用 getSurface,这会在 Droid 手机上的 API 5 中崩溃。
使用 Camera.setPreviewDisplay(SurfaceHolder sh) 的测试应用。它需要使用 MediaRecorder.setCamera 进行预览,但 setCamera 显然打破了 API 3 中的“已知限制 - 锁定相机”。
因此:我无法拥有适用于 1.5 和 2.0 的预览媒体记录器。所以我唯一的选择是,(确认 MediaRecorder.setCamera 在 Android2.0 中没有损坏 - 他们添加了解锁)是有两个单独的版本,一个用于 API 3,一个用于 API 5。
谢谢 commonsware 为我指出了正确的方向方向。为了安全起见,当我再次尝试使用 deviceanywhere 时,我会将状态更改为“已答复”。
Now it's confirmed, my lone Droid user sent back the 2 log files from:
A test app using MediaRecorder.setPreviewDisplay (Surface sv). It REQUIRES use of getSurface, which crashes in API 5 on Droid phone.
A test app using Camera.setPreviewDisplay(SurfaceHolder sh). It REQUIRES use of MediaRecorder.setCamera for preview, but setCamera is apparently broken "Known limitation - locked camera" in API 3.
So: I Cannot have a previewed media recorder that works on 1.5 and 2.0. So my only option is, (confirmed MediaRecorder.setCamera is not broken in Android2.0 - they added an unlock) is to have two separate versions , one for API 3 and one for API 5.
Thank you commonsware for pointing me in the right direction. I will change the status to "answered" once I try again with deviceanywhere, just to be safe.