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.lge.friendsCamera.MainActivity.java

private void initialize() {
    receiver = new WifiReceiver();

    FriendsCameraApplication.setContext(this);

    IntentFilter filter = new IntentFilter();
    filter.addAction(WifiClient.ACTION_WIFI_STATE);
    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(receiver, filter);

    checkFileWritePermission();// w  w  w  . j  a  va 2 s .c o m
    fingerPrint = "";
}

From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java

/**
 * USB???/*from w  w  w . j  ava 2s .  c  o  m*/
 */
private void listenUsbDevice(CallbackContext callbackContext) {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    this.usbCallbackContext = callbackContext;
    if (this.mUsbReceiver == null) {
        this.mUsbReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String handlerName = null;
                String action = intent.getAction();
                if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
                    // plugin result of USB attached
                    handlerName = HANDLER_PREFIX + "." + "attached";
                }
                if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
                    // plugin result of USB detached
                    handlerName = HANDLER_PREFIX + "." + "detached";
                }
                try {
                    String json = "{\"handlerName\":" + handlerName + " }";
                    JSONObject parameter = new JSONObject(json);
                    PluginResult dataResult = new PluginResult(PluginResult.Status.OK, parameter);
                    dataResult.setKeepCallback(true);
                    usbCallbackContext.sendPluginResult(dataResult);
                } catch (JSONException e) {
                    Log.e(POCKETDUINO, "Exception: " + e.getMessage());
                    usbCallbackContext.error(e.toString());
                }
            }
        };
        webView.getContext().registerReceiver(this.mUsbReceiver, intentFilter);
    }
}

From source file:com.dwdesign.tweetings.fragment.HomeTimelineFragment.java

@Override
public void onStart() {
    super.onStart();
    final IntentFilter filter = new IntentFilter(BROADCAST_HOME_TIMELINE_REFRESHED);
    filter.addAction(BROADCAST_ACCOUNT_LIST_DATABASE_UPDATED);
    filter.addAction(BROADCAST_HOME_TIMELINE_DATABASE_UPDATED);
    filter.addAction(BROADCAST_REFRESHSTATE_CHANGED);
    registerReceiver(mStatusReceiver, filter);
    if (mService.isHomeTimelineRefreshing()) {
        setRefreshing(false);//from   w w w .  ja  va 2  s  .c o m
    } else {
        onRefreshComplete();
    }
}

From source file:com.sina.weibo.sdk.demo.openapi.user_homeActivity.java

/**
 * @see {@link Activity#onCreate}//from   w  ww  .j  a  va2s. c  o m
 */

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.weibo_item);
    //mLogoutButton = (Button) findViewById(R.id.logout);

    // ??? Token
    mAccessToken = AccessTokenKeeper.readAccessToken(this);
    // ???
    mUsersAPI = new UsersAPI(this, Constants.APP_KEY, mAccessToken);
    mStatusesAPI = new StatusesAPI(this, Constants.APP_KEY, mAccessToken);
    getUserInfo();

    //
    this.findViewById(R.id.home_page).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(user_homeActivity.this, mytestActivity.class));
        }
    });
    this.findViewById(R.id.send_page).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(user_homeActivity.this, WBStatus_sendAPIActivity.class));
        }
    });
    //
    //
    this.findViewById(R.id.fllowers).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(user_homeActivity.this, user_fllowers.class));
        }
    });
    //?
    this.findViewById(R.id.friends).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(user_homeActivity.this, user_friends.class));
        }
    });
    //
    mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(this, Constants.APP_KEY);
    mWeiboShareAPI.registerApp();
    shearMessageReceiver = new ShearMessageReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_SHEAR_RESULT);
    registerReceiver(shearMessageReceiver, filter);
    this.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mWeiboShareAPI.isWeiboAppInstalled()) {
                Toast.makeText(user_homeActivity.this, "", Toast.LENGTH_LONG).show();
            }
            //
            if (true) {
                Bundle bundle = new Bundle();
                Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_logo);
                bundle.putString(WBConstants.SDK_WEOYOU_SHARETITLE, "share our app to others");
                bundle.putString(WBConstants.SDK_WEOYOU_SHAREDESC, "say something...");
                bundle.putString(WBConstants.SDK_WEOYOU_SHAREURL, "http://github/laterlater.com");
                bundle.putString("shareBackScheme", "weiboDemo://share");
                bundle.putString(SHARE_APP_NAME, "app name");
                bundle.putString(PARAM_SHARE_FROM, EXTEND_SHARE_570);
                bundle.putByteArray(WBConstants.SDK_WEOYOU_SHAREIMAGE, bitMapToBytes(bitmap));
                mWeiboShareAPI.shareMessageToWeiyou(user_homeActivity.this, bundle);
            } else {
                Toast.makeText(user_homeActivity.this, "?", Toast.LENGTH_LONG).show();
            }
        }
    });
    this.findViewById(R.id.logout).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mAccessToken != null && mAccessToken.isSessionValid()) {
                new LogoutAPI(user_homeActivity.this, Constants.APP_KEY, mAccessToken)
                        .logout(mLogoutRequestListener);
            }
        }
    });
}

