Java Code Examples for android.support.v4.content.LocalBroadcastManager#sendBroadcast()

The following examples show how to use android.support.v4.content.LocalBroadcastManager#sendBroadcast() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SKActivityRecognitionIntentService.java    From SensingKit-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {

    // If the intent contains an update
    if (ActivityRecognitionResult.hasResult(intent)) {

        // Get the update
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

        Intent i = new Intent(BROADCAST_UPDATE);
        i.putExtra(RECOGNITION_RESULT, result);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
        manager.sendBroadcast(i);
    }

}
 
Example 2
Source File: FolioActivity.java    From ankihelper with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();

    if (outState != null)
        outState.putParcelable(BUNDLE_READ_POSITION_CONFIG_CHANGE, lastReadPosition);

    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
    localBroadcastManager.unregisterReceiver(searchReceiver);
    localBroadcastManager.unregisterReceiver(closeBroadcastReceiver);

    if (r2StreamerServer != null) {
        r2StreamerServer.stop();
    }

    if (isFinishing())
        localBroadcastManager.sendBroadcast(new Intent(FolioReader.ACTION_FOLIOREADER_CLOSED));
}
 
Example 3
Source File: ChatActivity.java    From Socket.io-FLSocketIM-Android with MIT License 5 votes vote down vote up
private void sendMsgAfter(MessageModel messageModel) {
    messageList.add(messageModel);
    adapter.notifyDataSetChanged();
    listView.smoothScrollToPosition(messageList.size() - 1);

    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(mContext);
    localBroadcastManager.sendBroadcast(new Intent(BroadcastConstant.updateConversation));
}
 
Example 4
Source File: DfuUploadCancelFragment.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onCancel(final DialogInterface dialog) {
	// Send broadcast message to the DfuService
	final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getActivity());
	final Intent pauseAction = new Intent(DfuService.BROADCAST_ACTION);
	pauseAction.putExtra(DfuService.EXTRA_ACTION, DfuService.ACTION_RESUME);
	manager.sendBroadcast(pauseAction);
}
 
Example 5
Source File: DfuUploadCancelFragment.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	// Send broadcast message to the DfuService
	final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getActivity());
	final Intent pauseAction = new Intent(DfuService.BROADCAST_ACTION);
	pauseAction.putExtra(DfuService.EXTRA_ACTION, DfuService.ACTION_PAUSE);
	manager.sendBroadcast(pauseAction);
}
 
Example 6
Source File: HandstandApduService.java    From HandstandPay with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onDeactivated(int reason) {
    isProcessing = false;
    Context context = getApplicationContext();
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
    lbm.sendBroadcast(new Intent(PAYMENT_SENT));
}
 
Example 7
Source File: LogPrinter.java    From BlockCanary with Apache License 2.0 5 votes vote down vote up
private void notifyBlockEvent(long endTime,long startTime){
    Log.e(TAG,"block time:"+(endTime-startTime));

    LocalBroadcastManager manager= LocalBroadcastManager.getInstance(mContext);
    Intent intent=new Intent(ACTION_BLOCK);
    intent.putExtra(EXTRA_START_TIME,startTime);
    intent.putExtra(EXTRA_FINISH_TIME,endTime);
    manager.sendBroadcast(intent);
}
 
Example 8
Source File: MyTaskService.java    From android-gcmnetworkmanager with Apache License 2.0 5 votes vote down vote up
@Override
public int onRunTask(TaskParams taskParams) {
    Log.d(TAG, "onRunTask: " + taskParams.getTag());

    String tag = taskParams.getTag();

    // Default result is success.
    int result = GcmNetworkManager.RESULT_SUCCESS;

    // Choose method based on the tag.
    if (MainActivity.TASK_TAG_WIFI.equals(tag)) {
        result = doWifiTask();
    } else if (MainActivity.TASK_TAG_CHARGING.equals(tag)) {
        result = doChargingTask();
    } else if (MainActivity.TASK_TAG_PERIODIC.equals(tag)) {
        result = doPeriodicTask();
    }

    // Create Intent to broadcast the task information.
    Intent intent = new Intent();
    intent.setAction(ACTION_DONE);
    intent.putExtra(EXTRA_TAG, tag);
    intent.putExtra(EXTRA_RESULT, result);

    // Send local broadcast, running Activities will be notified about the task.
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
    manager.sendBroadcast(intent);

    // Return one of RESULT_SUCCESS, RESULT_FAILURE, or RESULT_RESCHEDULE
    return result;
}
 
