Hello everyone,
I've started diving into developing a Bluetooth Android module for Titanium. I've got the device to tell me if Bluetooth is enabled or not but now I'm having some trouble creating the little dialog box that will allow them to enable Bluetooth within the app. I know you have to set an intent and start an activity (Android is somewhat new to me).
When I tried adding the activity to the module all hell broke loose so I'm trying to get it to run on the titanium side. Here's my code:
var intent = Ti.Android.createIntent({ action:"BluetoothAdapter.ACTION_REQUEST_ENABLE" }); intent.putExtra("REQUEST_ENABLE_BT", 1); Ti.Android.currentActivity.startActivityForResult(intent, function(e){ if(e.resultCode == Ti.Android.RESULT_OK){ e.intent.getStringExtra("REQUEST_ENABLE_BT"); alert("hit"); }else if(e.resultCode == Ti.Android.RESULT_OK){ alert("failed"); }else{ alert(e); } });Got information for this in the [Android Documentation] (http://developer.android.com/guide/topics/connectivity/bluetooth.html). I'll save you the trouble of searching through that document so here's the code that they provide that I am trying to replicate in Titanium:
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);Here's some information that they give in the document.
"The REQUEST_ENABLE_BT constant passed to startActivityForResult() is a locally defined integer (which must be greater than 0), that the system passes back to you in your onActivityResult() implementation as the requestCode parameter. If enabling Bluetooth succeeds, your activity receives the RESULT_OK result code in the onActivityResult() callback. If Bluetooth was not enabled due to an error (or the user responded "No") then the result code is RESULT_CANCELED."
As the title states, I'm getting the error No Activity found to handle Intent. Below is the full error:
{No Activity found to handle Intent {act=BluetoothAdapter.ACTION_REQUEST_ENABLE (has extras) }, source = org.appcelerator.titanium.proxy.ActiveProxy@41a8ce60, requestCode = 1}Any help would be AMAZING! Thanks!
2 Answers
I ended up figuring out how to make the intent work on the module side instead. The code in Java:
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); getActivity().startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);using getActivity() was the key.
Hi, we have recently received an Android module for this purpose: Android Bluetooth
Your Answer
Think you can help? Login to answer this question!