Example usage for android.content IntentFilter IntentFilter

List of usage examples for android.content IntentFilter IntentFilter

Introduction

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

Prototype

public IntentFilter(Parcel source) 

Source Link

Usage

From source file:com.cssweb.android.base.BaseActivity.java

private void listenScreen() {
    lockreceiver = new BroadcastReceiver() {

        @Override//from  ww  w .  j a v  a  2 s.com
        public void onReceive(Context context, Intent intent) {

            ServiceControl.pauseScreenReceiver();
        }
    };
    registerReceiver(lockreceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
    homereceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            ServiceControl.resumeScreenReceiver();
        }
    };
    registerReceiver(homereceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));

}

From source file:com.frostwire.android.gui.activities.MainActivity.java

private void registerMainBroadcastReceiver() {
    mainBroadcastReceiver = new MainBroadcastReceiver(this);
    IntentFilter bf = new IntentFilter(Constants.ACTION_NOTIFY_SDCARD_MOUNTED);
    registerReceiver(mainBroadcastReceiver, bf);
}

From source file:com.ekumen.tangobot.application.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    registerReceiver(mUsbAttachedReceiver, new IntentFilter(ACTION_USB_PERMISSION));
    registerReceiver(mUsbDetachedReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED));
}

From source file:me.willowcheng.makerthings.ui.OpenHABMainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate()");
    // Check if we are in development mode
    perPreferences = getSharedPreferences("pref", this.MODE_PRIVATE);
    isDeveloper = false;//  www. jav a  2  s  .c o m
    // Set default values, false means do it one time during the very first launch
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    // Set non-persistent HABDroid version preference to current version from application package
    try {
        Log.d(TAG, "App version = " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
        PreferenceManager.getDefaultSharedPreferences(this).edit().putString(Constants.PREFERENCE_APPVERSION,
                getPackageManager().getPackageInfo(getPackageName(), 0).versionName).commit();
    } catch (PackageManager.NameNotFoundException e1) {
        if (e1 != null)
            Log.d(TAG, e1.getMessage());
    }
    checkDiscoveryPermissions();
    checkVoiceRecognition();
    // initialize loopj async http client
    mAsyncHttpClient = new MyAsyncHttpClient(this);
    // Set the theme to one from preferences
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    // Disable screen timeout if set in preferences
    if (mSettings.getBoolean(Constants.PREFERENCE_SCREENTIMEROFF, false)) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
    // Fetch openHAB service type name from strings.xml
    openHABServiceType = getString(R.string.openhab_service_type);
    // Get username/password from preferences
    openHABUsername = mSettings.getString(Constants.PREFERENCE_USERNAME, null);
    openHABPassword = mSettings.getString(Constants.PREFERENCE_PASSWORD, null);
    mAsyncHttpClient.setBasicAuth(openHABUsername, openHABPassword, true);
    mAsyncHttpClient.setTimeout(30000);
    if (!isDeveloper)
        Util.initCrittercism(getApplicationContext(), "5117659f59e1bd4ba9000004");
    Util.setActivityTheme(this);
    super.onCreate(savedInstanceState);
    if (!isDeveloper)
        ((HABDroid) getApplication()).getTracker(HABDroid.TrackerName.APP_TRACKER);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.openhab_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // ProgressBar layout params inside the toolbar have to be done programmatically
    // because it doesn't work through layout file :-(
    mProgressBar = (SwipeRefreshLayout) findViewById(R.id.toolbar_progress_bar);
    mProgressBar.setColorSchemeColors(getResources().getColor(R.color.theme_accent));
    mProgressBar.setEnabled(false);
    mProgressBar.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mProgressBar.setRefreshing(false);
        }
    });
    //        mProgressBar.setLayoutParams(new Toolbar.LayoutParams(Gravity.RIGHT));
    startProgressIndicator();
    gcmRegisterBackground();
    // Enable app icon in action bar work as 'home'
    //        this.getActionBar().setHomeButtonEnabled(true);
    pager = (OpenHABViewPager) findViewById(R.id.pager);
    pager.setScrollDurationFactor(2.5);
    pager.setOffscreenPageLimit(1);
    pagerAdapter = new OpenHABFragmentPagerAdapter(getSupportFragmentManager());
    pagerAdapter.setColumnsNumber(getResources().getInteger(R.integer.pager_columns));
    pagerAdapter.setOpenHABUsername(openHABUsername);
    pagerAdapter.setOpenHABPassword(openHABPassword);
    pager.setAdapter(pagerAdapter);
    pager.setOnPageChangeListener(pagerAdapter);
    MemorizingTrustManager.setResponder(this);
    //        pager.setPageMargin(1);
    //        pager.setPageMarginDrawable(android.R.color.darker_gray);
    // Check if we have openHAB page url in saved instance state?
    if (savedInstanceState != null) {
        openHABBaseUrl = savedInstanceState.getString("openHABBaseUrl");
        sitemapRootUrl = savedInstanceState.getString("sitemapRootUrl");
        mStartedWithNetworkConnectivityInfo = savedInstanceState
                .getParcelable("startedWithNetworkConnectivityInfo");
        mOpenHABVersion = savedInstanceState.getInt("openHABVersion");
        mSitemapList = savedInstanceState.getParcelableArrayList("sitemapList");
    }
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name,
            R.string.app_name) {
        public void onDrawerClosed(View view) {
            Log.d(TAG, "onDrawerClosed");
            getSupportActionBar().setTitle(pagerAdapter.getPageTitle(pager.getCurrentItem()));
        }

        public void onDrawerOpened(View drawerView) {
            Log.d(TAG, "onDrawerOpened");
            getSupportActionBar().setTitle("Makerthings");
            loadSitemapList(OpenHABMainActivity.this.openHABBaseUrl);
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    if (mSitemapList == null)
        mSitemapList = new ArrayList<OpenHABSitemap>();
    mDrawerItemList = new ArrayList<OpenHABDrawerItem>();
    mDrawerAdapter = new OpenHABDrawerAdapter(this, R.layout.openhabdrawer_sitemap_item, mDrawerItemList);
    mDrawerAdapter.setOpenHABUsername(openHABUsername);
    mDrawerAdapter.setOpenHABPassword(openHABPassword);
    mDrawerList.setAdapter(mDrawerAdapter);
    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
            Log.d(TAG, "Drawer selected item " + String.valueOf(item));
            if (mDrawerItemList != null && mDrawerItemList.get(item)
                    .getItemType() == OpenHABDrawerItem.DrawerItemType.SITEMAP_ITEM) {
                Log.d(TAG, "This is sitemap " + mDrawerItemList.get(item).getSiteMap().getLink());
                mDrawerLayout.closeDrawers();
                openSitemap(mDrawerItemList.get(item).getSiteMap().getHomepageLink());
            } else {
                Log.d(TAG, "This is not sitemap");
                if (mDrawerItemList.get(item).getTag() == DRAWER_NOTIFICATIONS) {
                    Log.d(TAG, "Notifications selected");
                    mDrawerLayout.closeDrawers();
                    OpenHABMainActivity.this.openNotifications();
                } else if (mDrawerItemList.get(item).getTag() == DRAWER_BINDINGS) {
                    Log.d(TAG, "Bindings selected");
                    mDrawerLayout.closeDrawers();
                    OpenHABMainActivity.this.openBindings();
                } else if (mDrawerItemList.get(item).getTag() == DRAWER_INBOX) {
                    Log.d(TAG, "Inbox selected");
                    mDrawerLayout.closeDrawers();
                    OpenHABMainActivity.this.openDiscoveryInbox();
                }
            }
        }
    });
    loadDrawerItems();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    if (getIntent() != null) {
        Log.d(TAG, "Intent != null");
        if (getIntent().getAction() != null) {
            Log.d(TAG, "Intent action = " + getIntent().getAction());
            if (getIntent().getAction().equals("android.nfc.action.NDEF_DISCOVERED")) {
                Log.d(TAG, "This is NFC action");
                if (getIntent().getDataString() != null) {
                    Log.d(TAG, "NFC data = " + getIntent().getDataString());
                    mNfcData = getIntent().getDataString();
                }
            } else if (getIntent().getAction().equals("org.openhab.notification.selected")) {
                onNotificationSelected(getIntent());
            } else if (getIntent().getAction().equals("android.intent.action.VIEW")) {
                Log.d(TAG, "This is URL Action");
                String URL = getIntent().getDataString();
                mNfcData = URL;
            }
        }
    }

    /**
     * If we are 4.4 we can use fullscreen mode and Daydream features
     */
    supportsKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    boolean fullScreen = mSettings.getBoolean("default_openhab_fullscreen", false);

    if (supportsKitKat && fullScreen) {
        registerReceiver(dreamReceiver, new IntentFilter("android.intent.action.DREAMING_STARTED"));
        registerReceiver(dreamReceiver, new IntentFilter("android.intent.action.DREAMING_STOPPED"));
        checkFullscreen();
    }
}