From source file:com.guoxiaoxing.kitty.ui.MainActivity.java

@Override
public void initView() {

    AppContext.getInstance().setLogin();

    mDoubleClickExit = new DoubleClickExitHelper(this);

    mTitle = getTitle();/*from   w  w w .  j  av  a  2s .com*/

    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
    if (android.os.Build.VERSION.SDK_INT > 10) {
        mTabHost.getTabWidget().setShowDividers(0);
    }

    initTabs();

    // ?
    mAddBt.setOnClickListener(this);

    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(this);

    IntentFilter filter = new IntentFilter(Constants.INTENT_ACTION_NOTICE);
    filter.addAction(Constants.INTENT_ACTION_LOGOUT);
    registerReceiver(mReceiver, filter);
    NoticeUtils.bindToService(this);

    if (AppContext.isFristStart()) {
        //            mNavigationDrawerFragment.openDrawerMenu();
        DataCleanManager.cleanInternalCache(AppContext.getInstance());
        AppContext.setFristStart(false);
    }

    //        checkUpdate();
}

From source file:com.ecoplayer.beta.MainActivity.java

@Override
protected void onCreate(Bundle arg0) {
    Debug.startMethodTracing();//  w ww  . j  a v  a  2s.  com
    super.onCreate(arg0);
    setContentView(R.layout.main);
    // Get sharedPreferences
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    playQueue = PlayQueue.getInstance();
    fragmentManager = getSupportFragmentManager();
    initialEnergySettings = InitialEnergySettings.getInstance();
    short fragmentId = FRAGMENT_ALBUMS;
    // Register broadcast
    IntentFilter intentFilter = new IntentFilter(MusicService.MUSIC_UPDATE);
    intentFilter.addAction(EnergyService.ENERGY_MODE_SET);
    intentFilter.addAction(EnergyService.ENERGY_STATE_GET);
    registerReceiver(broadcastReceiver, intentFilter);
    if (arg0 != null) {
        album = (Album) arg0.getParcelable(EXTRA_ALBUM);
        fragmentId = arg0.getShort(EXTRA_FRAGMENT_ID);
    }
    // Start energy service to save initial energy settings
    if (!AppState.isEnergyStateSaved()) {
        Intent intentEnergyService = new Intent(getApplicationContext(), EnergyService.class);
        intentEnergyService.setAction(EnergyService.ACTION_GET_ENERGY_STATE);
        startService(intentEnergyService);
    }
    // Load a fragment depending on the ID sent in the Intent.
    if (isFragmentIdValid(fragmentId)) {
        switch (fragmentId) {
        case FRAGMENT_ALBUMS:
            addAlbumFragment();
            break;
        case FRAGMENT_SONGS_ALBUM:
            if (album != null) {
                addSongsByAlbumFragment(album);
                break;
            }
            // if null won't break and will load the default one.
        case FRAGMENT_PLAY_QUEUE:
            addPlayQueueFragment();
            break;
        default:
            addAlbumFragment();
        }
    }
}

