please how is the correct way to use broadcastReceiver in concert with Intent filters.. In my android_manifest.xml file I have those lines:
<activity android:name=".DataDisplayActivity" android:theme="@android:style/Theme.Holo.NoActionBar" android:icon="@drawable/icon_3d" android:label="AdvancedHyperXPositiveSuperFluousApp">
<intent-filter>
<action android:name="com.simekadam.blindassistant.UPDATE_GPS_UI"/>
<action android:name="com.simekadam.blindassistant.UPDATE_CONTEXT_UI"/>
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And in the activity I set the receiver with this function
registerReceiver(broadcastReceiver, null);
It fails on the null, obvi it needs the IntentFilter to be set and I can add it inline as param to the function, but I asking, how to use it with XML defined intent filters..Thank for your help
Teaser: I actually got it working with the inline set intent, but I am asking how to make it working with the intent set in XML..
you dont need to define intent-filters in your xml when you are using registerReceiver to receive broadcasts.
In your case, you should create a class which extends to BroadcastReceiver and then define that class file in your android's manifest file. for example:
class file:
package your.package.name;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyCustomReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals("com.simekadam.blindassistant.UPDATE_GPS_UI")){
//do something
}
else if(action.equals("com.simekadam.blindassistant.UPDATE_CONTEXT_UI")){
//do something
}
}
}
and addition in manifest:
<receiver android:name=".MyCustomReceiver" android:enabled="true">
<intent-filter>
<action android:name="com.simekadam.blindassistant.UPDATE_GPS_UI" />
<action android:name="com.simekadam.blindassistant.UPDATE_CONTEXT_UI" />
</intent-filter>
</receiver>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With