Back to project page C2Framework.
The source code is released under:
Apache License
If you think the Android project C2Framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package gaia.c2.receivers; /* w ww . jav a 2 s .c o m*/ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class ContextBroadcastReceiver extends BroadcastReceiver { public static final String CONTENT_MESSAGE_OK = "gaia.c2.MESSAGE_OK"; public static final String CONTENT_MESSAGE_FAILED = "gaia.c2.MESSAGE_FAILED"; public static final String CONTENT_FIELD = "gaia.c2.Content"; public static final String CONTENT_FIELD_ARRAY = "gaia.c2.ContentArray"; public static final String CONTENT_MIME_TYPE = "gaia.c2.MimeType"; public static final String EXCEPTION_FIELD = "gaia.c2.Exception"; private ContextEventReceiver eventReceiver; public ContextBroadcastReceiver() { throw new UnsupportedOperationException("use ContextBroadcastReceiver(ContextEventReceiver) instead"); } public ContextBroadcastReceiver(ContextEventReceiver eventReceiver) { this.eventReceiver = eventReceiver; } @Override public void onReceive(Context androidContext, Intent intent) { final String action = intent.getAction(); if (action != null) { if (action.equals(CONTENT_MESSAGE_OK)) { eventReceiver.onSuccess(intent.getExtras()); } else if (action.equals(CONTENT_MESSAGE_FAILED)) { eventReceiver.onFail(intent.getExtras(), (Exception) intent.getExtras().getSerializable(EXCEPTION_FIELD)); } else { throw new UnsupportedOperationException("invalid action '" + action + "'"); } } else { throw new UnsupportedOperationException("invalid action null"); } } }