Example usage for android.content IntentFilter addAction

List of usage examples for android.content IntentFilter addAction

Introduction

In this page you can find the example usage for android.content IntentFilter addAction.

Prototype

public final void addAction(String action) 

Source Link

Document

Add a new Intent action to match against.

Usage

From source file:com.google.android.marvin.mytalkback.TalkBackService.java

/**
 * Registers listeners, sets service info, loads preferences. This should be
 * called from {@link #onServiceConnected} and when TalkBack resumes from a
 * suspended state./*from   w ww. j av  a2  s  . c  om*/
 */
private void resumeInfrastructure() {
    if (isServiceActive()) {
        LogUtils.log(this, Log.ERROR, "Attempted to resume while not suspended");
        return;
    }

    setServiceState(ServiceState.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;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REPORT_VIEW_IDS;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_FILTER_KEY_EVENTS;
    info.notificationTimeout = 0;

    // Ensure the initial touch exploration request mode is correct.
    if (SUPPORTS_TOUCH_PREF && SharedPreferencesUtils.getBooleanPref(mPrefs, getResources(),
            R.string.pref_explore_by_touch_key, R.bool.pref_explore_by_touch_default)) {
        info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_TOUCH_EXPLORATION_MODE;
    }

    setServiceInfo(info);

    if (mCallStateMonitor != null) {
        registerReceiver(mCallStateMonitor, mCallStateMonitor.getFilter());
    }

    if (mRingerModeAndScreenMonitor != null) {
        registerReceiver(mRingerModeAndScreenMonitor, mRingerModeAndScreenMonitor.getFilter());
    }

    if (mTextToSpeechManager != null) {
        mTextToSpeechManager.startDiscovery();
    }

    if (mRadialMenuManager != null) {
        registerReceiver(mRadialMenuManager, mRadialMenuManager.getFilter());
    }

    if (mVolumeMonitor != null) {
        registerReceiver(mVolumeMonitor, mVolumeMonitor.getFilter());
    }

    mPrefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);

    // Add the broadcast listener for gestures.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_PERFORM_GESTURE);
    registerReceiver(mActiveReceiver, filter, PERMISSION_TALKBACK, 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();
}

From source file:com.android.app.MediaPlaybackActivity.java

@Override
public void onStart() {
    super.onStart();

    paused = false;//from w w  w . j a  v a 2 s. c  om

    mToken = MusicUtils.bindToService(this, osc);
    if (mToken == null) {
        // something went wrong
        mHandler.sendEmptyMessage(QUIT);
    }

    IntentFilter f = new IntentFilter();
    f.addAction(MediaPlaybackService.PLAYSTATE_CHANGED);
    f.addAction(MediaPlaybackService.META_CHANGED);
    registerReceiver(mStatusListener, new IntentFilter(f));
    updateTrackInfo();
    long next = refreshNow();
    queueNextRefresh(next);
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    DataSource.createIcons(getResources());

    try {//  w w  w  .  java 2  s.c  o m
        // ??
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        // ?    ?? ?
        this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");
        // ?? 
        locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        //  ?? . 2 ?? (1/1000s), 3 ?? (m)? ? 
        locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 3, this);

        //orientation sensor 
        sensorMgr_ori = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        orientationSensor = sensorMgr_ori.getDefaultSensor(Sensor.TYPE_ORIENTATION);

        killOnError(); // ?  ?
        requestWindowFeature(Window.FEATURE_NO_TITLE); // ?   ? 

        //  ?? 
        FrameLayout frameLayout = new FrameLayout(this);

        //  ?    ?, ? 
        frameLayout.setMinimumWidth(3000);
        frameLayout.setPadding(10, 0, 10, 10);

        // ? ? ? ?? ?
        camScreen = new CameraSurface(this);
        augScreen = new AugmentedView(this);
        setContentView(camScreen); // ? ?? ?  ? 

        // ? ?? ? 
        addContentView(augScreen, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        // ? ? ? ?   ?.
        // ? ?  ?  ?? ?  ?  ?
        addContentView(frameLayout, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));

        topLayoutOnMixView = new TopLayoutOnMixView(this);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        addContentView(topLayoutOnMixView.mainArView, params);

        // ? ? ? topLayoutOnMixView ?  ?
        handleIntent(getIntent()); // ?? 

        //  ? ? ?
        if (!isInited) {
            mixContext = new MixContext(this); // ? ?
            // ? ?
            mixContext.downloadManager = new DownloadManager(mixContext);

            //? ?  ? 
            navigator = new Navigator(mixContext, topLayoutOnMixView.naverFragment);

            // ? ? ?? ? ?
            dWindow = new PaintScreen();
            dataView = new DataView(mixContext);

            isInited = true; //   true

        }

        if (mixContext.isActualLocation() == false) {
            Toast.makeText(this, getString(DataView.CONNECTION_GPS_DIALOG_TEXT), Toast.LENGTH_LONG).show();
        }

    } catch (Exception ex) {
        doError(ex); //  ? ? 
    }

    //   ? 
    IntentFilter naviBraodFilter = new IntentFilter();
    naviBraodFilter.addAction("NAVI");
    registerReceiver(naviRecevicer, naviBraodFilter);
}