From source file:com.arctech.stikyhive.ChattingActivity.java

@Override
protected void onResume() {
    super.onResume();
    // txtUserName = (TextView) findViewById(R.id.txtChatName);
    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(QuickstartPreferences.CHAT_REGISTRATION_COMPLETE));
    // txtUserName.invalidate();
}

From source file:com.appolis.move.AcMoveDetails.java

/**
 * Register Receiver/* ww  w. j av  a2 s . c  o m*/
 */
public void onRegisterReceiver() {
    // register to receive notifications from SingleEntryApplication
    // these notifications originate from ScanAPI 
    IntentFilter filter;

    filter = new IntentFilter(SingleEntryApplication.NOTIFY_SCANNER_ARRIVAL);
    registerReceiver(this._newItemsReceiver, filter);

    filter = new IntentFilter(SingleEntryApplication.NOTIFY_SCANNER_REMOVAL);
    registerReceiver(this._newItemsReceiver, filter);

    filter = new IntentFilter(SingleEntryApplication.NOTIFY_DECODED_DATA);
    registerReceiver(this._newItemsReceiver, filter);

    // increasing the Application View count from 0 to 1 will
    // cause the application to open and initialize ScanAPI
    SingleEntryApplication.getApplicationInstance().increaseViewCount();
}