Example 9
Source File: PopUpActivity.java    From microbit with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    Log.d("PopUpActivity", "onDestroy()");

    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);

    localBroadcastManager.sendBroadcast(new Intent(INTENT_ACTION_DESTROYED));
    localBroadcastManager.unregisterReceiver(broadcastReceiver);
    releaseViews();
}
 
Example 10
Source File: HomeContactFrament.java    From Socket.io-FLSocketIM-Android with MIT License 5 votes vote down vote up
private void clearUnread(int position){

        // 发送一个进入聊天的通知,让消息列表界面刷新UI
        LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(mContext);

        UserModel user = users.get(position);
        String conversationId = user.getName();
        Intent intent = new Intent(BroadcastConstant.clearUnreadMessage);
        intent.putExtra("conversation", conversationId);
        localBroadcastManager.sendBroadcast(intent);
    }
 
Example 11
Source File: HomeDashService.java    From homeDash with Apache License 2.0 4 votes vote down vote up
private void clearBrowserCache(){
    Intent intent = new Intent(BrowserActivity.BROADCAST_ACTION_CLEAR_BROWSER_CACHE);
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(getApplicationContext());
    bm.sendBroadcast(intent);
}
 
Example 12
Source File: HomeDashService.java    From homeDash with Apache License 2.0 4 votes vote down vote up
private void switchScreenOn(){
    Intent intent = new Intent(BrowserActivity.BROADCAST_ACTION_SCREEN_ON);
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(getApplicationContext());
    bm.sendBroadcast(intent);
}
 
Example 13
Source File: BroadcastUtil.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
public static final void sendBroadcast(Context context, String action) {
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
    lbm.sendBroadcast(new Intent(action));
}
 
Example 14
Source File: BroadcastUtil.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
public static final void sendBroadcast(Context context, Intent intent) {
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
    lbm.sendBroadcast(intent);
}
 
Example 15
Source File: KADataService.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 4 votes vote down vote up
private void broadcastOfflineVideoSetChanged() {
	LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
	Intent intent = new Intent(Constants.ACTION_OFFLINE_VIDEO_SET_CHANGED);
	broadcastManager.sendBroadcast(intent);
}
 
Example 16
Source File: PopUpActivity.java    From microbit with Apache License 2.0 3 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    GoogleAnalyticsManager.getInstance().sendViewEventStats(PopUpActivity.class.getSimpleName());

    Log.d("PopUpActivity", "onCreate() popuptype = " + getIntent().getIntExtra(INTENT_EXTRA_TYPE, PopUp.TYPE_NONE));
    setContentView(R.layout.activity_popup);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    initViews();

    isCancelable = getIntent().getBooleanExtra(INTENT_EXTRA_CANCELABLE, true);

    setLayout(getIntent());

    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);

    IntentFilter popupActivityFilter = new IntentFilter();
    popupActivityFilter.addAction(INTENT_ACTION_CLOSE);
    popupActivityFilter.addAction(INTENT_ACTION_UPDATE_PROGRESS);
    popupActivityFilter.addAction(INTENT_ACTION_UPDATE_LAYOUT);

    //listen for close or update progress.xml request
    localBroadcastManager.registerReceiver(broadcastReceiver, popupActivityFilter);

    //notify creation of activity to calling code PopUp class
    localBroadcastManager.sendBroadcast(new Intent(INTENT_ACTION_CREATED));
}
 
Example 17
Source File: WXPayEntryActivity.java    From EasyPay with Apache License 2.0 3 votes vote down vote up
/**
 * 发送微信支付结果的本地广播
 * 本地广播比全局广播效率高,更安全
 * <p>
 * 接收者请参考:
 * http://www.cnblogs.com/trinea/archive/2012/11/09/2763182.html
 *
 * @param resultCode
 */
private void sendPayResultBroadcast(int resultCode) {
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
    Intent payResult = new Intent();
    payResult.setAction(WECHAT_PAY_RESULT_ACTION);
    payResult.putExtra(WECHAT_PAY_RESULT_EXTRA, resultCode);
    broadcastManager.sendBroadcast(payResult);
    finish();
}