Java Code Examples for android.content.IntentFilter#addAction()

The following examples show how to use android.content.IntentFilter#addAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbsMusicServiceActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onServiceConnected() {
    if (!receiverRegistered) {
        musicStateReceiver = new MusicStateReceiver(this);

        final IntentFilter filter = new IntentFilter();
        filter.addAction(MusicService.PLAY_STATE_CHANGED);
        filter.addAction(MusicService.SHUFFLE_MODE_CHANGED);
        filter.addAction(MusicService.REPEAT_MODE_CHANGED);
        filter.addAction(MusicService.META_CHANGED);
        filter.addAction(MusicService.QUEUE_CHANGED);
        filter.addAction(MusicService.MEDIA_STORE_CHANGED);
        filter.addAction(MusicService.FAVORITE_STATE_CHANGED);

        registerReceiver(musicStateReceiver, filter);

        receiverRegistered = true;
    }

    for (MusicServiceEventListener listener : mMusicServiceEventListeners) {
        if (listener != null) {
            listener.onServiceConnected();
        }
    }
}
 
Example 2
Source File: UpdateController.java    From cube-sdk with Apache License 2.0 6 votes vote down vote up
public void beginDownLoad(String url, boolean forceReDownload) {

        String dir = DiskFileUtils.wantFilesPath(mContext, true);
        String fileName = url.substring(url.lastIndexOf("/") + 1);
        mApkPath = dir + File.separator + "downloads" + File.separator + fileName;

        mDownloadTask = new DownloadTask(this, url, mApkPath);
        notifyDownLoadStart();
        if (forceReDownload) {
            deleteApkFile();
        }

        IntentFilter filter = new IntentFilter();
        filter.addAction(mActionCancel);
        mContext.registerReceiver(new CancelBroadcastReceiver(), filter);

        Thread thread = new Thread(mDownloadTask);
        thread.setDaemon(true);
        thread.start();
    }
 
Example 3
Source File: MediaNotificationManager.java    From react-native-streaming-audio-player with MIT License 6 votes vote down vote up
/**
 * Posts the notification and starts tracking the session to keep it
 * updated. The notification will automatically be removed if the session is
 * destroyed before {@link #stopNotification} is called.
 */
public void startNotification() {
    if (!mStarted) {
        mMetadata = mController.getMetadata();
        mPlaybackState = mController.getPlaybackState();

        // The notification must be updated after setting started to true
        Notification notification = createNotification();
        if (notification != null) {
            mController.registerCallback(mCb);
            IntentFilter filter = new IntentFilter();
            filter.addAction(ACTION_NEXT);
            filter.addAction(ACTION_PAUSE);
            filter.addAction(ACTION_PLAY);
            filter.addAction(ACTION_PREV);
            mService.registerReceiver(this, filter);

            mService.startForeground(NOTIFICATION_ID, notification);
            mStarted = true;
        }
    }
}
 
Example 4
Source File: DefaultBandwidthMeter.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public static synchronized ConnectivityActionReceiver getInstance(Context context) {
  if (staticInstance == null) {
    staticInstance = new ConnectivityActionReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    context.registerReceiver(staticInstance, filter);
  }
  return staticInstance;
}
 
Example 5
Source File: NetStateUtil.java    From KSYMediaPlayer_Android with Apache License 2.0 5 votes vote down vote up
public static void  registerNetState(Context context, NetChangeListener netChangeListener) {
    if (netStateBroadcastReceiver == null) {
        netStateBroadcastReceiver = new NetStateBroadcastReceiver();
    }
    netStateBroadcastReceiver.addListener(netChangeListener);
    IntentFilter filter = new IntentFilter();
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    context.registerReceiver(netStateBroadcastReceiver, filter);
}
 
