views:

20

answers:

1

i have this activity that holds 2 intent filters and my problem is not to use this activity for devices 1.6 and before since i wanted them to use the native contacts.

thanks!

+1  A: 
public class A extends Activity {
    public A {
        IntentFilter filter = new IntentFilter(YOUR_BROADCAST);
        filter.addAction(YOUR_BROADCAST_2);
        registerReceiver(mReceiver, filter);
    }

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // code here
        }
    };
}

First you declare your filter - you can add multiple actions to single filter. Then you need to register it with BroadcastReceiver that will serve then upon arrival.

Marcin Gil
basically this is a work-around?
mikedroid
Question title is "how to add IntentFilter in an Activity code" :) So basically if you need to judge your functionality based on device - this would be the way to go - if you have 1.6 only available, check it in the code and don't register filters.
Marcin Gil