I've two activities, A and B. Activity A catches the intent with a broadcast receiver, activity B fires it.
Code of activity A :
final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(floatyNetworkList.CONNECT_INTENT)){
Log.v("com.vittorio", "intent catched");
BluetoothDevice target = (BluetoothDevice) intent.getExtras().get("Device");
Thread T = new Thread(new ConnectThread(target, mHandler, recmsgs, DDB, "Connecting"));
T.start();
}
..
..
In activity A I also register the receiver with the following code:
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
filter.addAction(floatyNetworkList.CONNECT_INTENT);
registerReceiver(mReceiver, filter);
Code of activity B, my intent is fired when i select an item from my listview:
listBtview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> adapterBt, View myView, int myItemInt, long mylng) {
@SuppressWarnings("unchecked")
HashMap<String,String> selectedFromList =(HashMap<String,String>) (listBtview.getItemAtPosition(myItemInt));
Toast.makeText(getBaseContext(), selectedFromList.get("Name"), Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), Floaty.class);
intent.setAction(CONNECT_INTENT);
intent.putExtra("Device",fetchDevice(selectedFromList.get("Address")));
getApplicationContext().sendBroadcast(intent);
}
});
}
Problem is that activity A never receives the intent. I've also added the filter for my custom intent and updated properly my manifest.
Manifest code :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.vittorio.intent.action.CONNECT_INTENT"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Any ideas?
Thank you