Example 6
Source File: MyRecruitActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_recruit_activity_layout);

    handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case OkhttpUtil.MESSAGE_MY_RECRUIT_LIST:
                    handleMyRecruitList(msg);
            }
        }
    };

    intentFilter = new IntentFilter();
    intentFilter.addAction("com.allever.social.updateMyRecruitList");
    updateMyRecruitListReceiver = new UpdateMyRecruitListReceiver();
    registerReceiver(updateMyRecruitListReceiver, intentFilter);

    ActionBar ab = this.getSupportActionBar();
    ab.setLogo(R.mipmap.ic_arrow_back_white_24dp);
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setTitle("我的招聘");

    listView = (ListView)this.findViewById(R.id.id_my_recruit_activity_listview);
    swipeRefreshLayout = (SwipeRefreshLayout)this.findViewById(R.id.id_my_recruit_activity_refresh);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimary,
            com.hyphenate.easeui.R.color.holo_orange_light, com.hyphenate.easeui.R.color.holo_red_light);

    btn_add_recruit = (AddFloatingActionButton)this.findViewById(R.id.id_my_recruit_activity_fab_add_recruit);
    btn_add_recruit.setOnClickListener(this);

    list_myRecruitItem = new ArrayList<>();

    getMyRecruit();


}
 
Example 7
Source File: MainActivity.java    From FileManager with Apache License 2.0 5 votes vote down vote up
@Override
public void initUiAndListener() {
    super.initUiAndListener();

    //扫描sd卡的广播
    mScannerReceiver = new ScannerReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    intentFilter.addDataScheme("file");
    registerReceiver(mScannerReceiver, intentFilter);

    //进入界面就开始扫描,进行数据更新,时间特别长,一分钟左右
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    intent.setData(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath())));
    sendBroadcast(intent);

    //监听应用卸载的广播
    mUninstallReceiver = new UnInstallReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    filter.addDataScheme("package");
    registerReceiver(mUninstallReceiver, filter);

    mPresenter = new MainPresenter(this);
    mPresenter.attachView(this);
}
 
Example 8
Source File: TimeIconData.java    From Status with Apache License 2.0 5 votes vote down vote up
@Override
public IntentFilter getIntentFilter() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_TIME_TICK);
    filter.addAction(Intent.ACTION_TIME_CHANGED);
    return filter;
}
 
Example 9
Source File: TimersFragment.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(LocalBroadcastConstants.INTENT_TIMER_CHANGED);
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(broadcastReceiver, intentFilter);
}
 
Example 10
Source File: DeviceControlActivity.java    From jessica with MIT License 5 votes vote down vote up
private static IntentFilter makeGattUpdateIntentFilter() {
    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothLeService.ACTION_GATT_CONNECTED);
    intentFilter.addAction(BluetoothLeService.ACTION_GATT_DISCONNECTED);
    intentFilter.addAction(BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED);
    intentFilter.addAction(BluetoothLeService.ACTION_DATA_AVAILABLE);
    return intentFilter;
}
 
Example 11
Source File: MainActivity.java    From lbry-android with MIT License 5 votes vote down vote up
private void registerServiceActionsReceiver() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_EVENT);
    intentFilter.addAction(LbrynetService.LBRY_SDK_SERVICE_STARTED);
    intentFilter.addAction(LbrynetService.ACTION_STOP_SERVICE);
    serviceActionsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (LbrynetService.ACTION_STOP_SERVICE.equals(action)) {
                MainActivity.this.receivedStopService = true;
                MainActivity.this.finish();
            } else if (LbrynetService.LBRY_SDK_SERVICE_STARTED.equals(action)) {
                // Rebuild the service notification
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Notification svcNotification = buildServiceNotification();
                        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                        notificationManager.notify(1, svcNotification);
                    }
                }, 1000);
            } else if (DownloadManager.ACTION_DOWNLOAD_EVENT.equalsIgnoreCase(action)) {
                String downloadAction = intent.getStringExtra("action");
                String uri = intent.getStringExtra("uri");
                String outpoint = intent.getStringExtra("outpoint");
                String fileInfoJson = intent.getStringExtra("file_info");
                double progress = intent.getDoubleExtra("progress", 0);
                if (uri == null || outpoint == null || (fileInfoJson == null && !"abort".equals(downloadAction))) {
                    return;
                }

                for (DownloadActionListener listener : downloadActionListeners) {
                    listener.onDownloadAction(downloadAction, uri, outpoint, fileInfoJson, progress);
                }
            }
        }
    };
    registerReceiver(serviceActionsReceiver, intentFilter);
}
 
