List of usage examples for android.content IntentFilter addAction
public final void addAction(String action)
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int userId = Util.getUserId(Process.myUid()); // Check privacy service client if (!PrivacyService.checkClient()) return;/*from ww w. j av a2 s . com*/ // Import license file if (Intent.ACTION_VIEW.equals(getIntent().getAction())) if (Util.importProLicense(new File(getIntent().getData().getPath())) != null) Toast.makeText(this, getString(R.string.menu_pro), Toast.LENGTH_LONG).show(); // Set layout setContentView(R.layout.mainlist); setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar)); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); // Set sub title if (Util.hasProLicense(this) != null) getSupportActionBar().setSubtitle(R.string.menu_pro); // Annotate Meta.annotate(this.getResources()); // Get localized restriction name List<String> listRestrictionName = new ArrayList<String>( PrivacyManager.getRestrictions(this).navigableKeySet()); listRestrictionName.add(0, getString(R.string.menu_all)); // Build spinner adapter SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item); spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spAdapter.addAll(listRestrictionName); // Handle info ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo); imgInfo.setOnClickListener(new View.OnClickListener() { @SuppressLint("SetJavaScriptEnabled") @Override public void onClick(View view) { int position = spRestriction.getSelectedItemPosition(); if (position != AdapterView.INVALID_POSITION) { String query = (position == 0 ? "restrictions" : (String) PrivacyManager.getRestrictions(ActivityMain.this).values().toArray()[position - 1]); WebView webview = new WebView(ActivityMain.this); webview.getSettings().setUserAgentString("Mozilla/5.0"); // needed for hashtag webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("https://github.com/M66B/XPrivacy#" + query); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this); alertDialogBuilder.setTitle((String) spRestriction.getSelectedItem()); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setView(webview); alertDialogBuilder.setCancelable(true); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }); // Setup category spinner spRestriction = (Spinner) findViewById(R.id.spRestriction); spRestriction.setAdapter(spAdapter); spRestriction.setOnItemSelectedListener(this); int pos = getSelectedCategory(userId); spRestriction.setSelection(pos); // Setup sort mSortMode = Integer.parseInt(PrivacyManager.getSetting(userId, PrivacyManager.cSettingSortMode, "0")); mSortInvert = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingSortInverted, false); // Start task to get app list AppListTask appListTask = new AppListTask(); appListTask.executeOnExecutor(mExecutor, (Object) null); // Check environment Requirements.check(this); // Licensing checkLicense(); // Listen for package add/remove IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_PACKAGE_ADDED); iff.addAction(Intent.ACTION_PACKAGE_REMOVED); iff.addDataScheme("package"); registerReceiver(mPackageChangeReceiver, iff); mPackageChangeReceiverRegistered = true; boolean showChangelog = true; // First run if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true)) { showChangelog = false; optionAbout(); } // Tutorial if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialMain, false)) { showChangelog = false; ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ViewParent parent = view.getParent(); while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent(); ((View) parent).setVisibility(View.GONE); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.TRUE.toString()); } }; ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener); ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener); // Legacy if (!PrivacyManager.cVersion3) { long now = new Date().getTime(); String legacy = PrivacyManager.getSetting(userId, PrivacyManager.cSettingLegacy, null); if (legacy == null || now > Long.parseLong(legacy) + 7 * 24 * 60 * 60 * 1000L) { showChangelog = false; PrivacyManager.setSetting(userId, PrivacyManager.cSettingLegacy, Long.toString(now)); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(R.string.app_name); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setMessage(R.string.title_update_legacy); alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Util.viewUri(ActivityMain.this, Uri.parse("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md#xprivacy3")); } }); alertDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); // Show dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } // Show changelog if (showChangelog) { String sVersion = PrivacyManager.getSetting(userId, PrivacyManager.cSettingChangelog, null); Version changelogVersion = new Version(sVersion == null ? "0.0" : sVersion); Version currentVersion = new Version(Util.getSelfVersionName(this)); if (sVersion == null || changelogVersion.compareTo(currentVersion) < 0) optionChangelog(); } }
From source file:android_network.hetnet.vpn_service.ServiceSinkhole.java
@Override public void onCreate() { Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Native init jni_init();// w w w .j a v a 2 s . c o m boolean pcap = prefs.getBoolean("pcap", false); setPcap(pcap, this); prefs.registerOnSharedPreferenceChangeListener(this); Util.setTheme(this); super.onCreate(); HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command", Process.THREAD_PRIORITY_FOREGROUND); HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log", Process.THREAD_PRIORITY_BACKGROUND); HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats", Process.THREAD_PRIORITY_BACKGROUND); commandThread.start(); logThread.start(); statsThread.start(); commandLooper = commandThread.getLooper(); logLooper = logThread.getLooper(); statsLooper = statsThread.getLooper(); commandHandler = new CommandHandler(commandLooper); logHandler = new LogHandler(logLooper); statsHandler = new StatsHandler(statsLooper); // Listen for power save mode if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Util.isPlayStoreInstall(this)) { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); powersaving = pm.isPowerSaveMode(); IntentFilter ifPower = new IntentFilter(); ifPower.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); registerReceiver(powerSaveReceiver, ifPower); registeredPowerSave = true; } // Listen for user switches if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { IntentFilter ifUser = new IntentFilter(); ifUser.addAction(Intent.ACTION_USER_BACKGROUND); ifUser.addAction(Intent.ACTION_USER_FOREGROUND); registerReceiver(userReceiver, ifUser); registeredUser = true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Listen for idle mode state changes IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); registerReceiver(idleStateReceiver, ifIdle); registeredIdleState = true; } // Listen for connectivity updates IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityChangedReceiver, ifConnectivity); registeredConnectivityChanged = true; // Listen for added applications IntentFilter ifPackage = new IntentFilter(); ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED); ifPackage.addDataScheme("package"); registerReceiver(packageAddedReceiver, ifPackage); registeredPackageAdded = true; // Setup house holding Intent alarmIntent = new Intent(this, ServiceSinkhole.class); alarmIntent.setAction(ACTION_HOUSE_HOLDING); PendingIntent pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi); }
From source file:com.ichi2.anki.AbstractFlashcardViewer.java
/** * Show/dismiss dialog when sd card is ejected/remounted (collection is saved by SdCardReceiver) */// w ww . j a va 2 s . c o m private void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) { finishWithoutAnimation(); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(SdCardReceiver.MEDIA_EJECT); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java
/** register boradcast*/ private void registerBoradcast() { IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction(Constants.RECEIVER_BROADCAST); intentfilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentfilter.addAction(Intent.ACTION_SCREEN_OFF); intentfilter.addAction(Intent.ACTION_SCREEN_ON); boradcastListener = new BroadcastReceiver() { @Override/* w w w . j a v a 2 s .c om*/ public void onReceive(Context context, Intent intent) { DebugLog.d(TAG, "WebViewActivity onReceive"); DebugLog.e(TAG, "BroadcastReceiver action = " + intent.getAction()); if (intent.getAction().equalsIgnoreCase(Constants.RECEIVER_BROADCAST)) { Bundle bundle = intent.getExtras(); int msgtype = bundle.getInt("msgtype"); String msgcontent = bundle.getString("msgcontent"); DebugLog.d(TAG, "handleMessage...... msgtype=" + msgtype + ", msgcontent=" + msgcontent); switch (msgtype) { case NotifyManagement.UP_PROBE_BAD_NETWORK: //irtsp 1.12 , WebBrowser is not need to handler the UP_PROBE_BAD_NETWORK event message. /*DebugLog.d(TAG, "UP_PROBE_BAD_NETWORK"); mPoorProbingresultFlag = true; mPlayer.bitrate_stopProbe(); notifyProbingCompleted(true);*/ break; case NotifyManagement.UP_PROBE_EXIT:// callback disconnectCB = 6 when bandwidth probe // success. Up_ui_gc.h DebugLog.d(TAG, "GameActivity.m_player.bitrate_stopProbe()"); //notifyProbingCompleted(true); /*if(bExitWaitProbeDone){ new Timer().schedule(new LogoutTimer(), 100); }*/ break; case NotifyManagement.UP_PROBE_EXIT_FAIL:// callback disconnectCB = 10 when bandwidth probe // fail. Up_ui_gc.h DebugLog.d(TAG, "WebViewActivity.onStart() probe fail, GameActivity.m_player.bitrate_stopProbe()"); //mPlayer.bitrate_stopProbe(); notifyProbingCompleted(false); /*if(bExitWaitProbeDone){ new Timer().schedule(new LogoutTimer(), 100); }*/ break; case NotifyManagement.UP_GAME_NOTIFY_DISPLAYTEXT: DebugLog.d(TAG, "notify UP_GAME_NOTIFY_DISPLAYTEXT"); gBNotifyDisplayExit = true; gNotifyDisplayText = msgcontent; break; case NotifyManagement.LOCAL_BROADCAST_CALL_UPDATE_STATE_200: callJsUpdateStatus(Constants.RESPONSE_200); break; case NotifyManagement.LOCAL_NOTIFY_WEBJS_GET_DUI: String gid = bundle.getString("gid"); String useragent = bundle.getString("useragent"); DebugLog.d(TAG, "notify webview js get DUI gid=" + gid + ",useragent=" + useragent); setToJsPlayMetadata(gid, useragent); break; case NotifyManagement.LOCAL_GAMEACTIVITY_RESULT: DebugLog.d(TAG, "Constants.LOCAL_GAMEACTIVITY_RESULT"); ((LoadWebJsActivity) mWebviewActivity).handleGameActivityResult(); break; case NotifyManagement.CAST_SESSION_STATUS_WEB: DebugLog.d(TAG, "build session have done"); String deviceId; String deviceName; String status; deviceId = bundle.getString("deviceId"); deviceName = bundle.getString("deviceName"); status = bundle.getString("status"); retPlayOnCast(deviceId, deviceName, status); synchronized (mLock) { mLock.notify(); DebugLog.d(TAG, "notify the thread"); } break; } } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { processNetworkType(intent, context); } if (intent.getAction().compareTo(Intent.ACTION_SCREEN_OFF) == 0) { DebugLog.d(TAG, "POWER ACTION_SCREEN_OFF"); final LoadWebJsActivity loadWebJsActivity = (LoadWebJsActivity) mContext; loadWebJsActivity.gBEntryPowerKeyMode = true; loadWebJsActivity.gCurEntryBackgroundTime = System.currentTimeMillis(); } else if (intent.getAction().compareTo(Intent.ACTION_SCREEN_ON) == 0) { DebugLog.d(TAG, "POWER ACTION_SCREEN_ON"); final LoadWebJsActivity loadWebJsActivity = (LoadWebJsActivity) mContext; loadWebJsActivity.gBEntryPowerKeyMode = false; // loadWebJsActivity.gCurEntryBackgroundTime = 0; } } }; this.mContext.registerReceiver(boradcastListener, intentfilter); }
From source file:com.andrew.apolloMod.service.ApolloService.java
/** * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. The * intent will call closeExternalStorageFiles() if the external media is * going to be ejected, so applications can clean up any files they have * open.//from ww w . j ava 2 s . com */ public void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_EJECT)) { saveQueue(true); mQueueIsSaveable = false; closeExternalStorageFiles(intent.getData().getPath()); } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { mMediaMountedCount++; mCardId = MusicUtils.getCardId(ApolloService.this); reloadQueue(); mQueueIsSaveable = true; notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(Intent.ACTION_MEDIA_EJECT); iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); iFilter.addDataScheme(DATA_SCHEME); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:com.andrew.apolloMod.service.ApolloService.java
@SuppressLint({ "WorldWriteableFiles", "WorldReadableFiles" }) @Override/*w ww .j a va 2 s. c o m*/ public void onCreate() { super.onCreate(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(rec); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(rec); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Constants.isApi14Supported()) { mRemoteControlClient = new RemoteControlClient(mediaPendingIntent); mAudioManager.registerRemoteControlClient(mRemoteControlClient); int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP; mRemoteControlClient.setTransportControlFlags(flags); } mPreferences = getSharedPreferences(APOLLO_PREFERENCES, MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE); mCardId = MusicUtils.getCardId(this); registerExternalStorageListener(); // Needs to be done in this thread, since otherwise // ApplicationContext.getPowerManager() crashes. mPlayer = new MultiPlayer(); mPlayer.setHandler(mMediaplayerHandler); reloadQueue(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); IntentFilter commandFilter = new IntentFilter(); commandFilter.addAction(SERVICECMD); commandFilter.addAction(TOGGLEPAUSE_ACTION); commandFilter.addAction(PAUSE_ACTION); commandFilter.addAction(NEXT_ACTION); commandFilter.addAction(PREVIOUS_ACTION); commandFilter.addAction(CYCLEREPEAT_ACTION); commandFilter.addAction(TOGGLESHUFFLE_ACTION); registerReceiver(mIntentReceiver, commandFilter); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); mWakeLock.setReferenceCounted(false); // If the service was idle, but got killed before it stopped itself, the // system will relaunch it. Make sure it gets stopped again in that // case. Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); }
From source file:com.devalladolid.musictoday.MusicService.java
@Override public void onCreate() { if (D)/*from w w w.ja va 2 s . c om*/ Log.d(TAG, "Creating service"); super.onCreate(); mNotificationManager = NotificationManagerCompat.from(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); mSongPlayCount = SongPlayCount.getInstance(this); mRecentStore = RecentStore.getInstance(this); mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) setUpMediaSession(); mPreferences = getSharedPreferences("Service", 0); mCardId = getCardId(); registerExternalStorageListener(); mPlayer = new MultiPlayer(this); mPlayer.setHandler(mPlayerHandler); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(SERVICECMD); filter.addAction(TOGGLEPAUSE_ACTION); filter.addAction(PAUSE_ACTION); filter.addAction(STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(PREVIOUS_FORCE_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler); getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver); getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver); // Initialize the wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); final Intent shutdownIntent = new Intent(this, MusicService.class); shutdownIntent.setAction(SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); scheduleDelayedShutdown(); reloadQueueAfterPermissionCheck(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:eu.faircode.netguard.ServiceSinkhole.java
@Override public void onCreate() { Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Native init jni_init();/*from ww w. j a va2s . c o m*/ boolean pcap = prefs.getBoolean("pcap", false); setPcap(pcap, this); prefs.registerOnSharedPreferenceChangeListener(this); Util.setTheme(this); super.onCreate(); HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command", Process.THREAD_PRIORITY_FOREGROUND); HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log", Process.THREAD_PRIORITY_BACKGROUND); HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats", Process.THREAD_PRIORITY_BACKGROUND); commandThread.start(); logThread.start(); statsThread.start(); commandLooper = commandThread.getLooper(); logLooper = logThread.getLooper(); statsLooper = statsThread.getLooper(); commandHandler = new CommandHandler(commandLooper); logHandler = new LogHandler(logLooper); statsHandler = new StatsHandler(statsLooper); // Listen for power save mode if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Util.isPlayStoreInstall(this)) { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); powersaving = pm.isPowerSaveMode(); IntentFilter ifPower = new IntentFilter(); ifPower.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); registerReceiver(powerSaveReceiver, ifPower); registeredPowerSave = true; } // Listen for user switches if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { IntentFilter ifUser = new IntentFilter(); ifUser.addAction(Intent.ACTION_USER_BACKGROUND); ifUser.addAction(Intent.ACTION_USER_FOREGROUND); registerReceiver(userReceiver, ifUser); registeredUser = true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Listen for idle mode state changes IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); registerReceiver(idleStateReceiver, ifIdle); registeredIdleState = true; } // Listen for connectivity updates IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityChangedReceiver, ifConnectivity); registeredConnectivityChanged = true; // Listen for added applications IntentFilter ifPackage = new IntentFilter(); ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED); ifPackage.addAction(Intent.ACTION_PACKAGE_REMOVED); ifPackage.addDataScheme("package"); registerReceiver(packageChangedReceiver, ifPackage); registeredPackageChanged = true; // Setup house holding Intent alarmIntent = new Intent(this, ServiceSinkhole.class); alarmIntent.setAction(ACTION_HOUSE_HOLDING); PendingIntent pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi); }
From source file:com.filemanager.free.activities.MainActivity.java
@Override public void onResume() { AdWrapper.viewAd(true, mainActivity); requestNewInterstitial();/* w w w . j a v a2 s . c om*/ if (materialDialog != null && !materialDialog.isShowing()) { materialDialog.show(); materialDialog = null; } IntentFilter newFilter = new IntentFilter(); newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); newFilter.addDataScheme(ContentResolver.SCHEME_FILE); registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter); registerReceiver(receiver2, new IntentFilter("general_communications")); if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName() .contains("TabFragment")) { floatingActionButton.setVisibility(View.VISIBLE); floatingActionButton.showMenuButton(false); } else { floatingActionButton.setVisibility(View.INVISIBLE); floatingActionButton.hideMenuButton(false); } super.onResume(); }