List of usage examples for android.content IntentFilter IntentFilter
public IntentFilter(Parcel source)
From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java
@Override protected void onResume() { super.onResume(); mBackPressExitCount = 0;/*w ww.j av a2 s. c o m*/ if (DEBUG) { registerReceiver(MPDConnectionHandler.getInstance(), new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); } }
From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java
private void checkLowStorageAlert() { final Intent stickyIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW)); if (stickyIntent != null) showDialog(DIALOG_LOW_STORAGE_ALERT); }
From source file:com.piusvelte.taplock.client.core.TapLockSettings.java
@Override protected void onListItemClick(ListView list, final View view, int position, final long id) { super.onListItemClick(list, view, position, id); mDialog = new AlertDialog.Builder(TapLockSettings.this) .setItems(R.array.actions_entries, new DialogInterface.OnClickListener() { @Override/*w w w.j a v a2 s .c o m*/ public void onClick(DialogInterface dialog, int which) { String action = getResources().getStringArray(R.array.actions_values)[which]; int deviceIdx = (int) id; JSONObject deviceJObj = mDevices.get(deviceIdx); dialog.cancel(); if (ACTION_UNLOCK.equals(action) || ACTION_LOCK.equals(action) || ACTION_TOGGLE.equals(action)) { String name = "uknown"; try { name = deviceJObj.getString(KEY_NAME); } catch (JSONException e) { e.printStackTrace(); } startActivity(TapLock.getPackageIntent(getApplicationContext(), TapLockToggle.class) .setAction(action).putExtra(EXTRA_DEVICE_NAME, name)); } else if (ACTION_TAG.equals(action)) { // write the device to a tag mInWriteMode = true; try { mNfcAdapter.enableForegroundDispatch(TapLockSettings.this, PendingIntent.getActivity(TapLockSettings.this, 0, new Intent(TapLockSettings.this, TapLockSettings.this.getClass()) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP).putExtra( EXTRA_DEVICE_NAME, deviceJObj.getString(KEY_NAME)), 0), new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED) }, null); } catch (JSONException e) { Log.e(TAG, e.getMessage()); } Toast.makeText(TapLockSettings.this, "Touch tag", Toast.LENGTH_LONG).show(); } else if (ACTION_REMOVE.equals(action)) { mDevices.remove(deviceIdx); storeDevices(); } else if (ACTION_PASSPHRASE.equals(action)) setPassphrase(deviceIdx); else if (ACTION_COPY_DEVICE_URI.equals(action)) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip; try { clip = ClipData.newPlainText(getString(R.string.app_name), String .format(getString(R.string.device_uri), deviceJObj.get(EXTRA_DEVICE_NAME))); clipboard.setPrimaryClip(clip); Toast.makeText(TapLockSettings.this, "copied to clipboard!", Toast.LENGTH_SHORT) .show(); } catch (JSONException e) { Log.e(TAG, e.getMessage()); Toast.makeText(TapLockSettings.this, getString(R.string.msg_oops), Toast.LENGTH_SHORT).show(); } } } }).create(); mDialog.show(); }
From source file:in.codehex.arrow.MainActivity.java
/** * Get the battery status of the device/*from w ww.jav a2s .com*/ * * @return the battery level of the device */ private float getBatteryLevel() { Intent batteryIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int level = -1, scale = -1; if (batteryIntent != null) { level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); } // Error checking that probably isn't needed but I added just in case. if (level == -1 || scale == -1) { return 50.0f; } return ((float) level / (float) scale) * 100.0f; }
From source file:edu.mit.viral.shen.DroidFish.java
@Override protected void onResume() { System.out.println("on resume"); lastVisibleMillis = 0;/*from w ww .j a v a 2s. c om*/ if (ctrl != null) { ctrl.setGuiPaused(false); if (ctrl.getState() == DroidChessController.GAME_STATE_PLAYING | ctrl.getState() == DroidChessController.EDIT_STATE_COMPLETED) { ctrl.resume(); } } notificationActive = true; updateNotification(); setWakeLock(useWakeLock); registerReceiver(receiver, new IntentFilter(UServer.NOTIFICATION)); super.onResume(); }
From source file:com.zertinteractive.wallpaper.MainActivity.java
public void initDownloadComponents() { BroadcastReceiver receiver = new BroadcastReceiver() { @Override/*from w w w .ja v a 2s .c o m*/ public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { // } } }; registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); unregisterReceiver(receiver); }
From source file:com.ieeton.agency.activity.ChatActivity.java
private void setUpView() { activityInstance = this; Intent intent = getIntent();//w ww . j a v a2 s. c o m if (intent == null) { return; } mChatUser = (ChatUser) intent.getExtras().getSerializable(EXTRA_USERINFO); 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"); // ??? chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE); if (chatType == CHATTYPE_SINGLE) { // ?? toChatUsername = intent.getStringExtra(EXTRA_USERID); String nick = ""; if (mChatUser != null) { nick = mChatUser.getName(); } else if (!TextUtils.isEmpty(Utils.getNickCache(this, toChatUsername))) { nick = Utils.getNickCache(this, toChatUsername); } else { nick = getString(R.string.default_nick); } if (toChatUsername.equals(NetEngine.getFeedbackId())) { mTitleName.setText(getString(R.string.xiaomishu)); } else { mTitleName.setText(nick); } } else { // ? findViewById(R.id.container_to_group).setVisibility(View.VISIBLE); findViewById(R.id.container_remove).setVisibility(View.GONE); findViewById(R.id.container_voice_call).setVisibility(View.GONE); toChatUsername = getIntent().getStringExtra("groupId"); group = EMGroupManager.getInstance().getGroup(toChatUsername); mTitleName.setText(group.getGroupName()); } if (mChatUser == null) { new FetchInfoTask().execute(MODE_HUANXIN); } else { if (ChatUser.USER_DOCTOR.equals(mChatUser.getType())) { new FetchInfoTask().execute(MODE_DOCTOR); } else if (ChatUser.USER_PATIENT.equals(mChatUser.getType())) { new FetchInfoTask().execute(MODE_PATIENT); } } if (toChatUsername.equals(NetEngine.getFeedbackId())) { mBtnCall.setVisibility(View.VISIBLE); } conversation = EMChatManager.getInstance().getConversation(toChatUsername); // ?0 conversation.resetUnsetMsgCount(); adapter = new MessageAdapter(this, toChatUsername, chatType, new MessageAdapter.HeaderClickListener() { @Override public void click(int id) { if (id == CLICK_LEFT) { if (mUser == null) { return; } //? if (mUser.getUserType() == UserInfo.ACCOUNT_DOCTOR) { return; } Intent intent = new Intent(ChatActivity.this, PatientProfileActivity.class); intent.putExtra(PatientProfileActivity.EXTRA_USERID, toChatUsername); startActivity(intent); } else { Intent intent = new Intent(ChatActivity.this, MainActivity.class); intent.putExtra(MainActivity.INPUT_INDEX, MainActivity.INPUT_SETTING); startActivity(intent); } } }); // ? 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; } }); if (toChatUsername.equals(NetEngine.getFeedbackId()) && conversation.getMsgCount() <= 0) { //??? boolean notificationOn = EMChatManager.getInstance().getChatOptions().getNotificationEnable(); boolean soundOn = EMChatManager.getInstance().getChatOptions().getNoticedBySound(); boolean vibrateOn = EMChatManager.getInstance().getChatOptions().getNoticedByVibrate(); if (notificationOn && soundOn) { mSoundID = initSoundPool(); mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { playSound(); } }); } if (notificationOn && vibrateOn) { mVibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); playVibrator(); } EMMessage message = EMMessage.createSendMessage(EMMessage.Type.TXT); String msgID = message.getMsgId(); message.setMsgId("ieeton" + msgID); String content = getString(R.string.mishu_begin_conversation); TextMessageBody txtBody = new TextMessageBody(content); message.addBody(txtBody); message.setFrom(toChatUsername); message.setTo(DemoApplication.getInstance().getUserName()); message.direct = EMMessage.Direct.RECEIVE; conversation.addMessage(message); EMChatManager.getInstance().saveMessage(message); adapter.refresh(); } // ? 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); // ??BroadcastReceiver IntentFilter deliveryAckMessageIntentFilter = new IntentFilter( EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction()); deliveryAckMessageIntentFilter.setPriority(5); registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter); // ????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:com.dwdesign.tweetings.service.TweetingsService.java
@Override public void onCreate() { super.onCreate(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mAsyncTaskManager = ((TweetingsApplication) getApplication()).getAsyncTaskManager(); mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); mResolver = getContentResolver();//from w ww . j a v a 2 s . c om mPendingRefreshHomeTimelineIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_HOME_TIMELINE), 0); mPendingRefreshMentionsIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_MENTIONS), 0); mPendingRefreshDirectMessagesIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_DIRECT_MESSAGES), 0); final IntentFilter filter = new IntentFilter(BROADCAST_REFRESHSTATE_CHANGED); filter.addAction(BROADCAST_NOTIFICATION_CLEARED); filter.addAction(BROADCAST_REFRESH_HOME_TIMELINE); filter.addAction(BROADCAST_REFRESH_MENTIONS); filter.addAction(BROADCAST_REFRESH_DIRECT_MESSAGES); filter.addAction(Intent.ACTION_BATTERY_LOW); filter.addAction(Intent.ACTION_BATTERY_OKAY); registerReceiver(mStateReceiver, filter); startAutoRefresh(); }
From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java
private void registerAudioManagerReceiver() { IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY); audioManagerReceiver = new BroadcastReceiver() { @Override/*from w ww. j av a2s.co m*/ public void onReceive(Context context, Intent intent) { if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) { // Pause playback pause(); } } }; registerReceiver(audioManagerReceiver, filter); }
From source file:com.wojtechnology.sunami.TheBrain.java
private void registerAudio() { if (mHasAudioFocus || !mIsInit) { return;/*from w w w . j a va 2 s . c o m*/ } mHasAudioFocus = true; // Add audio focus change listener mAFChangeListener = new AudioManager.OnAudioFocusChangeListener() { public void onAudioFocusChange(int focusChange) { if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) { pausePlayback(); setUI(false); } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { // Does nothing cause made me play music at work } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) { pausePlayback(); unregisterAudio(); setUI(false); } } }; mAudioManager.requestAudioFocus(mAFChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); // Add headphone out listener registerReceiver(mNoisyAudioStreamReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY)); // Add notification and transport controls ComponentName eventReceiver = new ComponentName(getPackageName(), RemoteControlEventReceiver.class.getName()); mSession = new MediaSessionCompat(this, "FireSession", eventReceiver, null); mSession.setFlags( MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS); mSession.setPlaybackToLocal(AudioManager.STREAM_MUSIC); mSession.setMetadata(new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_TITLE, "") .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, "") .putLong(MediaMetadata.METADATA_KEY_DURATION, -1).build()); mSession.setCallback(new MediaSessionCompat.Callback() { @Override public void onSeekTo(long pos) { super.onSeekTo(pos); setProgress((int) pos, isPlaying()); } }); mSession.setActive(true); }