Java Code Examples for android.content.IntentFilter
The following examples show how to use
android.content.IntentFilter.
These examples are extracted from open source projects.
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 Project: Shelter Author: PeterCxy File: FreezeService.java License: Do What The F*ck You Want To Public License | 6 votes |
@Override public void onReceive(Context context, Intent intent) { // Save usage statistics right now! // We need to use the statics at this moment // for "skipping foreground apps" // No app is foreground after the screen is locked. mScreenLockTime = new Date().getTime(); if (SettingsManager.getInstance().getSkipForegroundEnabled() && Utility.checkUsageStatsPermission(FreezeService.this)) { UsageStatsManager usm = getSystemService(UsageStatsManager.class); mUsageStats = usm.queryAndAggregateUsageStats(mScreenLockTime - APP_INACTIVE_TIMEOUT, mScreenLockTime); } // Delay the work so that it can be canceled if the screen // gets unlocked before the delay passes mHandler.postDelayed(mFreezeWork, ((long) SettingsManager.getInstance().getAutoFreezeDelay()) * 1000); registerReceiver(mUnlockReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); }
Example #2
Source Project: Cirrus_depricated Author: skymania File: FolderPickerActivity.java License: GNU General Public License v2.0 | 6 votes |
@Override protected void onResume() { super.onResume(); Log_OC.e(TAG, "onResume() start"); // refresh list of files refreshListOfFilesFragment(); // Listen for sync messages IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START); syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END); syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED); syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED); mSyncBroadcastReceiver = new SyncBroadcastReceiver(); registerReceiver(mSyncBroadcastReceiver, syncIntentFilter); Log_OC.d(TAG, "onResume() end"); }
Example #3
Source Project: PresencePublisher Author: ostrya File: BatteryMessageProvider.java License: MIT License | 6 votes |
@Override protected List<String> getMessageContents() { if (!getSharedPreferences().getBoolean(SEND_BATTERY_MESSAGE, false)) { HyperLog.d(TAG, "Battery messages disabled, not generating any messages"); return Collections.emptyList(); } HyperLog.i(TAG, "Scheduling battery message"); IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = getApplicationContext().registerReceiver(null, filter); if (batteryStatus == null) { HyperLog.w(TAG, "No battery status received, unable to generate message"); return Collections.emptyList(); } int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); int batteryPct = (int) (level / (0.01f * scale)); return Collections.singletonList(Integer.toString(batteryPct)); }
Example #4
Source Project: zen4android Author: nihaoyalong File: ZenNotificationActivity.java License: MIT License | 6 votes |
@Override protected void onResume() { super.onResume(); try { IntentFilter filter = new IntentFilter(); filter.addAction(ZenNotificationModel.ZEN_NEW_NOTIFICATION); filter.addAction(ZenNotificationModel.ZEN_NOTIFICATION_EMPTY); filter.addAction(ZenNotificationModel.ZEN_LOAD_NOTIFICATION_FAILED); registerReceiver(mBroadcastReceiver, filter); if (ZenUtils.getToken() != null) { // loged in mLoadingView.show(); model.load(); } refresh(); } catch (Exception e) { e.printStackTrace(); } }
Example #5
Source Project: platform-friends-android Author: telerik File: UiLifecycleHelper.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** * To be called from an Activity or Fragment's onResume method. */ public void onResume() { Session session = Session.getActiveSession(); if (session != null) { if (callback != null) { session.addCallback(callback); } if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState())) { session.openForRead(null); } } // add the broadcast receiver IntentFilter filter = new IntentFilter(); filter.addAction(Session.ACTION_ACTIVE_SESSION_SET); filter.addAction(Session.ACTION_ACTIVE_SESSION_UNSET); // Add a broadcast receiver to listen to when the active Session // is set or unset, and add/remove our callback as appropriate broadcastManager.registerReceiver(receiver, filter); }
Example #6
Source Project: custom-tabs-client Author: GoogleChrome File: CustomTabsHelper.java License: Apache License 2.0 | 6 votes |
/** * Used to check whether there is a specialized handler for a given intent. * @param intent The intent to check with. * @return Whether there is a specialized handler for the given intent. */ private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) { try { PackageManager pm = context.getPackageManager(); List<ResolveInfo> handlers = pm.queryIntentActivities( intent, PackageManager.GET_RESOLVED_FILTER); if (handlers == null || handlers.size() == 0) { return false; } for (ResolveInfo resolveInfo : handlers) { IntentFilter filter = resolveInfo.filter; if (filter == null) continue; if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue; if (resolveInfo.activityInfo == null) continue; return true; } } catch (RuntimeException e) { Log.e(TAG, "Runtime exception while getting specialized handlers"); } return false; }
Example #7
Source Project: android-browser-helper Author: GoogleChrome File: CustomTabsHelper.java License: Apache License 2.0 | 6 votes |
/** * Used to check whether there is a specialized handler for a given intent. * @param intent The intent to check with. * @return Whether there is a specialized handler for the given intent. */ private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) { try { PackageManager pm = context.getPackageManager(); List<ResolveInfo> handlers = pm.queryIntentActivities( intent, PackageManager.GET_RESOLVED_FILTER); if (handlers.size() == 0) { return false; } for (ResolveInfo resolveInfo : handlers) { IntentFilter filter = resolveInfo.filter; if (filter == null) continue; if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue; if (resolveInfo.activityInfo == null) continue; return true; } } catch (RuntimeException e) { Log.e(TAG, "Runtime exception while getting specialized handlers"); } return false; }
Example #8
Source Project: LNMOnlineAndroidSample Author: safaricom File: NotificationActivity.java License: Apache License 2.0 | 6 votes |
@Override protected void onResume() { super.onResume(); // register GCM registration complete receiver. LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver, new IntentFilter(REGISTRATION_COMPLETE)); // register new push message receiver. // by doing this, the activity will be notified each time a new message arrives LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver, new IntentFilter(PUSH_NOTIFICATION)); // clear the notification area when the app is opened. NotificationUtils.clearNotifications(getApplicationContext()); }
Example #9
Source Project: iBeebo Author: andforce File: MentionsCommentTimeLineFragment.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onResume() { super.onResume(); setListViewPositionFromPositionsCache(); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(newBroadcastReceiver, new IntentFilter(AppEventAction.NEW_MSG_BROADCAST)); // setActionBarTabCount(newMsgTipBar.getValues().size()); getNewMsgTipBar().setOnChangeListener(new TopTipsView.OnChangeListener() { @Override public void onChange(int count) { // ((MainTimeLineActivity) getActivity()).setMentionsCommentCount(count); // setActionBarTabCount(count); } }); checkUnreadInfo(); }
Example #10
Source Project: AppTroy Author: CvvT File: ActivityHook.java License: Apache License 2.0 | 6 votes |
@Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { Log.d("cc", "before, register receiver"); if (NEED_DEBUG) { Activity activity = (Activity) param.thisObject; Log.d(LOG_TAG, activity.toString()); } if (!ModuleContext.HAS_REGISTER_LISENER) { Activity app = (Activity) param.thisObject; IntentFilter filter = new IntentFilter(CommandBroadcastReceiver.INTENT_ACTION); app.registerReceiver(new CommandBroadcastReceiver(), filter); ModuleContext.HAS_REGISTER_LISENER = true; ModuleContext.getInstance().setFirstApplication(app.getApplication()); Log.d("cc", "register over"); } }
Example #11
Source Project: Trigger Author: airk000 File: TriggerLoop.java License: Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); jobSet = new ConcurrentHashMap<>(); receivers = new ConcurrentHashMap<>(); jobHappens = new ConcurrentHashMap<>(); binder = new TriggerBinder(); executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE, new TriggerWorkerFactory()); mainHandler = new Handler(Looper.getMainLooper()); alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); shortDeadlineHandler = new Handler(); deadlineCheck = new DeadlineCheck(); sDeviceStatus = DeviceStatus.get(this); registerReceiver(deadlineCheck, new IntentFilter(DEADLINE_BROADCAST)); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); int granted = checkCallingOrSelfPermission("android.permission.WAKE_LOCK"); if (granted == PackageManager.PERMISSION_GRANTED) { wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); } else { wakeLock = null; } handlerThread = new HandlerThread("Trigger-HandlerThread"); handlerThread.start(); checker = new CheckHandler(handlerThread.getLooper()); mayRecoverJobsFromFile(); }
Example #12
Source Project: TwistyTimer Author: aricneto File: TTIntent.java License: GNU General Public License v3.0 | 6 votes |
/** * Registers a broadcast receiver. The receiver will only be notified of intents that require * the category given and only for the actions that are supported for that category. If the * receiver is used by a fragment, create an instance of {@link TTFragmentBroadcastReceiver} * and register it with the {@link #registerReceiver(TTFragmentBroadcastReceiver)} method * instead, as it will be easier to maintain. * * @param receiver * The broadcast receiver to be registered. * @param category * The category for the actions to be received. Must not be {@code null} and must be a * supported category. * * @throws IllegalArgumentException * If the category is {@code null}, or is not one of the supported categories. */ public static void registerReceiver(BroadcastReceiver receiver, String category) { final String[] actions = ACTIONS_SUPPORTED_BY_CATEGORY.get(category); if (category == null || actions.length == 0) { throw new IllegalArgumentException("Category is not supported: " + category); } final IntentFilter filter = new IntentFilter(); filter.addCategory(category); for (String action : actions) { // IntentFilter will only match Intents with one of these actions. filter.addAction(action); } LocalBroadcastManager.getInstance(TwistyTimer.getAppContext()) .registerReceiver(receiver, filter); }
Example #13
Source Project: habpanelviewer Author: vbier File: ServerConnection.java License: GNU General Public License v3.0 | 6 votes |
public ServerConnection(Context context) { mCertListener = () -> { Log.d(TAG, "cert added, reconnecting to server..."); if (mSseConnection.getStatus() == SseConnection.Status.CERTIFICATE_ERROR) { mSseConnection.connect(); } }; mSseConnection.addListener(new SseConnectionListener()); mSseConnection.addItemValueListener(new SseStateUpdateListener()); CertificateManager.getInstance().addCertListener(mCertListener); CredentialManager.getInstance().addCredentialsListener(mSseConnection); IntentFilter f = new IntentFilter(); f.addAction(Constants.INTENT_ACTION_SET_WITH_TIMEOUT); LocalBroadcastManager.getInstance(context).registerReceiver(mReceiver, f); }
Example #14
Source Project: container Author: codehz File: IntentResolver.java License: GNU General Public License v3.0 | 6 votes |
private ArrayList<F> collectFilters(F[] array, IntentFilter matching) { ArrayList<F> res = null; if (array != null) { for (int i = 0; i < array.length; i++) { F cur = array[i]; if (cur == null) { break; } if (filterEquals(cur, matching)) { if (res == null) { res = new ArrayList<>(); } res.add(cur); } } } return res; }
Example #15
Source Project: slide-android Author: lkuich File: SystemSettings.java License: GNU General Public License v2.0 | 5 votes |
public boolean isUsbConnected(final Activity a) { final Intent intent = a.registerReceiver( null, new IntentFilter( "android.hardware.usb.action.USB_STATE") ); return intent != null && intent.getExtras().getBoolean("connected"); }
Example #16
Source Project: oversec Author: oversecio File: App.java License: GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { int pid = Process.myPid(); ActivityManager manager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); String currentProcName = null; for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) { if (processInfo.pid == pid) { currentProcName = processInfo.processName; break; } } if (currentProcName.endsWith("zxcvbn")) { super.onCreate(); return; } CrashHandler.init(this); LoggingConfig.INSTANCE.init(BuildConfig.DEBUG); super.onCreate(); if (IabUtil.isGooglePlayInstalled(this)) { RateThisApp.Config config = new RateThisApp.Config(7, 30); RateThisApp.init(config); } //need to register from code, registering from manifest is ignored IntentFilter packageChangeFilter = new IntentFilter(); packageChangeFilter.addAction("android.intent.action.PACKAGE_ADDED"); packageChangeFilter.addAction("android.intent.action.PACKAGE_REMOVED"); packageChangeFilter.addAction("android.intent.action.PACKAGE_CHANGED"); packageChangeFilter.addDataScheme("package"); registerReceiver(new AppsReceiver(), packageChangeFilter); IabUtil.getInstance(this); Core.getInstance(this); }
Example #17
Source Project: a Author: 804463258 File: ReadAloudService.java License: GNU General Public License v3.0 | 5 votes |
private void initBroadcastReceiver() { broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) { pauseReadAloud(true); } } }; IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY); registerReceiver(broadcastReceiver, intentFilter); }
Example #18
Source Project: Bolts-Android Author: BoltsFramework File: AppLinkTest.java License: MIT License | 5 votes |
public void testGeneralMeasurementEventsBroadcast() throws Exception { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); i.putExtra("foo", "bar"); ArrayList<String> arr = new ArrayList<>(); arr.add("foo2"); arr.add("bar2"); i.putExtra("foobar", arr); Map<String, String> other = new HashMap<>(); other.put("yetAnotherFoo", "yetAnotherBar"); final CountDownLatch lock = new CountDownLatch(1); final String[] receivedStrings = new String[5]; LocalBroadcastManager manager = LocalBroadcastManager.getInstance(instrumentation.getTargetContext()); manager.registerReceiver( new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String eventName = intent.getStringExtra("event_name"); Bundle eventArgs = intent.getBundleExtra("event_args"); receivedStrings[0] = eventName; receivedStrings[1] = eventArgs.getString("foo"); receivedStrings[2] = eventArgs.getString("foobar"); receivedStrings[3] = eventArgs.getString("yetAnotherFoo"); receivedStrings[4] = eventArgs.getString("intentData"); lock.countDown(); } }, new IntentFilter("com.parse.bolts.measurement_event") ); MeasurementEvent.sendBroadcastEvent(instrumentation.getTargetContext(), "myEventName", i, other); lock.await(20000, TimeUnit.MILLISECONDS); assertEquals("myEventName", receivedStrings[0]); assertEquals("bar", receivedStrings[1]); assertEquals((new JSONArray(arr)).toString(), receivedStrings[2]); assertEquals("yetAnotherBar", receivedStrings[3]); assertEquals("http://www.example.com", receivedStrings[4]); }
Example #19
Source Project: Gizwits-SmartBuld_Android Author: gizwits File: InactivityTimer.java License: MIT License | 5 votes |
public synchronized void onResume() { if (registered) { Log.w(TAG, "PowerStatusReceiver was already registered?"); } else { activity.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); registered = true; } onActivity(); }
Example #20
Source Project: wearable Author: JimSeker File: BatmanWatchFaceService.java License: Apache License 2.0 | 5 votes |
private void registerReceiver() { if (mRegisteredTimeZoneReceiver) { return; } mRegisteredTimeZoneReceiver = true; IntentFilter filter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED); BatmanWatchFaceService.this.registerReceiver(mTimeZoneReceiver, filter); }
Example #21
Source Project: Camera-Roll-Android-App Author: kollerlukas File: AlbumActivity.java License: Apache License 2.0 | 5 votes |
@Override public IntentFilter getBroadcastIntentFilter() { IntentFilter filter = FileOperation.Util.getIntentFilter(super.getBroadcastIntentFilter()); filter.addAction(ALBUM_ITEM_REMOVED); filter.addAction(ALBUM_ITEM_RENAMED); filter.addAction(DATA_CHANGED); return filter; }
Example #22
Source Project: bither-android Author: bither File: BlockchainService.java License: Apache License 2.0 | 5 votes |
private synchronized void startPeer() { try { if (peerCanNotRun) { return; } if (UpgradeUtil.needUpgrade()) { return; } if (!AppSharedPreference.getInstance().getDownloadSpvFinish()) { Block block = BlockUtil.dowloadSpvBlock(); if (block == null) { return; } } if (AppSharedPreference.getInstance().getAppMode() != BitherjSettings.AppMode.COLD) { if (!AppSharedPreference.getInstance().getBitherjDoneSyncFromSpv()) { if (!PeerManager.instance().isConnected()) { PeerManager.instance().start(); if (!spvFinishedReceivered) { final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(NotificationAndroidImpl.ACTION_SYNC_FROM_SPV_FINISHED); spvFinishedReceiver = new SPVFinishedReceiver(); registerReceiver(spvFinishedReceiver, intentFilter); spvFinishedReceivered = true; } } } else { if (!AddressManager.getInstance().addressIsSyncComplete()) { TransactionsUtil.getMyTxFromBither(); } startPeerManager(); } } } catch (Exception e) { e.printStackTrace(); } }
Example #23
Source Project: NightWatch Author: StephenBlackWasAlreadyTaken File: ShareGlucose.java License: GNU General Public License v3.0 | 5 votes |
public int getBatteryLevel() { Intent batteryIntent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); if(level == -1 || scale == -1) { return 50; } return (int)(((float)level / (float)scale) * 100.0f); }
Example #24
Source Project: xDrip Author: NightscoutFoundation File: PowerStateReceiver.java License: GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("ConstantConditions") public static int getBatteryLevel(Context context) { final Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); try { int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); if (level == -1 || scale == -1) { return 50; } return (int) (((float) level / (float) scale) * 100.0f); } catch (NullPointerException e) { return 50; } }
Example #25
Source Project: YCVideoPlayer Author: yangchong211 File: FloatLifecycle.java License: Apache License 2.0 | 5 votes |
FloatLifecycle(Context applicationContext, boolean showFlag, Class[] activities, LifecycleListener lifecycleListener) { this.showFlag = showFlag; this.activities = activities; mLifecycleListener = lifecycleListener; mHandler = new Handler(); ((Application) applicationContext).registerActivityLifecycleCallbacks(this); applicationContext.registerReceiver(this, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); }
Example #26
Source Project: android-openslmediaplayer Author: h6ah4i File: AppEventBus.java License: Apache License 2.0 | 5 votes |
private static IntentFilter createIntentFilter(Receiver<?> receiver) { int[] categories = receiver.getCategoryFilter(); IntentFilter filter = new IntentFilter(); if (categories != null) { for (int category : categories) { filter.addAction(categoryToActionName(category)); } } return filter; }
Example #27
Source Project: PrivacyStreams Author: PrivacyStreams File: BluetoothDeviceListProvider.java License: Apache License 2.0 | 5 votes |
@Override protected void provide() { BluetoothAdapter BTAdapter = BluetoothAdapter.getDefaultAdapter(); // Set up the adaptor if (BTAdapter == null || !BTAdapter.isEnabled()) { this.finish(); return; } IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(android.bluetooth.BluetoothDevice.ACTION_FOUND); intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED); intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); getContext().registerReceiver(mReceiver, intentFilter); BTAdapter.startDiscovery(); }
Example #28
Source Project: Taskbar Author: farmerbb File: StartMenuLayoutTest.java License: Apache License 2.0 | 5 votes |
@Test public void testDispatchKeyEvent() { IntentFilter filter = new IntentFilter(ACTION_HIDE_START_MENU); TestBroadcastReceiver receiver = new TestBroadcastReceiver(); LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter); KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); layout.dispatchKeyEvent(keyEvent); assertFalse(receiver.onReceived); layout.viewHandlesBackButton(); layout.dispatchKeyEvent(keyEvent); assertTrue(receiver.onReceived); }
Example #29
Source Project: Meshenger Author: dakhnod File: ContactListActivity.java License: GNU General Public License v3.0 | 5 votes |
@Override protected void onResume() { super.onResume(); LocalBroadcastManager.getInstance(this).registerReceiver(refreshReceiver, new IntentFilter("contact_refresh")); bindService(new Intent(this, MainService.class), this, Service.BIND_AUTO_CREATE); }
Example #30
Source Project: android_9.0.0_r45 Author: lulululbj File: Watchdog.java License: Apache License 2.0 | 5 votes |
public void init(Context context, ActivityManagerService activity) { mResolver = context.getContentResolver(); mActivity = activity; context.registerReceiver(new RebootRequestReceiver(), new IntentFilter(Intent.ACTION_REBOOT), android.Manifest.permission.REBOOT, null); }