Java Code Examples for android.content.BroadcastReceiver

The following are top voted examples for showing how to use android.content.BroadcastReceiver. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: phonk   File: PDevice.java   Source Code and License 6 votes vote down vote up
/**
 * 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"));
}
 
Example 2
Project: android-apkbox   File: ApkReceiver.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Project: BackTube   File: PlayerService.java   Source Code and License 6 votes vote down vote up
@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();
            }
        }
    };
}
 
Example 4
Project: LeCatApp   File: LoginActivity.java   Source Code and License 6 votes vote down vote up
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();
                }
            }
        };
    }
 
Example 5
Project: letv   File: RegisterActivity.java   Source Code and License 6 votes vote down vote up
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();
        }
    };
}
 
Example 6
Project: react-native-caller-id-android   File: InCall.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 7
Project: localcloud_fe   File: NetworkManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
    }

}
 
Example 8
Project: QuranAndroid   File: AudioManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 9
Project: pvdisplay   File: LiveFragment.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 10
Project: AndroidSensors   File: WifiMeasurementsGatherer.java   Source Code and License 6 votes vote down vote up
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();
        }
    };
}
 
Example 11
Project: sealtalk-android-master   File: MineFragment.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 12
Project: TYT   File: T_MyFund_AccountFinancingFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 注册广播接收者
 */
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);

}
 
Example 13
Project: Android-2017   File: TimerActivity.java   Source Code and License 6 votes vote down vote up
@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();
    }
}
 
Example 14
Project: siiMobilityAppKit   File: BLECentralPlugin.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 15
Project: Phoenix-for-VK   File: AccountsSettings.java   Source Code and License 6 votes vote down vote up
@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));
        }
    });
}
 
Example 16
Project: Sprog-App   File: PoemsLoader.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 17
Project: siiMobilityAppKit   File: NetworkManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
    }

}
 
Example 18
Project: Tech-Jalsa   File: MainActivity.java   Source Code and License 6 votes vote down vote up
@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
            }
        }
    };
}
 
Example 19
Project: localcloud_fe   File: NetworkManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
    }

}
 
Example 20
Project: rongyunDemo   File: GroupListActivity.java   Source Code and License 6 votes vote down vote up
@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();
        }
    });
}
 
Example 21
Project: container   File: VClientImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 22
Project: springreplugin   File: PluginMgr.java   Source Code and License 6 votes vote down vote up
/**
 * @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);
}
 
Example 23
Project: CXJPadProject   File: KeyBoardPopWindow.java   Source Code and License 6 votes vote down vote up
/** 注册广播接受来自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);
    }
 
Example 24
Project: Cable-Android   File: RecipientPreferenceActivity.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 25
Project: Things-Audio-Renderer   File: RxBroadcastReceiver.java   Source Code and License 6 votes vote down vote up
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;
            }
        });
    });
}
 
Example 26
Project: chromium-for-android-56-debug-video   File: SupervisedUserContentProvider.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 27
Project: letv   File: LetvApplication.java   Source Code and License 5 votes vote down vote up
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;
            }
        }
    };
}
 
Example 28
Project: GitHub   File: BaseBroadcastReceiver.java   Source Code and License 5 votes vote down vote up
/**注册广播接收器
 * @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;
}
 
Example 29
Project: WifiUtils   File: ConnectorUtils.java   Source Code and License 5 votes vote down vote up
static void registerReceiver(@NonNull Context context, @Nullable BroadcastReceiver receiver, @NonNull IntentFilter filter) {
    if (receiver != null) {
        try {
            context.registerReceiver(receiver, filter);
        } catch (Exception e) {
        }
    }
}
 
Example 30
Project: rongyunDemo   File: BroadcastManager.java   Source Code and License 5 votes vote down vote up
/**
 * 添加
 *
 * @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();
    }
}
 
Example 31
Project: springreplugin   File: PluginLocalBroadcastManager.java   Source Code and License 5 votes vote down vote up
/**
 * 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);
                    }
                }
            }
        }
    }
}
 
Example 32
Project: springreplugin   File: PluginLocalBroadcastManager.java   Source Code and License 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 33
Project: android-PictureInPicture   File: MainActivity.java   Source Code and License 5 votes vote down vote up
@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();
        }
    }
}
 
Example 34
Project: MakiLite   File: PinFragmentActivity.java   Source Code and License 5 votes vote down vote up
public PinFragmentActivity() {
    super();
    mPinCancelledReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };
}
 
Example 35
Project: MakiLite   File: PinActivity.java   Source Code and License 5 votes vote down vote up
public PinActivity() {
    super();
    mPinCancelledReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };
}
 
Example 36
Project: MakiLite   File: PinCompatActivity.java   Source Code and License 5 votes vote down vote up
public PinCompatActivity() {
    super();
    mPinCancelledReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };
}
 
Example 37
Project: LucaHome-AndroidApplication   File: ReceiverController.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 38
Project: bridgefy-android-samples   File: ChatActivity.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 39
Project: LQRWeChat-master   File: RecentMessageFragment.java   Source Code and License 5 votes vote down vote up
private void registerBR() {
    BroadcastManager.getInstance(getActivity()).register(AppConst.UPDATE_CONVERSATIONS, new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mPresenter.getConversations();
            isFirst = false;
        }
    });
}
 
Example 40
Project: PrivacyStreams   File: AlarmScheduler.java   Source Code and License 5 votes vote down vote up
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));
}