本文整理汇总了Java中android.content.BroadcastReceiver类的典型用法代码示例。如果您正苦于以下问题:Java BroadcastReceiver类的具体用法?Java BroadcastReceiver怎么用?Java BroadcastReceiver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BroadcastReceiver类属于android.content包,在下文中一共展示了BroadcastReceiver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onNewNotification
import android.content.BroadcastReceiver; //导入依赖的package包/类
/**
* Gets notifications from other apps.
* In order to work to must enable the access of notifications in your device settings
*
* @param callback
* @status TOREVIEW
*/
@ProtoMethod
public void onNewNotification(final ReturnInterface callback) {
if (!isNotificationServiceRunning()) {
showNotificationsManager();
}
onNotification = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ReturnObject ret = new ReturnObject();
ret.put("package", intent.getStringExtra("package"));
ret.put("title", intent.getStringExtra("title"));
ret.put("text", intent.getStringExtra("text"));
callback.event(ret);
}
};
LocalBroadcastManager.getInstance(getContext()).registerReceiver(onNotification, new IntentFilter("Msg"));
}
示例2: unregisterReceiver
import android.content.BroadcastReceiver; //导入依赖的package包/类
/**
* unregisterReceiver
*
* @param loaded mLoaded
*/
public static void unregisterReceiver(ApkLoaded loaded) {
String key = loaded.getApkPath();
if (!CONTEXT_MAP.containsKey(key)) {
return;
}
Context context = CONTEXT_MAP.get(key);
if (BROADCAST_RECEIVER_MAP.containsKey(key)) {
LinkedList<BroadcastReceiver> receivers = BROADCAST_RECEIVER_MAP.get(key);
for (int i = 0; i < receivers.size(); i++) {
context.unregisterReceiver(receivers.get(i));
}
BROADCAST_RECEIVER_MAP.remove(key);
}
CONTEXT_MAP.containsKey(key);
}
示例3: newBroadcastReceiver
import android.content.BroadcastReceiver; //导入依赖的package包/类
@CheckResult
private BroadcastReceiver newBroadcastReceiver() {
return new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case ServiceAction.HIDE:
resetViewParams(mHideParams);
break;
case ServiceAction.SHOW:
resetViewParams(mParams);
break;
case ServiceAction.STOP:
stopSelf();
break;
case ServiceAction.START:
default:
throw new IllegalStateException();
}
}
};
}
示例4: registMyRecivier
import android.content.BroadcastReceiver; //导入依赖的package包/类
private void registMyRecivier()
{
filter = new IntentFilter(Constant.REENTER);
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(Constant.REENTER))
{
LogUtil.d("dfy","收到重新登录的请求");
isNeedJump = false;
// LogUtil.d("dfy","loginBiz = "+loginBiz);
loginBiz = null;
loginBiz = new LoginBiz(loginInstance);
// LogUtil.d("dfy","loginBiz = "+loginBiz);
login();
}
}
};
}
示例5: RegisterActivity
import android.content.BroadcastReceiver; //导入依赖的package包/类
public RegisterActivity() {
if (HotFix.PREVENT_VERIFY) {
System.out.println(VerifyLoad.class);
}
this.recever = new BroadcastReceiver(this) {
final /* synthetic */ RegisterActivity this$0;
{
if (HotFix.PREVENT_VERIFY) {
System.out.println(VerifyLoad.class);
}
this.this$0 = this$0;
}
public void onReceive(Context arg0, Intent arg1) {
this.this$0.finish();
}
};
}
示例6: onResume
import android.content.BroadcastReceiver; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction("FINISH_ACTIVITY");
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(isAboveLolipop) {
finishAndRemoveTask();
} else {
finish();
}
}
};
registerReceiver(receiver, filter);
}
示例7: initialize
import android.content.BroadcastReceiver; //导入依赖的package包/类
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param cordova The context of the main Activity.
* @param webView The CordovaWebView Cordova is running in.
*/
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
this.connectionCallbackContext = null;
// We need to listen to connectivity events to update navigator.connection
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
if (this.receiver == null) {
this.receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// (The null check is for the ARM Emulator, please use Intel Emulator for better results)
if(NetworkManager.this.webView != null)
updateConnectionInfo(sockMan.getActiveNetworkInfo());
}
};
webView.getContext().registerReceiver(this.receiver, intentFilter);
}
}
示例8: initOutgoingBroadcastReceiver
import android.content.BroadcastReceiver; //导入依赖的package包/类
/**
* Broadcast receiver to check outgoing call
*/
private void initOutgoingBroadcastReceiver() {
OutgoingBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
isInCall = true;
if (isInCall == true) {
smallMediaPlayer = SmallMediaPlayer.getInstance(context);
bigNotification = false;
pauseMedia();
}
}
}
};
IntentFilter filter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
context.registerReceiver(OutgoingBroadcastReceiver, filter);
}
示例9: callPvDataService
import android.content.BroadcastReceiver; //导入依赖的package包/类
private void callPvDataService() {
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
if (intent.getBooleanExtra("success", true)) {
updateScreen();
} else {
Toast.makeText(context, intent.getStringExtra("message"),
Toast.LENGTH_LONG).show();
}
}
};
IntentFilter intentFilter = new IntentFilter(PvDataService.class.getName());
LocalBroadcastManager.getInstance(getContext())
.registerReceiver(broadcastReceiver, intentFilter);
PvDataService.callLive(getContext(), picked.year, picked.month, picked.day);
}
示例10: defineBroadcastReceiverFor
import android.content.BroadcastReceiver; //导入依赖的package包/类
private BroadcastReceiver defineBroadcastReceiverFor(final FlowableEmitter<SensorRecord> subscriber){
return new BroadcastReceiver() {
Timer timer = new Timer();
long prevCallTime = new Date().getTime();
@Override
public void onReceive(Context context, Intent intent) {
long actualTime = new Date().getTime();
long delay = calculateDiffDelay(prevCallTime, actualTime);
prevCallTime = actualTime;
subscriber.onNext(new WifiMeasurementsRecord(wifiManager.getScanResults()));
if (delay > 0)
timer.schedule(createScanTask(), delay);
else
createScanTask().run();
}
};
}
示例11: onCreateView
import android.content.BroadcastReceiver; //导入依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mView = inflater.inflate(R.layout.seal_mine_fragment, container, false);
isDebug = getContext().getSharedPreferences("config", getContext().MODE_PRIVATE).getBoolean("isDebug", false);
initViews(mView);
initData();
//设置广播接收者 更新用户头像和昵称
BroadcastManager.getInstance(getActivity()).addAction(SealConst.CHANGEINFO, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateUserInfo();
}
});
compareVersion();
return mView;
}
示例12: initBroadcastReceiver
import android.content.BroadcastReceiver; //导入依赖的package包/类
/**
* 注册广播接收者
*/
private void initBroadcastReceiver() {
mBroadcastManager = LocalBroadcastManager.getInstance(getActivity());
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(AppDelegate.ACTION_T_FINANCING_ACCOUNT_SEARCH);
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
arguments = intent.getStringExtra(AppDelegate.ACTION_T_ACCOUNT_SEARCH);
// 更新数据
pageIndex = 1;
isFirstLoading = true;
onBackgrounds();
}
};
mBroadcastManager.registerReceiver(mReceiver, intentFilter);
}
示例13: onResume
import android.content.BroadcastReceiver; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
// registramos un broadcast receiver
tickReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0) {
tvHour.setText(getHour());
tvMinute.setText(getMinute());
}
}
};
registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
if (!set.isRunning()) {
set.start();
}
}
示例14: addStateListener
import android.content.BroadcastReceiver; //导入依赖的package包/类
private void addStateListener() {
if (this.stateReceiver == null) {
this.stateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
onBluetoothStateChange(intent);
}
};
}
try {
IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
webView.getContext().registerReceiver(this.stateReceiver, intentFilter);
} catch (Exception e) {
LOG.e(TAG, "Error registering state receiver: " + e.getMessage(), e);
}
}
示例15: observeChanges
import android.content.BroadcastReceiver; //导入依赖的package包/类
@Override
public Observable<Integer> observeChanges() {
return Observable.create(e -> {
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (nonNull(intent) && WHAT_ACCOUNT_CHANGE.equals(intent.getAction())) {
e.onNext(intent.getExtras().getInt(Extra.ACCOUNT_ID));
}
}
};
e.setCancellable(() -> LocalBroadcastManager.getInstance(app).unregisterReceiver(receiver));
if (!e.isDisposed()) {
LocalBroadcastManager.getInstance(app).registerReceiver(receiver, new IntentFilter(WHAT_ACCOUNT_CHANGE));
}
});
}