Bluetooth通信を使って車を制御するアプリを作っています。
のようなものthis
ですが、車を制御したいので、他のオプションがあります。
Bluetooth アダプターを無効にしてアプリケーションを起動すると、Bluetooth を有効にするよう 2 回求められます。
Bluetoothを有効にするためだけにこれを持っています
public void onStart() {
super.onStart();
Log.d(TAG, "Start - enable bluetooth");
if(adaptadorBT==null){
Toast.makeText(this, "Bluetooth não é suportado", Toast.LENGTH_LONG).show();
finish();
}
else
{
Intent ativarBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(ativarBtIntent,REQUEST_ENABLE_BT);
}
}
LogCatで私は持っています
10-26 18:34:22.861: D/Bluetoothcar(29095): Start - enable bluetooth
10-26 18:34:22.971: D/Bluetoothcar(29095): ON DESTROY
10-26 18:34:23.031: D/Bluetoothcar(29095): Start - enable bluetooth
マニフェスト:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bluetoothcar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.bluetoothcar.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>