From source file:com.google.android.apps.iosched.ui.ScheduleFragment.java

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

    // Since we build our views manually instead of using an adapter, we
    // need to manually requery every time launched.
    requery();//  w  ww  .j  ava 2  s .  c o m

    getActivity().getContentResolver().registerContentObserver(ScheduleContract.Sessions.CONTENT_URI, true,
            mSessionChangesObserver);

    // Start listening for time updates to adjust "now" bar. TIME_TICK is
    // triggered once per minute, which is how we move the bar over time.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_TIME_TICK);
    filter.addAction(Intent.ACTION_TIME_CHANGED);
    filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
    getActivity().registerReceiver(mReceiver, filter, null, new Handler());
}

From source file:com.farmerbb.secondscreen.service.NotificationService.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//from  w w w.  j a  v a 2 s . c  om
public void onCreate() {
    // Load preferences
    SharedPreferences prefCurrent = U.getPrefCurrent(this);
    SharedPreferences prefMain = U.getPrefMain(this);

    // Register broadcast receivers for screen on and user present
    final IntentFilter filter1 = new IntentFilter();
    final IntentFilter filter2 = new IntentFilter();

    filter1.addAction(Intent.ACTION_SCREEN_ON);
    filter1.addAction(Intent.ACTION_DREAMING_STARTED);
    filter2.addAction(Intent.ACTION_USER_PRESENT);

    registerReceiver(screenOnReceiver, filter1);
    registerReceiver(userPresentReceiver, filter2);

    DisplayManager manager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    manager.registerDisplayListener(listener, null);

    // Intent to launch MainActivity when notification is clicked
    Intent mainActivityIntent = new Intent(this, MainActivity.class);
    PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(this, 0, mainActivityIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build the notification
    mBuilder = new NotificationCompat.Builder(this).setContentIntent(mainActivityPendingIntent)
            .setSmallIcon(R.drawable.ic_action_dock)
            .setContentTitle(getResources().getString(R.string.notification))
            .setContentText(
                    prefCurrent.getString("profile_name", getResources().getString(R.string.action_new)))
            .setOngoing(true);

    // Set action buttons
    setActionButton(prefMain.getString("notification_action_2", "turn-off"), prefCurrent, 0);
    setActionButton(prefMain.getString("notification_action", "lock-device"), prefCurrent, 1);

    // Respect setting to hide notification
    if (prefMain.getBoolean("hide_notification", false))
        mBuilder.setPriority(Notification.PRIORITY_MIN);

    // Set notification color on Lollipop
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setColor(getResources().getColor(R.color.primary_dark))
                .setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    // Start NotificationService
    startForeground(1, mBuilder.build());

    // Draw system overlay, if needed
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Settings.canDrawOverlays(this)
            && prefCurrent.getString("rotation_lock_new", "fallback").equals("landscape")) {
        windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

        params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

        view = new View(this);
        windowManager.addView(view, params);
    }
}

