Java 类android.content.BroadcastReceiver 实例源码

项目:phonk    文件:PDevice.java   
/**
 * 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"));
}
项目:android-apkbox    文件:ApkReceiver.java   
/**
 * 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);
}
项目:BackTube    文件:PlayerService.java   
@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();
            }
        }
    };
}
项目:LeCatApp    文件:LoginActivity.java   
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();
                }
            }
        };
    }
项目:letv    文件:RegisterActivity.java   
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();
        }
    };
}
项目:react-native-caller-id-android    文件:InCall.java   
@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);
}
项目:localcloud_fe    文件:NetworkManager.java   
/**
 * 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);
    }

}
项目:QuranAndroid    文件:AudioManager.java   
/**
 * 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);
}
项目:pvdisplay    文件:LiveFragment.java   
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);
}
项目:AndroidSensors    文件:WifiMeasurementsGatherer.java   
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();
        }
    };
}
项目:sealtalk-android-master    文件:MineFragment.java   
@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;
}
项目:TYT    文件:T_MyFund_AccountFinancingFragment.java   
/**
 * 注册广播接收者
 */
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);

}
项目:Android-2017    文件:TimerActivity.java   
@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();
    }
}
项目:siiMobilityAppKit    文件:BLECentralPlugin.java   
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);
    }
}
项目:Phoenix-for-VK    文件:AccountsSettings.java   
@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));
        }
    });
}
项目:Sprog-App    文件:PoemsLoader.java   
public static void loadPoems(final Context context, final MainPresenter presenter) {
    File poems_file = new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
            "poems.json");
    File poems_old_file = new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
            "poems_old.json");
    if (poems_file.exists()) {
        poems_file.renameTo(poems_old_file);
    }

    String url = "https://almoturg.com/poems.json";
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setDescription("Sprog poems");
    request.setTitle("Sprog");
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);

    request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS,
            "poems.json");

    // get download service and enqueue file
    DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    receiver = new BroadcastReceiver() {
        public void onReceive(Context ctxt, Intent intent) {
            if (intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) != downloadID){return;}
            context.unregisterReceiver(PoemsLoader.receiver);
            PoemsLoader.receiver = null;
            presenter.downloadComplete();
        }
    };
    context.registerReceiver(receiver,
            new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    downloadID = manager.enqueue(request);
}
项目:siiMobilityAppKit    文件:NetworkManager.java   
/**
 * 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);
    }

}
项目:Tech-Jalsa    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);
    viewPager.setOffscreenPageLimit(ITEM_COUNT);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);

    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
                FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
            } else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) {
                // new push notification is received
            }
        }
    };
}
项目:localcloud_fe    文件:NetworkManager.java   
/**
 * 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);
    }

}
项目:rongyunDemo    文件:GroupListActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fr_group_list);
    setTitle(R.string.my_groups);
    mGroupListView = (ListView) findViewById(R.id.group_listview);
    mNoGroups = (TextView) findViewById(R.id.show_no_group);
    mSearch = (EditText) findViewById(R.id.group_search);
    mTextView = (TextView)findViewById(R.id.foot_group_size);
    initData();
    BroadcastManager.getInstance(mContext).addAction(SealConst.GROUP_LIST_UPDATE, new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            initData();
        }
    });
}
项目:container    文件:VClientImpl.java   
private void handleReceiver(ReceiverData data) {
    BroadcastReceiver.PendingResult result = data.resultData.build();
    try {
        Context context = createPackageContext(data.component.getPackageName());
        Context receiverContext = ContextImpl.getReceiverRestrictedContext.call(context);
        String className = data.component.getClassName();
        BroadcastReceiver receiver = (BroadcastReceiver) context.getClassLoader().loadClass(className).newInstance();
        mirror.android.content.BroadcastReceiver.setPendingResult.call(receiver, result);
        data.intent.setExtrasClassLoader(context.getClassLoader());
        receiver.onReceive(receiverContext, data.intent);
        if (mirror.android.content.BroadcastReceiver.getPendingResult.call(receiver) != null) {
            result.finish();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(
                "Unable to start receiver " + data.component
                        + ": " + e.toString(), e);
    }
    VActivityManager.get().broadcastFinish(data.resultData);
}
项目:springreplugin    文件:PluginMgr.java   
/**
 * @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);
}
项目:CXJPadProject    文件:KeyBoardPopWindow.java   
/** 注册广播接受来自keyboard的车牌号 */
    public void registerReceiver() {
//        输入车牌完成后的intent过滤器
        IntentFilter finishFilter = new IntentFilter(INPUT_LICENSE_COMPLETE);
        receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String license = intent.getStringExtra(INPUT_LICENSE_KEY);
                if (license != null && license.length() > 0) {
                    if (keyboardUtil != null) {
                        keyboardUtil.hideKeyboard();
                    }
                    KeyBoardPopWindow.this.dismiss();
                    mListener.setLicense(license);
                }
            }
        };
        mContext.registerReceiver(receiver, finishFilter);
    }
