List of usage examples for android.content IntentFilter addAction
public final void addAction(String action)
From source file:com.moez.QKSMS.mmssms.Transaction.java
private void trySending(final APN apns, final byte[] bytesToSend, final int numRetries) { try {//w ww . ja va 2 s. c om IntentFilter filter = new IntentFilter(); filter.addAction(ProgressCallbackEntity.PROGRESS_STATUS_ACTION); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int progress = intent.getIntExtra("progress", -3); if (LOCAL_LOGV) Log.v(TAG, "progress: " + progress); // send progress broadcast to update ui if desired... Intent progressIntent = new Intent(MMS_PROGRESS); progressIntent.putExtra("progress", progress); context.sendBroadcast(progressIntent); if (progress == ProgressCallbackEntity.PROGRESS_COMPLETE) { if (saveMessage) { Cursor query = context.getContentResolver().query(Uri.parse("content://mms"), new String[] { "_id" }, null, null, "date desc"); if (query != null && query.moveToFirst()) { String id = query.getString(query.getColumnIndex("_id")); query.close(); // move to the sent box ContentValues values = new ContentValues(); values.put("msg_box", 2); String where = "_id" + " = '" + id + "'"; context.getContentResolver().update(Uri.parse("content://mms"), values, where, null); } } context.sendBroadcast(new Intent(REFRESH)); try { context.unregisterReceiver(this); } catch (Exception e) { /* Receiver not registered */ } // give everything time to finish up, may help the abort being shown after the progress is already 100 new Handler().postDelayed(new Runnable() { @Override public void run() { mConnMgr.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE_MMS, "enableMMS"); if (settings.getWifiMmsFix()) { reinstateWifi(); } } }, 1000); } else if (progress == ProgressCallbackEntity.PROGRESS_ABORT) { // This seems to get called only after the progress has reached 100 and then something else goes wrong, so here we will try and send again and see if it works if (LOCAL_LOGV) Log.v(TAG, "sending aborted for some reason..."); context.unregisterReceiver(this); if (numRetries < NUM_RETRIES) { // sleep and try again in three seconds to see if that give wifi and mobile data a chance to toggle in time try { Thread.sleep(3000); } catch (Exception f) { } if (settings.getWifiMmsFix()) { sendMMS(bytesToSend); } else { sendMMSWiFi(bytesToSend); } } else { markMmsFailed(); } } } }; context.registerReceiver(receiver, filter); // This is where the actual post request is made to send the bytes we previously created through the given apns if (LOCAL_LOGV) Log.v(TAG, "attempt: " + numRetries); Utils.ensureRouteToHost(context, apns.MMSCenterUrl, apns.MMSProxy); HttpUtils.httpConnection(context, 4444L, apns.MMSCenterUrl, bytesToSend, HttpUtils.HTTP_POST_METHOD, !TextUtils.isEmpty(apns.MMSProxy), apns.MMSProxy, Integer.parseInt(apns.MMSPort)); } catch (IOException e) { if (LOCAL_LOGV) Log.v(TAG, "some type of error happened when actually sending maybe?"); Log.e(TAG, "exception thrown", e); if (numRetries < NUM_RETRIES) { // sleep and try again in three seconds to see if that give wifi and mobile data a chance to toggle in time try { Thread.sleep(3000); } catch (Exception f) { } trySending(apns, bytesToSend, numRetries + 1); } else { markMmsFailed(); } } }
From source file:com.android.music.TrackBrowserFragment.java
public void onServiceConnected(ComponentName name, IBinder service) { IntentFilter f = new IntentFilter(); f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); f.addAction(Intent.ACTION_MEDIA_UNMOUNTED); f.addDataScheme("file"); getActivity().registerReceiver(mScanListener, f); if (mAdapter == null) { //Log.i("@@@", "starting query"); mAdapter = new TrackListAdapter(getActivity().getApplication(), // need to use application context to avoid leaks this, mEditMode ? R.layout.edit_track_list_item : R.layout.track_list_item, null, // cursor new String[] {}, new int[] {}, "nowplaying".equals(mPlaylist), mPlaylist != null && !(mPlaylist.equals("podcasts") || mPlaylist.equals("recentlyadded"))); mTrackList.setAdapter(mAdapter); //getActivity().setTitle(R.string.working_songs); getTrackCursor(mAdapter.getQueryHandler(), null, true); } else {//from w w w . jav a 2 s .c o m mTrackCursor = mAdapter.getCursor(); // If mTrackCursor is null, this can be because it doesn't have // a cursor yet (because the initial query that sets its cursor // is still in progress), or because the query failed. // In order to not flash the error dialog at the user for the // first case, simply retry the query when the cursor is null. // Worst case, we end up doing the same query twice. if (mTrackCursor != null) { init(mTrackCursor, false); } else { //getActivity(). setTitle(R.string.working_songs); getTrackCursor(mAdapter.getQueryHandler(), null, true); } } if (!mEditMode) { MusicUtils.updateNowPlaying(getActivity()); } }
From source file:com.android.music.TrackBrowserFragment.java
public void init(Cursor newCursor, boolean isLimited) { if (mAdapter == null) { return;//www . j ava 2 s .c om } mAdapter.changeCursor(newCursor); // also sets mTrackCursor if (mTrackCursor == null) { MusicUtils.displayDatabaseError(getActivity()); getActivity().closeContextMenu(); mReScanHandler.sendEmptyMessageDelayed(0, 1000); return; } MusicUtils.hideDatabaseError(getActivity()); //mUseLastListPos = MusicUtils.updateButtonBar(getActivity(), R.id.songtab); //setTitle(); // Restore previous position if (mLastListPosCourse >= 0 && mUseLastListPos) { //ListView lv = getListView(); // this hack is needed because otherwise the position doesn't change // for the 2nd (non-limited) cursor mTrackList.setAdapter(mTrackList.getAdapter()); mTrackList.setSelectionFromTop(mLastListPosCourse, mLastListPosFine); if (!isLimited) { mLastListPosCourse = -1; } } // When showing the queue, position the selection on the currently playing track // Otherwise, position the selection on the first matching artist, if any IntentFilter f = new IntentFilter(); f.addAction(MediaPlaybackService.META_CHANGED); f.addAction(MediaPlaybackService.QUEUE_CHANGED); if ("nowplaying".equals(mPlaylist)) { try { int cur = MusicUtils.sService.getQueuePosition(); mTrackList.setSelection(cur); getActivity().registerReceiver(mNowPlayingListener, new IntentFilter(f)); mNowPlayingListener.onReceive(getActivity(), new Intent(MediaPlaybackService.META_CHANGED)); } catch (RemoteException ex) { } } else { String key = getActivity().getIntent().getStringExtra("artist"); if (key != null) { int keyidx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID); mTrackCursor.moveToFirst(); while (!mTrackCursor.isAfterLast()) { String artist = mTrackCursor.getString(keyidx); if (artist.equals(key)) { mTrackList.setSelection(mTrackCursor.getPosition()); break; } mTrackCursor.moveToNext(); } } getActivity().registerReceiver(mTrackListListener, new IntentFilter(f)); mTrackListListener.onReceive(getActivity(), new Intent(MediaPlaybackService.META_CHANGED)); } }
From source file:com.google.android.marvin.screenspeak.ScreenSpeakService.java
/** * Suspends ScreenSpeak and Explore by Touch. *///from w w w . j a va2 s . c om public void suspendScreenSpeak() { if (!isServiceActive()) { if (LogUtils.LOG_LEVEL <= Log.ERROR) { Log.e(LOGTAG, "Attempted to suspend ScreenSpeak while already suspended."); } return; } SharedPreferencesUtils.storeBooleanAsync(mPrefs, getString(R.string.pref_suspended), true); mFeedbackController.playAuditory(R.raw.paused_feedback); if (mSupportsTouchScreen) { requestTouchExploration(false); } if (mCursorController != null) { try { mCursorController.clearCursor(); } catch (SecurityException e) { if (LogUtils.LOG_LEVEL >= Log.ERROR) { Log.e(LOGTAG, "Unable to clear cursor"); } } } final IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_RESUME_FEEDBACK); filter.addAction(Intent.ACTION_SCREEN_ON); registerReceiver(mSuspendedReceiver, filter, PERMISSION_SCREENSPEAK, null); // Suspending infrastructure sets sIsScreenSpeakSuspended to true. suspendInfrastructure(); final Intent resumeIntent = new Intent(ACTION_RESUME_FEEDBACK); final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, resumeIntent, 0); final Notification notification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.notification_title_screenspeak_suspended)) .setContentText(getString(R.string.notification_message_screenspeak_suspended)) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.ic_stat_info) .setContentIntent(pendingIntent).setOngoing(true).setWhen(0).build(); startForeground(R.id.notification_suspended, notification); mSpeechController.speak(getString(R.string.screenspeak_suspended), SpeechController.QUEUE_MODE_UNINTERRUPTIBLE, 0, null); }
From source file:android_network.hetnet.vpn_service.ActivitySettings.java
@Override protected void onResume() { super.onResume(); // Check if permissions were revoked checkPermissions();// w w w . j a v a 2 s. co m // Listen for preference changes SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); // Listen for interactive state changes IntentFilter ifInteractive = new IntentFilter(); ifInteractive.addAction(Intent.ACTION_SCREEN_ON); ifInteractive.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(interactiveStateReceiver, ifInteractive); // Listen for connectivity updates IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityChangedReceiver, ifConnectivity); if (Util.hasPhoneStatePermission(this)) { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(phoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_SERVICE_STATE); phone_state = true; } }
From source file:com.google.android.marvin.screenspeak.ScreenSpeakService.java
/** * Registers listeners, sets service info, loads preferences. This should be * called from {@link #onServiceConnected} and when ScreenSpeak resumes from a * suspended state./*from w w w.j a v a 2 s . c o m*/ */ private void resumeInfrastructure() { if (isServiceActive()) { if (LogUtils.LOG_LEVEL <= Log.ERROR) { Log.e(LOGTAG, "Attempted to resume while not suspended"); } return; } setServiceState(SERVICE_STATE_ACTIVE); stopForeground(true); final AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK; info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_SPOKEN; info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_AUDIBLE; info.feedbackType |= AccessibilityServiceInfo.FEEDBACK_HAPTIC; info.flags |= AccessibilityServiceInfo.DEFAULT; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { info.flags |= AccessibilityServiceInfo.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY; info.flags |= AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS; info.flags |= AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { info.flags |= AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS; } info.notificationTimeout = 0; // Ensure the initial touch exploration request mode is correct. if (mSupportsTouchScreen && SharedPreferencesUtils.getBooleanPref(mPrefs, getResources(), R.string.pref_explore_by_touch_key, R.bool.pref_explore_by_touch_default)) { info.flags |= AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE; } setServiceInfo(info); if (mRingerModeAndScreenMonitor != null) { registerReceiver(mRingerModeAndScreenMonitor, mRingerModeAndScreenMonitor.getFilter()); // It could now be confused with the current screen state mRingerModeAndScreenMonitor.updateScreenState(); } if (mVolumeMonitor != null) { registerReceiver(mVolumeMonitor, mVolumeMonitor.getFilter()); } if (mBatteryMonitor != null) { registerReceiver(mBatteryMonitor, mBatteryMonitor.getFilter()); } if (mPackageReceiver != null) { registerReceiver(mPackageReceiver, mPackageReceiver.getFilter()); if (mLabelManager != null) { mLabelManager.ensureDataConsistency(); } } if (mSideTapManager != null) { registerReceiver(mSideTapManager, SideTapManager.getFilter()); } mPrefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener); // Add the broadcast listener for gestures. final IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_PERFORM_GESTURE_ACTION); registerReceiver(mActiveReceiver, filter, PERMISSION_SCREENSPEAK, null); // Enable the proxy activity for long-press search. final PackageManager packageManager = getPackageManager(); final ComponentName shortcutProxy = new ComponentName(this, ShortcutProxyActivity.class); packageManager.setComponentEnabledSetting(shortcutProxy, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); reloadPreferences(); if (mDimScreenController.isDimmingEnabled()) { mDimScreenController.makeScreenDim(); } }
From source file:com.google.android.marvin.mytalkback.TalkBackService.java
/** * Suspends TalkBack and Explore by Touch. *//*from www. j a v a 2 s. c om*/ private void suspendTalkBack() { if (!isServiceActive()) { LogUtils.log(this, Log.ERROR, "Attempted to suspend TalkBack while already suspended."); return; } mFeedbackController.playAuditory(R.id.sounds_paused_feedback); if (SUPPORTS_TOUCH_PREF) { requestTouchExploration(false); } if (mCursorController != null) { mCursorController.clearCursor(); } final IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_RESUME_FEEDBACK); filter.addAction(Intent.ACTION_SCREEN_ON); registerReceiver(mSuspendedReceiver, filter, PERMISSION_TALKBACK, null); // Suspending infrastructure sets sIsTalkBackSuspended to true. suspendInfrastructure(); final Intent resumeIntent = new Intent(ACTION_RESUME_FEEDBACK); final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, resumeIntent, 0); final Notification notification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.notification_title_talkback_suspended)) .setContentText(getString(R.string.notification_message_talkback_suspended)) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.ic_stat_info) .setContentIntent(pendingIntent).setOngoing(true).setWhen(0).build(); startForeground(R.id.notification_suspended, notification); }
From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java
/** * {@inheritDoc}// ww w.j av a 2 s . co m */ @Override protected void onCreate(Bundle state) { if (DEBUG) { Log.d(TAG, "NavigationActivity.onCreate"); //$NON-NLS-1$ } // Register the broadcast receiver IntentFilter filter = new IntentFilter(); filter.addAction(FileManagerSettings.INTENT_SETTING_CHANGED); filter.addAction(FileManagerSettings.INTENT_FILE_CHANGED); filter.addAction(FileManagerSettings.INTENT_THEME_CHANGED); registerReceiver(this.mNotificationReceiver, filter); //Set the main layout of the activity setContentView(R.layout.navigation_pager); //Initialize nfc adapter NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this); if (mNfcAdapter != null && Build.VERSION.SDK_INT > 15) { mNfcAdapter.setBeamPushUrisCallback(new NfcAdapter.CreateBeamUrisCallback() { @Override public Uri[] createBeamUris(NfcEvent event) { List<FileSystemObject> selectedFiles = getCurrentNavigationFragment().getSelectedFiles(); if (selectedFiles.size() > 0) { List<Uri> fileUri = new ArrayList<Uri>(); for (FileSystemObject f : selectedFiles) { //Beam ignores folders and system files if (!FileHelper.isDirectory(f) && !FileHelper.isSystemFile(f)) { fileUri.add(Uri.fromFile(new File(f.getFullPath()))); } } if (fileUri.size() > 0) { return fileUri.toArray(new Uri[fileUri.size()]); } } return null; } }, this); } //Initialize activity init(); //Initialize viewPager initViewPager(); //Initialize action bar mActionBar = getActionBar(); initTitleActionBar(); // Apply the theme applyTheme(); // Show welcome message showWelcomeMsg(); //Save state super.onCreate(state); }