From source file:com.example.parking.InputLicenseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mDBAdapter = new DBAdapter(this);
    Intent intent = getIntent();// ww w  .j a v a  2 s.c  o m
    Bundle bundle = intent.getExtras();
    if (bundle.getInt("type") == ARRIVING_TYPE) {
        mType = ARRIVING_TYPE;
    } else if (bundle.getInt("type") == LEAVING_TYPE) {
        mType = LEAVING_TYPE;
    }
    setContentView(R.layout.activity_input_license);
    mLicensePlateET = (EditText) findViewById(R.id.et_license_plate);
    mLetterTV = (TextView) findViewById(R.id.tv_letter);
    mNumberTV = (TextView) findViewById(R.id.tv_number);
    mLocationTV = (TextView) findViewById(R.id.tv_location);
    mScanBT = (Button) findViewById(R.id.bt_scan);
    mNextBT = (Button) findViewById(R.id.bt_next);
    mLetterTV.setOnClickListener(mTabClickListener);
    mNumberTV.setOnClickListener(mTabClickListener);
    mLocationTV.setOnClickListener(mTabClickListener);
    changeSelect(R.id.tv_location);
    changeFragment(R.id.tv_location);
    mLicensePlateET.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // et.getCompoundDrawables()4?
            Drawable drawable = mLicensePlateET.getCompoundDrawables()[2];
            //????
            if (drawable == null)
                return false;
            //????
            if (event.getAction() != MotionEvent.ACTION_UP)
                return false;
            if (event.getX() > mLicensePlateET.getWidth() - mLicensePlateET.getPaddingRight()
                    - drawable.getIntrinsicWidth()) {
                mLicensePlateET.setText("");
            }
            return false;
        }
    });
    mScanBT.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            Message msg = new Message();
            msg.what = EVENT_SCAN_STATE_NOTIFY;
            mHandler.sendMessage(msg);
        }
    });
    mLicensePlateET.setInputType(InputType.TYPE_NULL);
    mLicensePlateET.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mLicensePlateET.getText() != null
                    && mLicensePlateET.getText().length() > LICENSE_PLATE_NUMBER_SIZE) {
                Message msg = new Message();
                msg.what = EVENT_INVALID_LICENSE_PLATE;
                mHandler.sendMessage(msg);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
        }
    });
    mNextBT.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            if (mLicensePlateET.getText().length() != LICENSE_PLATE_NUMBER_SIZE) {
                Message msg = new Message();
                msg.what = EVENT_INVALID_LICENSE_PLATE;
                mHandler.sendMessage(msg);
                return;
            }
            new SQLThread().start();
        }
    });
    getActionBar().setDisplayHomeAsUpEnabled(true);
    IntentFilter filter = new IntentFilter();
    filter.addAction("ExitApp");
    filter.addAction("BackMain");
    registerReceiver(mReceiver, filter);
}

From source file:com.anykey.balala.activity.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    receiver = new LocalRouterReceiver(new LocalRouterReceiver.RouterCallback() {
        @Override//from   w  w w.ja  va2 s  .c o m
        public void onHandle(byte[] parcel, Object obj) {
            int type = new WillProtocol().getType(parcel);
            byte[] msgByte = new WillProtocol().getData(parcel);
            String msgStr = new String(msgByte).trim();
            if (type == WillOutProtocol.BROADCAST_TYPE_VALUE) {//??
                SystemNotificationModel.SystemBroadcast commonData = JsonUtil.fromJson(msgStr,
                        SystemNotificationModel.SystemBroadcast.class);
                if (commonData.code == 4) {//??
                    String str = commonData.msg;
                    int VersionCode = Integer.valueOf(str.split("%-%")[0]);
                    String message = String.valueOf(str.split("%-%")[1]);
                    int force = commonData.data.force;
                    String AppURL = commonData.data.url;
                    if (Integer.valueOf(versionCode) < VersionCode) {
                        UploadApp uploadApp = new UploadApp(
                                FileUtil.getSDCardDir(MainActivity.this, AppBalala.FILEPATH_UPAPK));
                        uploadApp.showUpApk(MainActivity.this, message, AppURL, force);
                        if (force == 1) {
                            sp.saveUpLoadApk(true, String.valueOf(VersionCode), message, AppURL);
                        }
                    }
                }
            }
        }
    });
    IntentFilter filter = new IntentFilter();
    filter.addAction(RouterProcess.ACTION_ROUTER_PARCEL);
    LocalBroadcastManager.getInstance(MainActivity.this).registerReceiver(receiver, filter);
    if (!sp.getApkInfo_version().equals("")) {
        int ApkVersion = Integer.valueOf(sp.getApkInfo_version());
        if (ApkVersion > Integer.valueOf(versionCode)) {//?
            UploadApp uploadApp = new UploadApp(
                    FileUtil.getSDCardDir(MainActivity.this, AppBalala.FILEPATH_UPAPK));
            uploadApp.showUpApk(MainActivity.this, sp.getApkInfo_message(), sp.getApkInfo_Url(), 1);
        }
    }
}