项目:Cable-Android    文件:RecipientPreferenceActivity.java   
private void initializeRecipients() {
  this.recipients = RecipientFactory.getRecipientsForIds(getActivity(),
                                                         getArguments().getLongArray(RECIPIENTS_EXTRA),
                                                         true);

  this.recipients.addListener(this);

  this.staleReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
      recipients.removeListener(RecipientPreferenceFragment.this);
      recipients = RecipientFactory.getRecipientsForIds(getActivity(), getArguments().getLongArray(RECIPIENTS_EXTRA), true);
      onModified(recipients);
    }
  };

  IntentFilter intentFilter = new IntentFilter();
  intentFilter.addAction(GroupDatabase.DATABASE_UPDATE_ACTION);
  intentFilter.addAction(RecipientFactory.RECIPIENT_CLEAR_ACTION);

  getActivity().registerReceiver(staleReceiver, intentFilter);
}
项目:Things-Audio-Renderer    文件:RxBroadcastReceiver.java   
public static Observable<Intent> fromBroadcast(final Context context, final IntentFilter filter) {
    return Observable.create(e -> {


        final BroadcastReceiver receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context1, Intent intent) {
                e.onNext(intent);
            }

        };
        context.registerReceiver(receiver, filter);
        e.setDisposable(new Disposable() {
            @Override
            public void dispose() {
                context.unregisterReceiver(receiver);
            }

            @Override
            public boolean isDisposed() {
                return false;
            }
        });
    });
}
项目:chromium-for-android-56-debug-video    文件:SupervisedUserContentProvider.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void createEnabledBroadcastReceiver() {
    IntentFilter restrictionsFilter = new IntentFilter(
            Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);
    BroadcastReceiver restrictionsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateEnabledState();
        }
    };
    getContext().registerReceiver(restrictionsReceiver, restrictionsFilter);
}
项目:letv    文件:LetvApplication.java   
public LetvApplication() {
    if (HotFix.PREVENT_VERIFY) {
        System.out.println(VerifyLoad.class);
    }
    this.mPluginInstallSuccessReceiver = new BroadcastReceiver(this) {
        final /* synthetic */ LetvApplication this$0;

        {
            if (HotFix.PREVENT_VERIFY) {
                System.out.println(VerifyLoad.class);
            }
            this.this$0 = this$0;
        }

        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            String data = intent.getDataString();
            LogInfo.log("plugin", "接收到插件安装成功消息... action = " + action);
            if (action.equals(ApkManager.ACTION_PACKAGE_ADDED) && data.substring(data.lastIndexOf("/") + 1).equals("com.letv.android.lite")) {
                this.this$0.mIsPluginInitedSuccess = true;
                if (this.this$0.mCallLiteIntent != null) {
                    if (LetvUtils.isTopRunning(this.this$0.getApplicationContext())) {
                        Toast.makeText(this.this$0.getApplicationContext(), 2131100676, 0).show();
                        LogInfo.log("plugin", "之前有影视大全的lite调起,现在自动补上...");
                        LeMessageManager.getInstance().dispatchMessage(BaseApplication.instance, new LeMessage(115, LetvApplication.getInstance().mCallLiteIntent));
                        JarLaunchUtils.launchLitePlayerDefault(this.this$0.getApplicationContext(), LetvApplication.getInstance().mCallLiteIntent);
                    } else {
                        Toast.makeText(this.this$0.getApplicationContext(), 2131101586, 0).show();
                    }
                }
                this.this$0.mCallLiteIntent = null;
            }
        }
    };
}
项目:GitHub    文件:BaseBroadcastReceiver.java   
/**注册广播接收器
 * @param context
 * @param receiver
 * @param filter
 * @return
 */
