Bluetooth Activity - No Activity found to handle Intent

You must Login before you can answer or comment on any questions.

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!

— asked 7 months ago by Chris Bill
2 Comments
  • I was able to get it somewhat running. At the very least I don't see the error anymore. Here's my new intent:

    var intent = Ti.Android.createIntent({
        action:"BluetoothAdapter.ACTION_REQUEST_ENABLE",
        className:Ti.App.id+".Bluetooth_scaleActivity",
        packageName:Ti.App.id
    });
    Now it seems to be doing a loop and never starting the activity. The output below keeps showing up like the app is in a loop.
    [INFO][ActivityManager(  147)] START {act=BluetoothAdapter.ACTION_REQUEST_ENABLE cat=[android.intent.category.LAUNCHER] pkg=com.DearingGroup.btscale cmp=com.DearingGroup.btscale/.Bluetooth_scaleActivity (has extras) u=0} from pid 680
    [INFO][Choreographer(  680)] Skipped 105 frames!  The application may be doing too much work on its main thread.
    [INFO][Choreographer(  680)] Skipped 121 frames!  The application may be doing too much work on its main thread.
    [INFO][dalvikvm-heap(  680)] Grow heap (frag case) to 6.974MB for 614416-byte allocation
    [WARN][ActivityManager(  147)] Activity pause timeout for ActivityRecord{41208358 com.DearingGroup.btscale/.Bluetooth_scaleActivity}
    [INFO][Choreographer(  147)] Skipped 47 frames!  The application may be doing too much work on its main thread.
    [INFO][TiRootActivity(  680)] (main) [0,0] checkpoint, on root activity resume. activity = com.DearingGroup.btscale.Bluetooth_scaleActivity@410137a0
    [INFO][TiRootActivity(  680)] (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
    [INFO][Choreographer(  680)] Skipped 34 frames!  The application may be doing too much work on its main thread.
    Again, ANY help on this would be greatly appreciated.

    — commented 7 months ago by Chris Bill

  • It appears that when the activity is run the app restarts itself.

    — commented 7 months ago by Chris Bill

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.

Your Answer

Think you can help? Login to answer this question!