This is outgoing class.which is broadcast the Intent through sendBroadcast method :
public class SendingBroadcastIntent { |
| public static final String CUSTOM_INTENT = "com.custom.intent.action.TEST"; |
| System.out.println("HIT OUTGOING"); |
| i.setAction(CUSTOM_INTENT);
Bundle extras = new Bundle(); |
extras.putInt("progress", progressPercentage);
i.putExtras(extras);
| context.sendBroadcast(i); |
This is incoming class.which is receive broadcast Intenet :
public class IncomingIntentReceiver extends BroadcastReceiver { |
| public void onReceive(Context context, Intent intent) { |
| if (intent.getAction().equals(OutgoingReceiver.CUSTOM_INTENT)) { |
| System.out.println("RECEIVE THE INTENT"); |
Register Receiver in The Android Manifest:
<receiver android:name=".IncomingIntentReceiver" android:enabled="true">
Thanks Pradeep for sharing your knowledge with us.
ReplyDeletetrucking factoring
What's OutgoingReceiver????
ReplyDeleteSendingBroadcastIntent class send broadcast intent with data .you can call this is OutgoingReceiver class .
Deleteyou can write down in IncomingIntentReceiver class
if (intent.getAction().equals(SendingBroadcastIntent.CUSTOM_INTENT)) {
System.out.println("RECEIVE THE INTENT");
}
}
This comment has been removed by the author.
ReplyDelete