本文整理匯總了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);
}
示例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;
}
示例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));
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
}
示例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;
}}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}