Example 12
Source File: VolumeFragment.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    mStatusReceiver = new StatusReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intents.ACTION_STATUS);
    getActivity().registerReceiver(mStatusReceiver, filter);
}
 
Example 13
Source File: BluetoothTetheringTile.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void registerListeners() {
    if (!mIsListening) {
        registerServiceListener();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ACTION_TETHER_STATE_CHANGED);
        intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        mContext.registerReceiver(mBroadcastReceiver, intentFilter);
        mIsListening = true;
        if (DEBUG) log("listeners registered");
    }
}
 
Example 14
Source File: UsbSyncService.java    From UsbSerial with MIT License 5 votes vote down vote up
private void setFilter() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_USB_PERMISSION);
    filter.addAction(ACTION_USB_DETACHED);
    filter.addAction(ACTION_USB_ATTACHED);
    registerReceiver(usbReceiver, filter);
}
 
Example 15
Source File: SearchDeviceActivity.java    From Gizwits-SmartSocket_Android with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    loadingDialog.show();
    mCenter.cGetBoundDevices(setmanager.getUid(), setmanager.getToken());
    handler.sendEmptyMessageDelayed(handler_key.FOUND_FINISH.ordinal(),
            5000);
    IntentFilter filter = new IntentFilter();
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mChangeBroadcast, filter);
}
 
Example 16
Source File: ShadowsocksNotification.java    From Maying with Apache License 2.0 5 votes vote down vote up
private void registerLockReceiver(Service service, boolean visible) {
    IntentFilter screenFilter = new IntentFilter();
    screenFilter.addAction(Intent.ACTION_SCREEN_ON);
    screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
    if (visible && Utils.isLollipopOrAbove()) {
        screenFilter.addAction(Intent.ACTION_USER_PRESENT);
    }
    service.registerReceiver(lockReceiver, screenFilter);
}
 
Example 17
Source File: AndroidDeviceIMEIUtil.java    From CacheEmulatorChecker with Apache License 2.0 5 votes vote down vote up
public static void registerBatteryChangeListener(Context context) {

        if (sBatteryChangeReceiver == null) {
            sBatteryChangeReceiver = new BatteryChangeReceiver();
            IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_BATTERY_CHANGED);
            context.registerReceiver(sBatteryChangeReceiver, filter);
        }
    }
 
Example 18
Source File: NotificationGlobal.java    From Android-Notification with Apache License 2.0 5 votes vote down vote up
NotificationWindow(Context context) {
    super(context);

    mWindowManager = (WindowManager)
        mContext.getSystemService(Context.WINDOW_SERVICE);

    mRoot = new NotificationRootView(mContext);
    addView(mRoot);

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    context.registerReceiver(mReceiver, filter);
}
 
Example 19
Source File: UploadService.java    From rcloneExplorer with MIT License 4 votes vote down vote up
private void registerBroadcastReceivers() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    registerReceiver(connectivityChangeBroadcastReceiver, intentFilter);
}
 
Example 20
Source File: NotificationActionsReceiver.java    From react-native-background-upload with MIT License 3 votes vote down vote up
/**
 * Register this notifcation receiver.<br>
 * If you use this receiver in an {@link android.app.Activity}, you have to call this method inside
 * {@link android.app.Activity#onResume()}, after {@code super.onResume();}.<br>
 * If you use it in a {@link android.app.Service}, you have to
 * call this method inside {@link android.app.Service#onCreate()}, after {@code super.onCreate();}.
 *
 * @param context context in which to register this receiver
 */
public void register(final Context context) {
    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(NotificationActions.INTENT_ACTION);
    context.registerReceiver(this, intentFilter);

    this.reactContext = (ReactApplicationContext) context;
}