當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalBroadcastManager類代碼示例

本文整理匯總了Java中android.support.v4.content.LocalBroadcastManager的典型用法代碼示例。如果您正苦於以下問題:Java LocalBroadcastManager類的具體用法?Java LocalBroadcastManager怎麽用?Java LocalBroadcastManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LocalBroadcastManager類屬於android.support.v4.content包,在下文中一共展示了LocalBroadcastManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onNotificationPosted

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    String pack = sbn.getPackageName();
    String ticker = sbn.getNotification().tickerText.toString();
    Bundle extras = sbn.getNotification().extras;
    String title = extras.getString("android.title");
    String text = extras.getCharSequence("android.text").toString();

    Log.i("Package",pack);
    Log.i("Ticker",ticker);
    Log.i("Title",title);
    Log.i("Text",text);

    Intent msgrcv = new Intent("Msg");
    msgrcv.putExtra("package", pack);
    msgrcv.putExtra("ticker", ticker);
    msgrcv.putExtra("title", title);
    msgrcv.putExtra("text", text);

    LocalBroadcastManager.getInstance(context).sendBroadcast(msgrcv);


}
 
開發者ID:ayc3ue,項目名稱:NotificationsApp,代碼行數:24,代碼來源:MyNLS.java

示例2: onCreateView

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_station_lobby, container, false);

    IntentFilter filter = new IntentFilter();
    filter.addAction(StationActivity.ACTION_MAIN_SERVICE_BOUND);
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(getContext());
    bm.registerReceiver(mBroadcastReceiver, filter);

    lobbiesLayout = (LinearLayout) view.findViewById(R.id.lobbies_layout);

    update();

    return view;
}
 
開發者ID:gbl08ma,項目名稱:underlx,代碼行數:18,代碼來源:StationLobbyFragment.java

示例3: checksOnEventReceivedPushNotCalledWhenTelemetryDisabled

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Test
public void checksOnEventReceivedPushNotCalledWhenTelemetryDisabled() throws Exception {
  Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
  MapboxTelemetry.applicationContext = mockedContext;
  String aValidAccessToken = "validAccessToken";
  String aValidUserAgent = "MapboxTelemetryAndroid/";
  EventsQueue mockedEventsQueue = mock(EventsQueue.class);
  TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class);
  Callback mockedHttpCallback = mock(Callback.class);
  SchedulerFlusher mockedSchedulerFlusher = mock(SchedulerFlusher.class);
  Clock mockedClock = mock(Clock.class);
  LocalBroadcastManager mockedLocalBroadcastManager = mock(LocalBroadcastManager.class);
  boolean indifferentServiceBound = true;
  MapboxTelemetry theMapboxTelemetry = new MapboxTelemetry(mockedContext, aValidAccessToken, aValidUserAgent,
    mockedEventsQueue, mockedTelemetryClient, mockedHttpCallback, mockedSchedulerFlusher, mockedClock,
    mockedLocalBroadcastManager, indifferentServiceBound);
  Event mockedEvent = mock(Event.class);

  theMapboxTelemetry.onEventReceived(mockedEvent);

  verify(mockedEventsQueue, never()).push(eq(mockedEvent));
}
 
開發者ID:mapbox,項目名稱:mapbox-events-android,代碼行數:23,代碼來源:MapboxTelemetryTest.java

示例4: registerReceiverAction

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
/**
 * @param action
 */
private final void registerReceiverAction(final String action) {
    IntentFilter filter = new IntentFilter(action);
    LocalBroadcastManager.getInstance(mContext).registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (action.equals(intent.getAction())) {
                PluginInfo info = intent.getParcelableExtra("obj");
                if (info != null) {
                    switch (action) {
                        case ACTION_NEW_PLUGIN:
                            // 非常駐進程上下文
                            newPluginFound(info, intent.getBooleanExtra(RePluginConstants.KEY_PERSIST_NEED_RESTART, false));
                            break;
                        case ACTION_UNINSTALL_PLUGIN:
                            pluginUninstalled(info);
                            break;
                    }
                }
            }
        }
    }, filter);
}
 
開發者ID:wangyupeng1-iri,項目名稱:springreplugin,代碼行數:27,代碼來源:PluginMgr.java

示例5: onDestroy

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Override
    public void onDestroy() {
        if (server != null) {
            try {
                LocalBroadcastManager.getInstance(this).unregisterReceiver(messageReceiver);
//                server.stop();
                server.shutdownNow();
                server = null;
                Intent statusIntent = new Intent(DeskDroidService.SERVER_STATUS_CHANGE);
                statusIntent.putExtra("running", false);
                LocalBroadcastManager.getInstance(this).sendBroadcast(statusIntent);
            } catch (Exception e) {
            }
        }
        super.onDestroy();
    }
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:17,代碼來源:DeskDroidService.java

