Nao consigo usar o metodo write(bytes[] );
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_ENABLE_BT = 123;
private static final int REQUEST_MICROPHONE = 456;
Bt_connect bt_connect;
private static TextView subtitle;
private boolean firstTime = true;
public static Context context;
private SpeechToText stt;
private static TextView statusMessage;
private Button mic_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
statusMessage = (TextView) findViewById(R.id.temp);
subtitle = (TextView) findViewById(R.id.text_test);
mic_button = (Button) findViewById(R.id.mic_button);
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() == 0) {
mic_button.setEnabled(false);
showToast("Reconhecedor de voz nao encontrado");
}
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null) {
Toast.makeText(MainActivity.this,"Sem suporte a BlueTooth",Toast.LENGTH_LONG).show();
}
if(!btAdapter.isEnabled()) {
showToast("Ótimo! Hardware Bluetooth está funcionando :)");
Intent turnon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnon, REQUEST_ENABLE_BT);
showToast("Bluetooth Ligado");
}
if (ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.RECORD_AUDIO},REQUEST_MICROPHONE);
}
context = getApplicationContext();
if(isFirstTime()) {
setSST();
}
}
/........\
public void onClickBt_connect(View view)throws InterruptedException{
bt_connect = new Bt_connect("98:D3:34:90:F1:41");
bt_connect.start();
}
public void MsgToArduino(String msg) {
bt_connect.write("Teste\n".getBytes());
}
Stack Trace
java.lang.NullPointerException: Attempt to invoke virtual method 'void skynet.home_control.Bt_connect.write(byte[])' on a null object reference
at skynet.home_control.MainActivity.MsgToArduino(MainActivity.java:139)
at skynet.home_control.SpeechToText.toMainActivity(SpeechToText.java:94)
at skynet.home_control.SpeechToText.onPartialResults(SpeechToText.java:84)
at android.speech.SpeechRecognizer$InternalListener$1.handleMessage(SpeechRecognizer.java:459)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)