From source file:com.ubuntuone.android.files.service.UpDownService.java

private void registerConnectivityReceiver(BroadcastReceiver receiver) {
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    getApplicationContext().registerReceiver(receiver, filter);
}

From source file:com.ccxt.whl.activity.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???/*from w  ww .  j a  va 2 s.  co  m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        UserDao userdao = new UserDao(this);
        User user = userdao.getUser(toChatUsername);
        //nickname = getIntent().getStringExtra("nickname");
        //headurl =  getIntent().getStringExtra("headurl");
        ((TextView) findViewById(R.id.name)).setText(user.getNick());
    } else if (chatType == 0) { // ? 
        toChatUsername = getIntent().getStringExtra("userId");
        ((TextView) findViewById(R.id.name)).setText("?");
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        ((TextView) findViewById(R.id.name)).setText(group.getGroupName());
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnsetMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            expressionContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    // ?
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,??chat??????
    intentFilter.setPriority(5);
    registerReceiver(receiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ????T
    groupListener = new GroupListener();
    EMGroupManager.getInstance().addGroupChangeListener(groupListener);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // ?????
        forwardMessage(forward_msg_id);
    }

}

From source file:net.kidlogger.kidlogger.KLService.java

public void setupLogging() {
    // Set up GPS / Network logging      
    if (Settings.loggingGps(this)) {
        startGpsUpdates();//  w w  w.  jav a  2s.c  o m
        gpsOn = true;
    }

    // Set up WiFi logging
    if (Settings.loggingWifi(this)) {
        wifiReceiver = new WifiReceiver(this);
        registerReceiver(wifiReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
        wifiOn = true;
    }

    // Set up SMS logging
    if (Settings.loggingSms(this)) {
        smsObserver = new SmsObserver(this, handlering);
        IntentFilter smsFilter = new IntentFilter(SMS_RECEIVED);
        registerReceiver(smsObserver.inSms, smsFilter);
        smsOn = true;
    }

    // Set up Calls logging
    if (Settings.loggingCalls(this)) {
        IntentFilter callsFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED);

        callsReceiver = new CallsReceiver(this);
        registerReceiver(callsReceiver, callsFilter);
        callOn = true;
    }

    // Set up Idle logging
    IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    idleFilter.addAction(Intent.ACTION_USER_PRESENT);

    idleReceiver = new IdleReceiver(this);
    registerReceiver(idleReceiver, idleFilter);
    idleOn = true;
    /*if(Settings.loggingIdle(this)){
       IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
       idleFilter.addAction(Intent.ACTION_USER_PRESENT);
               
       idleReceiver = new IdleReceiver(this);
       registerReceiver(idleReceiver, idleFilter);
       idleOn = true;
    }*/

    // Set up URL logging
    if (Settings.loggingUrl(this)) {
        urlObserver = new HistoryObserver(this, handlering);
        urlOn = true;
    }

    // Set up USB logging
    if (Settings.loggingUsb(this)) {
        IntentFilter usbFilter = new IntentFilter(Intent.ACTION_UMS_CONNECTED);
        usbFilter.addAction(Intent.ACTION_UMS_DISCONNECTED);

        usbReceiver = new UsbReceiver(this);
        registerReceiver(usbReceiver, usbFilter);
        usbOn = true;
    }

    // Set up Tasks logging
    if (logTask) {
        // Check if a new Application was started
        taskScan = new Runnable() {
            public void run() {
                new Thread(new Runnable() {
                    public void run() {
                        doScanTask();
                    }
                }).start();
                if (userPresent) {
                    handleTask.postDelayed(this, SCAN_TASK_TIME);
                    scanningTask = true;
                } else {
                    scanningTask = false;
                }
            }
        };
        handleTask.postDelayed(taskScan, SCAN_TASK_TIME);
        taskOn = true;
    }

    // Set up Clipboard logging
    if (logClip) {
        // Scan clipboard content, only first 30 characters
        clipboardScan = new Runnable() {
            public void run() {
                new Thread(new Runnable() {
                    public void run() {
                        doScanClipboard();
                    }
                }).start();
                if (userPresent) {
                    handleClipb.postDelayed(this, SCAN_CLIP_TIME);
                    scanningClip = true;
                } else {
                    scanningClip = false;
                }
            }
        };
        handleClipb.postDelayed(clipboardScan, SCAN_CLIP_TIME);
        clipOn = true;
    }

    // Set up Power logging
    if (Settings.loggingPower(this)) {
        IntentFilter powerFilter = new IntentFilter(Intent.ACTION_SHUTDOWN);

        powerReceiver = new ShutdownReceiver(this);
        registerReceiver(powerReceiver, powerFilter);
        powerOn = true;
    }

    // Set up Memory Card logging
    if (Settings.loggingMedia(this)) {
        IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_REMOVED);
        mediaFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
        mediaFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        mediaFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
        mediaFilter.addAction(Intent.ACTION_MEDIA_SHARED);
        mediaFilter.addDataScheme("file");

        mediaReceiver = new MediaReceiver(this);
        registerReceiver(mediaReceiver, mediaFilter);

        mediaOn = true;
    }

    // Set up GSM logging
    if (Settings.loggingGsm(this)) {
        gsmObserver = new GsmObserver(this);
        telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        telManager.listen(gsmObserver,
                PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_CELL_LOCATION);
        gsmOn = true;
    }

    // Set up Airplane mode receiver
    if (Settings.loggingAir(this)) {
        IntentFilter airFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);

        airReceiver = new AirplaneReceiver(this);
        registerReceiver(airReceiver, airFilter);
        airOn = true;
    }

    // Set up Photos logging
    if (Settings.loggingPhotos(this)) {
        photoObserver = new PhotoObserver(this, this, handlering);
        photoOn = true;
    }

    // Set up SliceMultimediaFile
    if (Settings.uploadPhotos(this) || Settings.uploadRecords(this)) {
        mediaSlicer = new SliceMultimediaFile(this);
    }

    // Set up ConnectivityReceiver
    mConReceiver = new ConnectivityReceiver(this);
    registerReceiver(mConReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    // Ser up CallIntentReceiver
    //outCallReceiver = new CallIntentReceiver();
    //registerReceiver(outCallReceiver, new IntentFilter(KLService.OUTGOING_CALL));
}