示例6: AndroidJSTPConnection

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
public AndroidJSTPConnection(String host, int port, boolean usesSSL, Context context) {
    mListeners = new CopyOnWriteArrayList<>();
    mTaggedCacheCalls = new ConcurrentHashMap<>();
    mConnectionState = STATE_NOT_CONNECTED;

    mNeedsRestoration = true;
    mContext = context;

    TCPTransport transport = new TCPTransport(host, port, usesSSL);
    mConnection = new Connection(transport, this);
    mConnection.addSocketListener(this);

    mBroadcastManager = LocalBroadcastManager.getInstance(mContext);

    initNetworkReceiver();
}
 
開發者ID:metarhia,項目名稱:metacom-android,代碼行數:17,代碼來源:AndroidJSTPConnection.java

示例7: onMessageReceived

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equals("/heartRate")) {
        final String message = new String(messageEvent.getData());
        Log.v("pactchat", "Message path received on watch is: " + messageEvent.getPath());
        Log.v("packtchat", "Message received on watch is: " + message);

        // Broadcast message to wearable activity for display
        Intent messageIntent = new Intent();
        messageIntent.setAction(Intent.ACTION_SEND);
        messageIntent.putExtra("heart", message);
        LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
    }
    else {
        super.onMessageReceived(messageEvent);
    }
}
 
開發者ID:PacktPublishing,項目名稱:Android-Wear-Projects,代碼行數:18,代碼來源:HeartListener.java

示例8: onCreate

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    s = new Setting();
    Language = s.getLang();
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    Language = preferences.getString("l",Language);
    setLanguage(Language);
    setContentView(R.layout.activity_main);
    BottomNavigationView navigation =  findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    fm=getSupportFragmentManager();
    fm.beginTransaction().add(R.id.content,new BlankFragment()).commit();
    Intent i = new Intent(this,SocketService.class);
    bindService(i,myConnection,Context.BIND_AUTO_CREATE);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    Log.e("Brodcast","Broadcast intent onCreate invoked");
    if(savedInstanceState == null){
    if(!registred){
        LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
                new IntentFilter("my-event"));
        Log.e("Registre","Broadcast intent  register");
        registred = true;
    }}

}
 
開發者ID:RRDL,項目名稱:CRT,代碼行數:27,代碼來源:MainActivity.java

示例9: cleanup

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
/**
 * Cleanup the object
 * Should be called when the object is not used anymore
 */
public void cleanup() {
    stopDiscovering();
    //close discovery service
    Log.d(TAG, "closeServices ...");

    if (mArdiscoveryService != null) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mArdiscoveryService.stop();

                mCtx.unbindService(mArdiscoveryServiceConnection);
                mArdiscoveryService = null;
            }
        }).start();
    }

    // unregister receivers
    LocalBroadcastManager localBroadcastMgr = LocalBroadcastManager.getInstance(mCtx);
    localBroadcastMgr.unregisterReceiver(mArdiscoveryServicesDevicesListUpdatedReceiver);
}
 
開發者ID:pkargupta,項目名稱:gyrodrone,代碼行數:26,代碼來源:DroneDiscoverer.java

示例10: onNotifactionShowedResult

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Override
public void onNotifactionShowedResult(Context context, XGPushShowedResult xgPushShowedResult) {
    LogUtils.d(TAG, xgPushShowedResult.toString());
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss", Locale.CHINA);

    Notice notice = new Notice();
    notice.setTitle(xgPushShowedResult.getTitle());
    notice.setContent(xgPushShowedResult.getContent());
    notice.setTime(simpleDateFormat.format(new Date()));
    notice.setUserId(getLoginUser());
    NoticeDao noticeDao = getDaoSession().getNoticeDao();
    noticeDao.insert(notice);

    //發送廣播通知更新
    Intent intent = new Intent(Constants.mainBroadcast);
    Bundle bundle = new Bundle();
    bundle.putInt("type", Constants.BROADCAST_TYPE_NOTICE);
    intent.putExtras(bundle);
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
 
開發者ID:NICOLITE,項目名稱:HutHelper,代碼行數:21,代碼來源:XinGeReceiver.java

示例11: checksUserAgentEvents

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Test
public void checksUserAgentEvents() throws Exception {
  Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
  MapboxTelemetry.applicationContext = mockedContext;
  String aValidAccessToken = "validAccessToken";
  String theEventsAndroidAgent = "MapboxEventsAndroid/";
  EventsQueue mockedEventsQueue = mock(EventsQueue.class);
  TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class);
  Callback mockedHttpCallback = mock(Callback.class);
  SchedulerFlusher mockedSchedulerFlusher = mock(SchedulerFlusher.class);
  Clock mockedClock = mock(Clock.class);
  LocalBroadcastManager mockedLocalBroadcastManager = mock(LocalBroadcastManager.class);
  boolean indifferentServiceBound = true;
  MapboxTelemetry theMapboxTelemetry = new MapboxTelemetry(mockedContext, aValidAccessToken, theEventsAndroidAgent,
    mockedEventsQueue, mockedTelemetryClient, mockedHttpCallback, mockedSchedulerFlusher, mockedClock,
    mockedLocalBroadcastManager, indifferentServiceBound);
  theMapboxTelemetry.enable();

  boolean validRequiredParameters = theMapboxTelemetry.checkRequiredParameters(aValidAccessToken,
    theEventsAndroidAgent);

  assertTrue(validRequiredParameters);
}
 
