2011-07-19 6 views
1

cyanogenmod 7.03を実行しているHTC Desireを使用して、新しいアンドロイドのBluetoothコードをデバッグしてください。私は、アプリケーションがBluetoothコードによる実験...問題

閉じ例:mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) BluetoothAdapterに影響何かを追加イムはちょうど最初に/ブルートゥースをオン・オフするためのボタンを使用するBluetoothChatプロジェクトを使用して ...

毎回、私のアプリケーションが

を閉じるようにします

私のコードはJocActivity.javaから完全になっています - 私のメインで唯一のjavaファイル: これは多くのことがコメントされていますが、私は別のものを試していますが、基本的にはボタンを押すと、 Bluetoothアダプタが照会されます。 私はSDKが2.2に準拠していると思っているかもしれませんが、私の電話は2.3.3 私は2.3.3をダウンロードしていますが、そのslowwwwwwはここにあります:(

package test.joc; 

import android.app.Activity; 
import android.bluetooth.BluetoothAdapter; 
import android.bluetooth.BluetoothDevice; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 

public class JocActivity extends Activity implements OnClickListener{ 
    /** Called when the activity is first created. */ 

    // Debugging 
    private static final String TAG = "joc"; 
    private static final boolean D = true; 

    // 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; 

    // Local Bluetooth adapter 
    private BluetoothAdapter mBluetoothAdapter = null; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     Button button = (Button)findViewById(R.id.button1); 
     button.setOnClickListener(this); 

     // 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(); 
      Context context = getApplicationContext(); 
      CharSequence text = "Bluetooth enabled!"; 
      int duration = Toast.LENGTH_SHORT; 
      Toast.makeText(context, text, duration).show(); 
     } 
    }*/ 


// Implement the OnClickListener callback 
    public void onClick(View v) { 
     // do something when the button is clicked 
     Context context = getApplicationContext(); 
     int duration = Toast.LENGTH_SHORT; 
     if(D) Log.e(TAG, "++ ON START ++"); 

     //BluetoothAdapter.enable(); 
     //Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
     //InstanceOfAnActivity.startActivity(enableIntent); 
     /*Intent btIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
     btIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     context.startActivity(btIntent);*/ 

     // If BT is not on, request that it be enabled. 
     // setupChat() will then be called during onActivityResult 
     // Get local Bluetooth adapter 
     mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
     if (!mBluetoothAdapter.isEnabled()) {/* 
      Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
      startActivityForResult(enableIntent, REQUEST_ENABLE_BT); 
      Toast.makeText(context, "Bluetooth Enabled", duration).show(); 
     // Otherwise, setup the chat session 
     } else { 
      //if (mChatService == null) setupChat();*/ 
      Toast.makeText(context, "Ready", duration).show(); 
     } 
    } 
} 
+0

は、ログ内の例外とスタックトレースはありますか? –

答えて

1

あなたはおそらくあなたのAndroidManifest.xmlにbluetooth permissionを追加する必要があります。しかし、してください、logcat/DDMSであなたのスタックトレースを確認してください。

関連する問題