当前位置: 首页>>代码示例>>Java>>正文


Java BroadcastReceiver类代码示例

本文整理汇总了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"));
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:29,代码来源:PDevice.java

示例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);
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:21,代码来源:ApkReceiver.java

示例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();
            }
        }
    };
}
 
开发者ID:RollnCode,项目名称:BackTube,代码行数:26,代码来源:PlayerService.java

示例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();
                }
            }
        };
    }
 
开发者ID:dufangyu1990,项目名称:LeCatApp,代码行数:23,代码来源:LoginActivity.java

示例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();
        }
    };
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:RegisterActivity.java

示例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);
}
 
开发者ID:ceanyd,项目名称:react-native-caller-id-android,代码行数:18,代码来源:InCall.java

示例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);
    }

}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:29,代码来源:NetworkManager.java

示例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);
}
 
开发者ID:fekracomputers,项目名称:QuranAndroid,代码行数:26,代码来源:AudioManager.java

示例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);
}
 
开发者ID:jansipke,项目名称:pvdisplay,代码行数:20,代码来源:LiveFragment.java

示例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();
        }
    };
}
 
开发者ID:ubikgs,项目名称:AndroidSensors,代码行数:21,代码来源:WifiMeasurementsGatherer.java

示例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;
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:18,代码来源:MineFragment.java

示例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);

}
 
开发者ID:jpaijh,项目名称:TYT,代码行数:22,代码来源:T_MyFund_AccountFinancingFragment.java

示例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();
    }
}
 
开发者ID:gothalo,项目名称:Android-2017,代码行数:19,代码来源:TimerActivity.java

示例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);
    }
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:18,代码来源:BLECentralPlugin.java

示例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));
        }
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:19,代码来源:AccountsSettings.java


注:本文中的android.content.BroadcastReceiver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。