From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java

private void setupWifiBroadcast() {
    broadcastReceiver = new WifiBroadcastReceiver(ShowModuleActivity.this);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    registerReceiver(broadcastReceiver, intentFilter);

    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    // initialize wifi connection state
    if (mWifi != null && mWifi.isConnected()) {
        wifiConnected = true;//from   w w  w. j  a v a  2 s .c  om
    }
}

From source file:RhodesService.java

private File downloadPackage(String url) throws IOException {
    final Context ctx = RhodesActivity.getContext();

    final Thread thisThread = Thread.currentThread();

    final Runnable cancelAction = new Runnable() {
        public void run() {
            thisThread.interrupt();/* w  w  w  . ja v a 2  s  . c o m*/
        }
    };

    BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(ACTION_ASK_CANCEL_DOWNLOAD)) {
                AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
                builder.setMessage("Cancel download?");
                AlertDialog dialog = builder.create();
                dialog.setButton(AlertDialog.BUTTON_POSITIVE, ctx.getText(android.R.string.yes),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                cancelAction.run();
                            }
                        });
                dialog.setButton(AlertDialog.BUTTON_NEGATIVE, ctx.getText(android.R.string.no),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // Nothing
                            }
                        });
                dialog.show();
            } else if (action.equals(ACTION_CANCEL_DOWNLOAD)) {
                cancelAction.run();
            }
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_ASK_CANCEL_DOWNLOAD);
    filter.addAction(ACTION_CANCEL_DOWNLOAD);
    ctx.registerReceiver(downloadReceiver, filter);

    File tmpFile = null;
    InputStream is = null;
    OutputStream os = null;
    try {
        updateDownloadNotification(url, -1, 0);

        /*
        List<File> folders = new ArrayList<File>();
        folders.add(Environment.getDownloadCacheDirectory());
        folders.add(Environment.getDataDirectory());
        folders.add(ctx.getCacheDir());
        folders.add(ctx.getFilesDir());
        try {
           folders.add(new File(ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), 0).dataDir));
        } catch (NameNotFoundException e1) {
           // Ignore
        }
        folders.add(Environment.getExternalStorageDirectory());
                
        for (File folder : folders) {
           File tmpRootFolder = new File(folder, "rhodownload");
           File tmpFolder = new File(tmpRootFolder, ctx.getPackageName());
           if (tmpFolder.exists())
              deleteFilesInFolder(tmpFolder.getAbsolutePath());
           else
              tmpFolder.mkdirs();
                   
           File of = new File(tmpFolder, UUID.randomUUID().toString() + ".apk");
           Logger.D(TAG, "Check path " + of.getAbsolutePath() + "...");
           try {
              os = new FileOutputStream(of);
           }
           catch (FileNotFoundException e) {
              Logger.D(TAG, "Can't open file " + of.getAbsolutePath() + ", check next path");
              continue;
           }
           Logger.D(TAG, "File " + of.getAbsolutePath() + " succesfully opened for write, start download app");
                   
           tmpFile = of;
           break;
        }
        */

        tmpFile = ctx.getFileStreamPath(UUID.randomUUID().toString() + ".apk");
        os = ctx.openFileOutput(tmpFile.getName(), Context.MODE_WORLD_READABLE);

        Logger.D(TAG, "Download " + url + " to " + tmpFile.getAbsolutePath() + "...");

        URL u = new URL(url);
        URLConnection conn = u.openConnection();
        int totalBytes = -1;
        if (conn instanceof HttpURLConnection) {
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            totalBytes = httpConn.getContentLength();
        }
        is = conn.getInputStream();

        int downloaded = 0;
        updateDownloadNotification(url, totalBytes, downloaded);

        long prevProgress = 0;
        byte[] buf = new byte[65536];
        for (;;) {
            if (thisThread.isInterrupted()) {
                tmpFile.delete();
                Logger.D(TAG, "Download of " + url + " was canceled");
                return null;
            }
            int nread = is.read(buf);
            if (nread == -1)
                break;

            //Logger.D(TAG, "Downloading " + url + ": got " + nread + " bytes...");
            os.write(buf, 0, nread);

            downloaded += nread;
            if (totalBytes > 0) {
                // Update progress view only if current progress is greater than
                // previous by more than 10%. Otherwise, if update it very frequently,
                // user will no have chance to click on notification view and cancel if need
                long progress = downloaded * 10 / totalBytes;
                if (progress > prevProgress) {
                    updateDownloadNotification(url, totalBytes, downloaded);
                    prevProgress = progress;
                }
            }
        }

        Logger.D(TAG, "File stored to " + tmpFile.getAbsolutePath());

        return tmpFile;
    } catch (IOException e) {
        if (tmpFile != null)
            tmpFile.delete();
        throw e;
    } finally {
        try {
            if (is != null)
                is.close();
        } catch (IOException e) {
        }
        try {
            if (os != null)
                os.close();
        } catch (IOException e) {
        }

        mNM.cancel(DOWNLOAD_PACKAGE_ID);
        ctx.unregisterReceiver(downloadReceiver);
    }
}

