- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我修改了来自 http://www.elektor.com/magazines/2012/march/android-switch-interface.2084156.lynkx 的示例蓝牙通信应用程序使其与我的 Arduino 同步。
在做了一些小改动后(如果是搜索栏则改为按钮),我无法让它运行。我的手机上出现了 FC 错误,如下所示。
我是 android/java 的新手,但已经编程多年。
我在网上搜索了 2 天似乎无法修复它。
11-13 18:41:58.127: E/AndroidRuntime(21448): java.lang.RuntimeException: Unable to start activity ComponentInfo{www.elektor.BTInterface/www.elektor.BTInterface.BluetoothChat}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.app.ActivityThread.access$600(ActivityThread.java:140)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.os.Looper.loop(Looper.java:137)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.app.ActivityThread.main(ActivityThread.java:4906)
11-13 18:41:58.127: E/AndroidRuntime(21448): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 18:41:58.127: E/AndroidRuntime(21448): at java.lang.reflect.Method.invoke(Method.java:511)
11-13 18:41:58.127: E/AndroidRuntime(21448): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
11-13 18:41:58.127: E/AndroidRuntime(21448): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
11-13 18:41:58.127: E/AndroidRuntime(21448): at dalvik.system.NativeStart.main(Native Method)
11-13 18:41:58.127: E/AndroidRuntime(21448): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
11-13 18:41:58.127: E/AndroidRuntime(21448): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:227)
11-13 18:41:58.127: E/AndroidRuntime(21448): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2604)
11-13 18:41:58.127: E/AndroidRuntime(21448): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2844)
11-13 18:41:58.127: E/AndroidRuntime(21448): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:252)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.app.Activity.setContentView(Activity.java:1867)
11-13 18:41:58.127: E/AndroidRuntime(21448): at www.elektor.BTInterface.BluetoothChat.onCreate(BluetoothChat.java:101)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.app.Activity.performCreate(Activity.java:5008)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-13 18:41:58.127: E/AndroidRuntime(21448): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
11-13 18:41:58.127: E/AndroidRuntime(21448): ... 11 more
11-13 18:42:02.872: I/Process(21448): Sending signal. PID: 21448 SIG: 9
这是我的代码和xmls
/**
* This is the main Activity that displays the current chat session.
*/
public class BluetoothChat extends Activity {
// Debugging
private static final String TAG = "BluetoothChat";
private static final boolean D = true;
// Message types sent from the BluetoothChatService Handler
public static final int MESSAGE_STATE_CHANGE = 1;
public static final int MESSAGE_READ = 2;
public static final int MESSAGE_WRITE = 3;
public static final int MESSAGE_DEVICE_NAME = 4;
public static final int MESSAGE_TOAST = 5;
// Key names received from the BluetoothChatService Handler
public static final String DEVICE_NAME = "device_name";
public static final String TOAST = "toast";
// Intent request codes
private static final int REQUEST_CONNECT_DEVICE_SECURE = 1;
private static final int REQUEST_CONNECT_DEVICE_INSECURE = 2;
private static final int REQUEST_ENABLE_BT = 3;
// Layout Views
private TextView mTitle;
private ListView mConversationView;
private EditText mOutEditText;
private WakeLock w1;
private String mConnectedDeviceName = null;
// Array adapter for the conversation thread
private ArrayAdapter<String> mConversationArrayAdapter;
// String buffer for outgoing messages
private StringBuffer mOutStringBuffer;
// Local Bluetooth adapter
private BluetoothAdapter mBluetoothAdapter = null;
// Member object for the chat services
private BluetoothRfcommClient mChatService = null;
// Activity mContext = null;
private int Servo1;
private int Servo2;
private int maxServo=120;
private Button sButton1;
private Button sButton2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(D) Log.e(TAG, "+++ ON CREATE +++");
// Set up the window layout
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
// Set up the custom title
mTitle = (TextView) findViewById(R.id.title_left_text);
mTitle.setText(R.string.app_name);
mTitle = (TextView) findViewById(R.id.title_right_text);
sButton1 = (Button) findViewById(R.id.button1);
sButton2 = (Button) findViewById(R.id.button2);
// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// If the adapter is null, then Bluetooth is not supported
if (mBluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
finish();
return;
}
}
@Override
public void onStart() {
super.onStart();
if(D) Log.e(TAG, "++ ON START ++");
// If BT is not on, request that it be enabled.
// setupChat() will then be called during onActivityResult
if (!mBluetoothAdapter.isEnabled()) {
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
// Otherwise, setup the chat session
} else {
if (mChatService == null) setupChat();
}
}
@Override
public synchronized void onResume() {
super.onResume();
if(D) Log.e(TAG, "+ ON RESUME +");
// Performing this check in onResume() covers the case in which BT was
// not enabled during onStart(), so we were paused to enable it...
// onResume() will be called when ACTION_REQUEST_ENABLE activity returns.
if (mChatService != null) {
// Only if the state is STATE_NONE, do we know that we haven't started already
if (mChatService.getState() == BluetoothRfcommClient.STATE_NONE) {
// Start the Bluetooth chat services
mChatService.start();
}
}
}
private void setupChat() {
Log.d(TAG, "setupChat()");
// Initialize the array adapter for the conversation thread
mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);
mConversationView = (ListView) findViewById(R.id.in);
mConversationView.setAdapter(mConversationArrayAdapter);
// Initialize the BluetoothChatService to perform bluetooth connections
mChatService = new BluetoothRfcommClient(this, mHandler);
// Initialize the buffer for outgoing messages
mOutStringBuffer = new StringBuffer("");
}
@Override
public synchronized void onPause() {
super.onPause();
if(D) Log.e(TAG, "- ON PAUSE -");
//w1.release();
}
@Override
public void onStop() {
super.onStop();
if(D) Log.e(TAG, "-- ON STOP --");
}
@Override
public void onDestroy() {
super.onDestroy();
// Stop the Bluetooth chat services
if (mChatService != null) mChatService.stop();
if(D) Log.e(TAG, "--- ON DESTROY ---");
}
private void ensureDiscoverable() {
if(D) Log.d(TAG, "ensure discoverable");
if (mBluetoothAdapter.getScanMode() !=
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
}
}
/**
* Sends a message.
* @param message A string of text to send.
*/
private void sendMessage(String message) {
// Check that we're actually connected before trying anything
if (mChatService.getState() != BluetoothRfcommClient.STATE_CONNECTED) {
Toast.makeText(this, R.string.not_connected, Toast.LENGTH_SHORT).show();
return;
}
// Check that there's actually something to send
if (message.length() > 0) {
// Get the message bytes and tell the BluetoothChatService to write
byte[] send = message.getBytes();
mChatService.write(send);
// Reset out string buffer to zero and clear the edit text field
mOutStringBuffer.setLength(0);
mOutEditText.setText(mOutStringBuffer);
}
}
// The action listener for the EditText widget, to listen for the return key
// The Handler that gets information back from the BluetoothChatService
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_STATE_CHANGE:
if(D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
switch (msg.arg1) {
case BluetoothRfcommClient.STATE_CONNECTED:
mTitle.setText(R.string.title_connected_to);
mTitle.append(mConnectedDeviceName);
mConversationArrayAdapter.clear();
break;
case BluetoothRfcommClient.STATE_CONNECTING:
mTitle.setText(R.string.title_connecting);
break;
//case BluetoothRfcommClient.STATE_LISTEN:
case BluetoothRfcommClient.STATE_NONE:
mTitle.setText(R.string.title_not_connected);
break;
}
break;
case MESSAGE_WRITE:
byte[] writeBuf = (byte[]) msg.obj;
// construct a string from the buffer
String writeMessage = new String(writeBuf);
mConversationArrayAdapter.add("Me: " + writeMessage);
break;
case MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
// construct a string from the valid bytes in the buffer
String readMessage = new String(readBuf, 0, msg.arg1);
mConversationArrayAdapter.add(mConnectedDeviceName+": " + readMessage);
UpdateScreen(readMessage);
// INSERT READING SWICTH
break;
case MESSAGE_DEVICE_NAME:
// save the connected device's name
mConnectedDeviceName = msg.getData().getString(DEVICE_NAME);
Toast.makeText(getApplicationContext(), "Connected to "
+ mConnectedDeviceName, Toast.LENGTH_SHORT).show();
break;
case MESSAGE_TOAST:
Toast.makeText(getApplicationContext(), msg.getData().getString(TOAST),
Toast.LENGTH_SHORT).show();
break;
}
}
};
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(D) Log.d(TAG, "onActivityResult " + resultCode);
switch (requestCode) {
case REQUEST_CONNECT_DEVICE_SECURE:
// When DeviceListActivity returns with a device to connect
if (resultCode == Activity.RESULT_OK) {
connectDevice(data, true);
}
break;
case REQUEST_CONNECT_DEVICE_INSECURE:
// When DeviceListActivity returns with a device to connect
if (resultCode == Activity.RESULT_OK) {
connectDevice(data, false);
}
break;
case REQUEST_ENABLE_BT:
// When the request to enable Bluetooth returns
if (resultCode == Activity.RESULT_OK) {
// Bluetooth is now enabled, so set up a chat session
setupChat();
} else {
// User did not enable Bluetooth or an error occured
Log.d(TAG, "BT not enabled");
Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show();
finish();
}
}
}
private void connectDevice(Intent data, boolean secure) {
// Get the device MAC address
String address = data.getExtras()
.getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
// Get the BLuetoothDevice object
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
// Attempt to connect to the device
mChatService.connect(device);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.option_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent serverIntent = null;
switch (item.getItemId()) {
case R.id.secure_connect_scan:
// Launch the DeviceListActivity to see devices and do scan
serverIntent = new Intent(this, DeviceListActivity.class);
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
return true;
case R.id.insecure_connect_scan:
// Launch the DeviceListActivity to see devices and do scan
serverIntent = new Intent(this, DeviceListActivity.class);
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_INSECURE);
return true;
case R.id.discoverable:
// Ensure this device is discoverable by others
ensureDiscoverable();
return true;
}
return false;
}
private void UpdateScreen(String txtMessage) {
}
public void onServoButtonClick(View view) {
switch (view.getId()){
case R.id.button1:
if (Servo1 < maxServo){
Servo1++;
sendMessage("P,"+Servo1);
}
case R.id.button2:
if (Servo1 > 0){
Servo1--;
sendMessage("P,"+Servo1);
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/GridLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:orientation="horizontal" >
<ListView
android:id="@+id/in"
android:layout_height="62dp"
android:layout_column="0"
android:layout_gravity="fill_horizontal"
android:layout_row="0"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="1"
android:text="@string/servo_1_up" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="2"
android:text="@string/servo_1_down" />
</GridLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="www.elektor.BTInterface">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<application android:label="@string/app_name"
android:icon="@drawable/app_icon" >
<activity android:name=".BluetoothChat"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="www.elektor.BTInterface.DeviceListActivity"
android:label="@string/select_device"
android:theme="@android:style/Theme.Dialog"
android:configChanges="orientation|keyboardHidden" />
</application>
</manifest>
最佳答案
当我将最小 SDK 提高到 16 时,我可以复制崩溃报告。所以在您的 list 中将 minSdkVersion
返回到 6:
<uses-sdk android:minSdkVersion="6" android:targetSdkVersion="16" />
关于android - 修改Android bluetoothchat示例后无法启动activity ComponentInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13366867/
我想在 Eclipse 中运行应用程序时在我的模拟器中实现蓝牙聊天。请帮助我。 . . 同样,我也想通过模拟器实现在线聊天。是否可以 ?如果是,请给我解决方案。 谢谢。 最佳答案 您可以在记事本中完成
我正在尝试使用 Android BluetoothChat 示例与 ELM327 OBDII 蓝牙加密狗进行通信。我可以毫无问题地连接到设备,从 BluetoothChat 到 ODBII 设备的消息
我已使用 BluetoothChat 示例在我的应用程序中构建蓝牙连接。应用程序正确连接,并正确存储所有配对设备,但未正确报告丢失的连接。 我的手机连接的设备由一 block 小电池供电,并在闲置约
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: getActionBar returns null 完整的 Android 菜鸟。我正在尝试从 Galaxy
好吧,我对为什么在下面标记的行中使用同步有点困惑。 对我来说,只有在代码块可能被多个线程访问的情况下才使用同步,但是该代码只能在其 run 方法中从该线程调用。 mConnectThread 的实例在
我使用 BluetoothChat 示例中的代码从蓝牙秤发送和接收字节数据。秤从设备接收命令,然后发回一个字节数组。{2,198,48,48,48,48,199,3}在我们的通信协议(protocol
我正在开发一个基于 BluetoothChat 示例代码的应用程序。我需要能够将包含十六进制值的字节数组写入输出流。我还需要解析输入流上的字节数组并读取十六进制值。这是我的代码,只是将十六进制值简单地
我目前正在尝试通过 BluetoothChat 示例应用程序与 ELM327 OBDII 蓝牙加密狗进行通信。我可以连接,因为我已经更改了 UUID,但是我只能收到启动命令和提示“>”来发送命令,每当
再次需要您的帮助:我正在使用 android 的蓝牙聊天示例,并尝试实现一个等待处理程序答复的函数: public void getOBD2Values() { Log.d(TAG, "Bef
我从 4 天开始就尝试运行一个小应用程序。我使用 BluetoothChat 的代码只是为了检查 BT 是否启用。如果不是,它应该显示启用对话框。我尝试在装有 Android 2.2 的 HTC Wi
背景 我正在开展一个项目,通过蓝牙(带有 HC-05 模块的 Arduino Uno)将 Android 应用程序与 Arduino 板连接起来。所以我从 Arduino 端开始开发,暂时使用 Pla
我开发了一个与串行端口设备通信的蓝牙应用程序,到目前为止通信(开始连接、数据交换和终止线程)工作正常。 但是,我在 Nexus 4 (Android 4.4.2) 上测试时遇到了一个奇怪的蓝牙连接问题
我只是在测试来自 http://developer.android.com/resources/samples/BluetoothChat/index.html .它在一些 android 手机(当然
我是一名优秀的程序员,十分优秀!