開發者ID:mapbox,項目名稱:mapbox-events-android,代碼行數:24,代碼來源:MapboxTelemetryTest.java

示例12: run

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Override
public void run() {
    try {
        sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    LocalBroadcastManager _manager = LocalBroadcastManager.getInstance(Global.get_applicationContext());
    SDFile _file;
    for (int _temp_i = 0; _temp_i < _files.size(); _temp_i++) {
        _file = _files.valueAt(_temp_i);
        _file.updateRubbish();
        Intent _update = new Intent(ACTION_UPDATE);
        _update.putExtra("index", _files.keyAt(_temp_i));
        _manager.sendBroadcast(_update);
    }
    Intent _finish = new Intent(ACTION_FINISH);
    _manager.sendBroadcast(_finish);
}
 
開發者ID:bonepeople,項目名稱:SDCardCleaner,代碼行數:20,代碼來源:UpdateRubbishThread.java

示例13: checksInvalidUserAgent

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Test
public void checksInvalidUserAgent() throws Exception {
  Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
  MapboxTelemetry.applicationContext = mockedContext;
  String aValidAccessToken = "validAccessToken";
  String aInvalidUserAgent = "invalidUserAgent";
  EventsQueue mockedEventsQueue = mock(EventsQueue.class);
  TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class);
  Callback mockedHttpCallback = mock(Callback.class);
  SchedulerFlusher mockedSchedulerFlusher = mock(SchedulerFlusher.class);
  Clock mockedClock = mock(Clock.class);
  LocalBroadcastManager mockedLocalBroadcastManager = mock(LocalBroadcastManager.class);
  boolean indifferentServiceBound = true;
  MapboxTelemetry theMapboxTelemetry = new MapboxTelemetry(mockedContext, aValidAccessToken, aInvalidUserAgent,
    mockedEventsQueue, mockedTelemetryClient, mockedHttpCallback, mockedSchedulerFlusher, mockedClock,
    mockedLocalBroadcastManager, indifferentServiceBound);
  theMapboxTelemetry.enable();

  boolean validRequiredParameters = theMapboxTelemetry.checkRequiredParameters(aValidAccessToken, aInvalidUserAgent);

  assertFalse(validRequiredParameters);
}
 
開發者ID:mapbox,項目名稱:mapbox-events-android,代碼行數:23,代碼來源:MapboxTelemetryTest.java

示例14: getInstance

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
static AccessTokenManager getInstance() {
    if (instance == null) {
        synchronized (AccessTokenManager.class) {
            if (instance == null) {
                Context applicationContext = FacebookSdk.getApplicationContext();
                LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(
                        applicationContext);
                AccessTokenCache accessTokenCache = new AccessTokenCache();

                instance = new AccessTokenManager(localBroadcastManager, accessTokenCache);
            }
        }
    }

    return instance;
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:17,代碼來源:AccessTokenManager.java

示例15: onCreate

import android.support.v4.content.LocalBroadcastManager; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_list_with_header);

	// Get the list component from the layout of the activity
	final WearableListView listView = (WearableListView) findViewById(R.id.devices_list);
	listView.setAdapter(mDeviceAdapter = new DevicesAdapter(listView));
	listView.setClickListener(mOnRowClickListener);
	listView.addOnScrollListener(mOnScrollListener);

	// The header will be moved as the list is scrolled
	mHeader = findViewById(R.id.header);

	// Register a broadcast receiver that will listen for events from the service.
	LocalBroadcastManager.getInstance(this).registerReceiver(mServiceBroadcastReceiver, BleProfileService.makeIntentFilter());
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:18,代碼來源:ScannerActivity.java


注:本文中的android.support.v4.content.LocalBroadcastManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。