From source file:com.google.android.marvin.talkback.TalkBackService.java

/**
 * Registers listeners, sets service info, loads preferences. This should be
 * called from {@link #onServiceConnected} and when TalkBack resumes from a
 * suspended state.//from  w  w w .j a v a2 s  .  com
 */
private void resumeInfrastructure() {
    if (isServiceActive()) {
        LogUtils.log(this, Log.ERROR, "Attempted to resume while not suspended");
        return;
    }

    setServiceState(ServiceState.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;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REPORT_VIEW_IDS;
    info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_FILTER_KEY_EVENTS;
    info.notificationTimeout = 0;

    // Ensure the initial touch exploration request mode is correct.
    if (SUPPORTS_TOUCH_PREF && SharedPreferencesUtils.getBooleanPref(mPrefs, getResources(),
            R.string.pref_explore_by_touch_key, R.bool.pref_explore_by_touch_default)) {
        info.flags |= AccessibilityServiceInfoCompatUtils.FLAG_REQUEST_TOUCH_EXPLORATION_MODE;
    }

    setServiceInfo(info);

    if (mCallStateMonitor != null) {
        registerReceiver(mCallStateMonitor, mCallStateMonitor.getFilter());
    }

    if (mRingerModeAndScreenMonitor != null) {
        registerReceiver(mRingerModeAndScreenMonitor, mRingerModeAndScreenMonitor.getFilter());
    }

    if (mTextToSpeechManager != null) {
        mTextToSpeechManager.startDiscovery();
    }

    if (mRadialMenuManager != null) {
        registerReceiver(mRadialMenuManager, mRadialMenuManager.getFilter());
    }

    if (mVolumeMonitor != null) {
        registerReceiver(mVolumeMonitor, mVolumeMonitor.getFilter());
    }

    if (mPackageReceiver != null) {
        registerReceiver(mPackageReceiver, mPackageReceiver.getFilter());
        if (mLabelManager != null) {
            mLabelManager.ensureDataConsistency();
        }
    }

    mPrefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);

    // Add the broadcast listener for gestures.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_PERFORM_GESTURE_ACTION);
    registerReceiver(mActiveReceiver, filter, PERMISSION_TALKBACK, 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();
}

From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java

public void onResume() {
    super.onResume();
    //register bluetooth receiver
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);

    registerReceiver(mBroadcastReceiver, intentFilter);
}

From source file:com.digitalarx.android.ui.activity.FileDisplayActivity.java

@Override
protected void onResume() {
    super.onResume();
    Log_OC.e(TAG, "onResume() start");

    // refresh list of files
    refreshListOfFilesFragment();/* w w  w .  j a  va 2  s. c  o m*/

    // 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(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
    syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
    mSyncBroadcastReceiver = new SyncBroadcastReceiver();
    registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
    //LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);

    // Listen for upload messages
    IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage());
    mUploadFinishReceiver = new UploadFinishReceiver();
    registerReceiver(mUploadFinishReceiver, uploadIntentFilter);

    // Listen for download messages
    IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.getDownloadAddedMessage());
    downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
    mDownloadFinishReceiver = new DownloadFinishReceiver();
    registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);

    Log_OC.d(TAG, "onResume() end");
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    T.UI();/*from  w  w  w  . ja va 2  s .  c om*/
    createWorkerThread();
    mUIHandler = new Handler();
    T.setUIThread("RegistrationProcedureActivity.onCreate()");
    setTitle(R.string.registration_title);

    mHttpClient = HTTPUtil.getHttpClient(HTTP_TIMEOUT, HTTP_RETRY_COUNT);

    final IntentFilter filter = new IntentFilter(MainService.INTENT_BEACON_SERVICE_CONNECTED);
    filter.addAction(RegistrationWizard2.INTENT_GOT_BEACON_REGIONS);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(mBroadcastReceiver, filter);

    startRegistrationService();

    // TODO: This has to be improved.
    // If the app relies on GCM the user should not be able to register.
    if (CloudConstants.USE_GCM_KICK_CHANNEL)
        GoogleServicesUtils.checkPlayServices(this);

}

From source file:com.findcab.activity.LocationOverlay.java

/**
 * ?//from   www  .j  a  v a 2 s .co  m
 */
private void initMyBroadcastReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction("cn.jpush.android.intent.REGISTRATION");// SDKintent
    filter.addAction("cn.jpush.android.intent.UNREGISTRATION");
    filter.addAction("cn.jpush.android.intent.MESSAGE_RECEIVED");// SDK?intent
    filter.addAction("cn.jpush.android.intent.NOTIFICATION_RECEIVED");// SDK??intent
    filter.addAction("cn.jpush.android.intent.NOTIFICATION_OPENED");// ?intent
    filter.addCategory("com.findcab");
    getApplicationContext().registerReceiver(MyReceiver, filter); // 
}