public static BroadcastReceiver register(Context context, @Nullable BroadcastReceiver receiver, IntentFilter filter) {
    Log.i(TAG, "register >>>");
    if (context == null || filter == null) {
        Log.e(TAG, "register  context == null || filter == null >> return;");
        return receiver;
    }

    context.registerReceiver(receiver, filter);

    return receiver;
}
项目:WifiUtils    文件:ConnectorUtils.java   
static void registerReceiver(@NonNull Context context, @Nullable BroadcastReceiver receiver, @NonNull IntentFilter filter) {
    if (receiver != null) {
        try {
            context.registerReceiver(receiver, filter);
        } catch (Exception e) {
        }
    }
}
项目:rongyunDemo    文件:BroadcastManager.java   
/**
 * 添加
 *
 * @param
 */
public void addAction(String action, BroadcastReceiver receiver) {
    try {
        IntentFilter filter = new IntentFilter();
        filter.addAction(action);
        mContext.registerReceiver(receiver, filter);
        receiverMap.put(action, receiver);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:springreplugin    文件:PluginLocalBroadcastManager.java   
/**
 * Unregister a previously registered BroadcastReceiver.  <em>All</em>
 * filters that have been registered for this BroadcastReceiver will be
 * removed.
 *
 * @param receiver The BroadcastReceiver to unregister.
 *
 * @see #registerReceiver
 */
public void unregisterReceiver(BroadcastReceiver receiver) {
    if (RePluginFramework.mHostInitialized) {
        try {
            ProxyLocalBroadcastManagerVar.unregisterReceiver.call(sOrigInstance, receiver);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return;
    }
    synchronized (mReceivers) {
        ArrayList<IntentFilter> filters = mReceivers.remove(receiver);
        if (filters == null) {
            return;
        }
        for (int i=0; i<filters.size(); i++) {
            IntentFilter filter = filters.get(i);
            for (int j=0; j<filter.countActions(); j++) {
                String action = filter.getAction(j);
                ArrayList<ReceiverRecord> receivers = mActions.get(action);
                if (receivers != null) {
                    for (int k=0; k<receivers.size(); k++) {
                        if (receivers.get(k).receiver == receiver) {
                            receivers.remove(k);
                            k--;
                        }
                    }
                    if (receivers.size() <= 0) {
                        mActions.remove(action);
                    }
                }
            }
        }
    }
}
项目:springreplugin    文件:PluginLocalBroadcastManager.java   
/**
 * Register a receive for any local broadcasts that match the given IntentFilter.
 *
 * @param receiver The BroadcastReceiver to handle the broadcast.
 * @param filter Selects the Intent broadcasts to be received.
 *
 * @see #unregisterReceiver
 */
public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
    if (RePluginFramework.mHostInitialized) {
        try {
            ProxyLocalBroadcastManagerVar.registerReceiver.call(sOrigInstance, receiver, filter);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return;
    }
    synchronized (mReceivers) {
        ReceiverRecord entry = new ReceiverRecord(filter, receiver);
        ArrayList<IntentFilter> filters = mReceivers.get(receiver);
        if (filters == null) {
            filters = new ArrayList<IntentFilter>(1);
            mReceivers.put(receiver, filters);
        }
        filters.add(filter);
        for (int i=0; i<filter.countActions(); i++) {
            String action = filter.getAction(i);
            ArrayList<ReceiverRecord> entries = mActions.get(action);
            if (entries == null) {
                entries = new ArrayList<ReceiverRecord>(1);
                mActions.put(action, entries);
            }
            entries.add(entry);
        }
    }
}
项目:android-PictureInPicture    文件:MainActivity.java   
@Override
public void onPictureInPictureModeChanged(
        boolean isInPictureInPictureMode, Configuration configuration) {
    super.onPictureInPictureModeChanged(isInPictureInPictureMode, configuration);
    if (isInPictureInPictureMode) {
        // Starts receiving events from action items in PiP mode.
        mReceiver =
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        if (intent == null
                                || !ACTION_MEDIA_CONTROL.equals(intent.getAction())) {
                            return;
                        }

                        // This is where we are called back from Picture-in-Picture action
                        // items.
                        final int controlType = intent.getIntExtra(EXTRA_CONTROL_TYPE, 0);
                        switch (controlType) {
                            case CONTROL_TYPE_PLAY:
                                mMovieView.play();
                                break;
                            case CONTROL_TYPE_PAUSE:
                                mMovieView.pause();
                                break;
                        }
                    }
                };
        registerReceiver(mReceiver, new IntentFilter(ACTION_MEDIA_CONTROL));
    } else {
        // We are out of PiP mode. We can stop receiving events from it.
        unregisterReceiver(mReceiver);
        mReceiver = null;
        // Show the video controls if the video is not playing
        if (mMovieView != null && !mMovieView.isPlaying()) {
            mMovieView.showControls();
        }
    }
}
项目:MakiLite    文件:PinFragmentActivity.java   
public PinFragmentActivity() {
    super();
    mPinCancelledReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };
}
项目:MakiLite    文件:PinActivity.java   
public PinActivity() {
    super();
    mPinCancelledReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };
}
项目:MakiLite    文件:PinCompatActivity.java   
public PinCompatActivity() {
    super();
    mPinCancelledReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };
}
项目:LucaHome-AndroidApplication    文件:ReceiverController.java   
public void RegisterReceiver(
        @NonNull BroadcastReceiver receiver,
        @NonNull String[] actions) {
    IntentFilter downloadStateFilter = new IntentFilter();
    for (String action : actions) {
        downloadStateFilter.addAction(action);
    }

    UnregisterReceiver(receiver);

    _context.registerReceiver(receiver, downloadStateFilter);
    _registeredReceiver.add(receiver);
}
项目:bridgefy-android-samples    文件:ChatActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    ButterKnife.bind(this);

    // recover our Peer object
    conversationName = getIntent().getStringExtra(INTENT_EXTRA_NAME);
    conversationId   = getIntent().getStringExtra(INTENT_EXTRA_UUID);

    // Configure the Toolbar
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Enable the Up button
    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setTitle(conversationName);
        ab.setDisplayHomeAsUpEnabled(true);
    }

    // register the receiver to listen for incoming messages
    LocalBroadcastManager.getInstance(getBaseContext())
            .registerReceiver(new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    Message message = new Message(intent.getStringExtra(MainActivity.INTENT_EXTRA_MSG));
                    message.setDeviceName(intent.getStringExtra(MainActivity.INTENT_EXTRA_NAME));
                    message.setDirection(Message.INCOMING_MESSAGE);
                    messagesAdapter.addMessage(message);
                }
            }, new IntentFilter(conversationId));

    // configure the recyclerview
    RecyclerView messagesRecyclerView = findViewById(R.id.message_list);
    LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this);
    mLinearLayoutManager.setReverseLayout(true);
    messagesRecyclerView.setLayoutManager(mLinearLayoutManager);
    messagesRecyclerView.setAdapter(messagesAdapter);
}
项目:LQRWeChat-master    文件:RecentMessageFragment.java   
private void registerBR() {
    BroadcastManager.getInstance(getActivity()).register(AppConst.UPDATE_CONVERSATIONS, new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mPresenter.getConversations();
            isFirst = false;
        }
    });
}
项目:PrivacyStreams    文件:AlarmScheduler.java   
public AlarmScheduler(Context ctx, String actionToken) {
    this.ctx = ctx;
    am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    mAlarmIntent = PendingIntent.getBroadcast(ctx, 0, new Intent(actionToken), 0);
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            run();
        }
    };
    ctx.registerReceiver(mReceiver, new IntentFilter(actionToken));
}