List of usage examples for android.content IntentFilter IntentFilter
public IntentFilter(Parcel source)
From source file:com.ubuntuone.android.files.service.UpDownService.java
private void registerChargingReceiver(BroadcastReceiver receiver) { IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); getApplicationContext().registerReceiver(receiver, filter); }
From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java
private void monitorBatteryState() { battReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { StringBuilder sb = new StringBuilder(); int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); // charge level from 0 to scale inclusive int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); // Max value for charge level int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, -1); boolean present = intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); //0 if the device is not plugged in; 1 if plugged into an AC power adapter; 2 if plugged in via USB. // int voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1); // voltage in millivolts nBatteryTemp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1); // current battery temperature in tenths of a degree Centigrade // String technology = intent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY); nChargeLevel = -1; // percentage, or -1 for unknown if (rawlevel >= 0 && scale > 0) { nChargeLevel = (rawlevel * 100) / scale; }// w w w . j a va 2 s . c om if (plugged > 0) sACStatus = "ONLINE"; else sACStatus = "OFFLINE"; if (present == false) sb.append("NO BATTERY"); else { if (nChargeLevel < 10) sb.append("Critical"); else if (nChargeLevel < 33) sb.append("LOW"); else if (nChargeLevel > 80) sb.append("HIGH"); } if (BatteryManager.BATTERY_HEALTH_OVERHEAT == health) { sb.append("Overheated "); sb.append((((float) (nBatteryTemp)) / 10)); sb.append("(C)"); } else { switch (status) { case BatteryManager.BATTERY_STATUS_UNKNOWN: // old emulator; maybe also when plugged in with no battery if (present == true) sb.append(" UNKNOWN"); break; case BatteryManager.BATTERY_STATUS_CHARGING: sb.append(" CHARGING"); break; case BatteryManager.BATTERY_STATUS_DISCHARGING: sb.append(" DISCHARGING"); break; case BatteryManager.BATTERY_STATUS_NOT_CHARGING: sb.append(" NOTCHARGING"); break; case BatteryManager.BATTERY_STATUS_FULL: sb.append(" FULL"); break; default: if (present == true) sb.append("Unknown"); break; } } sPowerStatus = sb.toString(); } }; IntentFilter battFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); registerReceiver(battReceiver, battFilter); }
From source file:org.universAAL.android.proxies.ServiceCalleeProxy.java
/** * This is an auxiliary method that invokes this proxy when a service * request matched in the R API server, and the ServiceCall was sent here * through GCM. We receive a ServiceCall not a BusMessage nor a * ServiceRequest. It sends the response back to the R API rather than * through the inner bus./* w w w. ja va 2 s . c om*/ * * @param scall * The ServiceCall as received from R API through GCM. * @param origincall * The original ServiceCall URI as specified by the server. It is * not the same as scall.getURI() since that object is created * here in the client. */ public void handleCallFromGCM(ServiceCall scall, String origincall) { Boolean needsOuts = (Boolean) scall.getNonSemanticInput(AppConstants.UAAL_META_PROP_NEEDSOUTPUTS); Context ctxt = contextRef.get(); if (ctxt != null) { // Prepare an intent for sending to Android grounded service Intent serv = new Intent(action); serv.addCategory(category); boolean expecting = false; // If a response is expected, prepare a callback receiver (which must be called by uaalized app) if ((replyAction != null && !replyAction.isEmpty()) && (replyCategory != null && !replyCategory.isEmpty())) { // Tell the destination where to send the reply serv.putExtra(AppConstants.ACTION_META_REPLYTOACT, replyAction); serv.putExtra(AppConstants.ACTION_META_REPLYTOCAT, replyCategory); // Register the receiver for the reply receiver = new ServiceCalleeProxyReceiverGCM(origincall); IntentFilter filter = new IntentFilter(replyAction); filter.addCategory(replyCategory); ctxt.registerReceiver(receiver, filter); expecting = true; } else if (needsOuts != null && needsOuts.booleanValue()) { // No reply* fields set, but caller still needs a response, lets // build one (does not work for callers outside android MW) Random r = new Random(); String action = AppConstants.ACTION_REPLY + r.nextInt(); serv.putExtra(AppConstants.ACTION_META_REPLYTOACT, action); serv.putExtra(AppConstants.ACTION_META_REPLYTOCAT, Intent.CATEGORY_DEFAULT); // Register the receiver for the reply receiver = new ServiceCalleeProxyReceiverGCM(origincall); IntentFilter filter = new IntentFilter(action); filter.addCategory(Intent.CATEGORY_DEFAULT); ctxt.registerReceiver(receiver, filter); expecting = true; } // Take the inputs from the call and put them in the intent if (inputURItoExtraKEY != null && !inputURItoExtraKEY.isEmpty()) { VariableSubstitution.putCallInputsAsIntentExtras(scall, serv, inputURItoExtraKEY); } // Flag to avoid feeding back the intent to bus when intent is the same in app and in callerproxy serv.putExtra(AppConstants.ACTION_META_FROMPROXY, true); // Send the intent to Android grounded service ComponentName started = null; try { // HACK: In android 5.0 it is forbidden to send implicit service intents like this one started = ctxt.startService(serv); } catch (Exception e) { // Therefore if it fails, fail silently and try again with broadcast receivers started = null; } if (started == null) { // No android service was there, try with broadcast. Before, here it used to send failure response ctxt.sendBroadcast(serv); // No way to know if received. If no response, bus will timeout (?) } else if (!expecting) { // There is no receiver waiting a response, send success now ServiceResponse resp = new ServiceResponse(CallStatus.succeeded); sendResponseGCM(resp, origincall); } //TODO Handle timeout } }
From source file:com.ieeton.user.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"); String name = Utils.getNickCache(this, toChatUsername); if (TextUtils.isEmpty(name)) { if (mUser != null) { name = mUser.getName();/* w ww . j a v a 2s. co m*/ } else { name = getResources().getString(R.string.default_doctor_nickname); } } if (toChatUsername.equals(NetEngine.getSecretaryID())) { mTvTitle.setText(R.string.secretary_default_name); } else { mTvTitle.setText(name); } conversation = EMChatManager.getInstance().getConversation(toChatUsername); // ?0 conversation.resetUnsetMsgCount(); adapter = new MessageAdapter(this, toChatUsername, new MessageAdapter.HeaderClickListener() { @Override public void click(int id) { if (id == MessageAdapter.HeaderClickListener.CLICK_LEFT) { if (mUser != null) { if (mUser.getUserType() == 1 || mUser.getUserType() == 2 || mUser.getUserType() == 3) { Intent intent = new Intent(ChatActivity.this, DoctorProfileActivity.class); intent.putExtra(Constants.EXTRA_USER, mUser); intent.putExtra(Constants.EXTRA_UID, mUser.getUid()); startActivity(intent); } } } else if (id == MessageAdapter.HeaderClickListener.CLICK_RIGHT) { 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); emojiIconContainer.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); // ??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:cgeo.geocaching.CacheDetailActivity.java
@Override public void onStart() { super.onStart(); LocalBroadcastManager.getInstance(this).registerReceiver(updateReceiver, new IntentFilter(Intents.INTENT_CACHE_CHANGED)); }
From source file:de.lespace.apprtc.activity.ConnectActivity.java
private void registerNetworkChangeReceiver() { if (!isNetworkChangeReceiverRegistered) { LocalBroadcastManager.getInstance(this).registerReceiver(networkchangeBroadcastReceiver, new IntentFilter(QuickstartPreferences.NETWORK_ONLINE)); isNetworkChangeReceiverRegistered = true; }//w ww . ja v a 2 s . c o m }
From source file:com.hhunj.hhudata.ForegroundService.java
private void sendSMS(String message) { if (message == "") return;/*from w w w.ja v a 2s. com*/ //String stext = " " +m_contactmap.size(); //notification ,title showNotification("hhudata", message); if (m_alarmInWorktime) {// Date dt = new Date(); if (IsDuringWorkHours(dt) == false) { return; } else { //alarm. } } if (message.length() > 140) { //.... return; } // ---sends an SMS message to another device--- SmsManager sms = SmsManager.getDefault(); String SENT_SMS_ACTION = "SENT_SMS_ACTION"; String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION"; // create the sentIntent parameter Intent sentIntent = new Intent(SENT_SMS_ACTION); PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0); // create the deilverIntent parameter Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION); PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0); // register the Broadcast Receivers registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context _context, Intent _intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent success actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "SMS generic failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "SMS radio off failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "SMS null PDU failure actions", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(SENT_SMS_ACTION)); registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context _context, Intent _intent) { Toast.makeText(getBaseContext(), "SMS delivered actions", Toast.LENGTH_SHORT).show(); } }, new IntentFilter(DELIVERED_SMS_ACTION)); // if message's length more than 70 , // then call divideMessage to dive message into several part ,and call // sendTextMessage() // else direct call sendTextMessage() Iterator it = m_contactmap.keySet().iterator(); while (it.hasNext()) { ContactColumn.ContactInfo info = m_contactmap.get(it.next()); if (info.mobile == null) continue; String mobile = info.mobile.trim(); if (mobile.length() >= 4) { if (message.length() > 70) { ArrayList<String> msgs = sms.divideMessage(message); for (String msg : msgs) { sms.sendTextMessage(mobile, null, msg, sentPI, deliverPI); } } else { sms.sendTextMessage(mobile, null, message, sentPI, deliverPI); } } } }
From source file:com.amazonaws.mobileconnectors.cognito.DefaultDataset.java
@Override public void synchronizeOnConnectivity(SyncCallback callback) { if (isNetworkAvailable(context)) { synchronize(callback);//from w ww . j a v a 2s.c o m } else { discardPendingSyncRequest(); LOGGER.debug( "Connectivity is unavailable. " + "Scheduling synchronize for when connectivity is resumed."); pendingSyncRequest = new SyncOnConnectivity(this, callback); // listen to only connectivity change context.registerReceiver(pendingSyncRequest, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } }
From source file:com.halseyburgund.rwframework.core.RWService.java
@Override public void onCreate() { super.onCreate(); // create default configuration and tags configuration = new RWConfiguration(this); tags = new RWTags(); // get default server url from resources and reset other critical vars mServerUrl = getString(R.string.rw_spec_server_url); mStreamUrl = null;/*from w ww . j av a 2 s .c o m*/ // create a factory for actions mActionFactory = new RWActionFactory(this); // create a queue for actions RWActionQueue.instance().init(this); // listen to connectivity state broadcasts registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); // listen to own server calls success and failure broadcasts IntentFilter filter = createOperationsIntentFilter(); filter.addAction(RW.CONFIGURATION_LOADED); filter.addAction(RW.NO_CONFIGURATION); registerReceiver(rwReceiver, filter); // setup for GPS callback RWLocationTracker.instance().init(this); RWLocationTracker.instance().addObserver(this); // setup a tracker for assets streamed by the server mAssetTracker = new RWStreamAssetsTracker(this); }
From source file:com.fullteem.yueba.app.ui.ChatActivity.java
private void setUpView() { // popwindow/* ww w. j av a2s.c om*/ menuTexts = getResources().getStringArray(R.array.msgmenu); 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"); // ??? chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE); if (chatType == CHATTYPE_SINGLE) { // ?? // ?? Map<String, User> users = appContext.getContactList(); toChatUsername = getIntent().getStringExtra("userId");// bug bill.// should be// imServerId if (null == toChatUsername) { return; } userNickName = getIntent().getStringExtra("nickname"); getUserTokenByAccount(toChatUsername); ImageUrl = getIntent().getStringExtra("imgurl"); List<String> blackList = EMContactManager.getInstance().getBlackListUsernames(); for (String key : users.keySet()) { // ?????? if (null != toChatUsername && toChatUsername.equalsIgnoreCase(key)// debug to be // null! && !blackList.contains(key)) { menuTexts = getResources().getStringArray(R.array.msgmenu_friend); } } ((TextView) findViewById(R.id.name)).setText(userNickName); // conversation = // EMChatManager.getInstance().getConversation(toChatUsername,false); } 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"); System.out.println("toChatUsername" + toChatUsername); group = EMGroupManager.getInstance().getGroup(toChatUsername); menuTexts = getResources().getStringArray(R.array.msgmenu_group); if (group == null) { ((TextView) findViewById(R.id.name)).setText(""); } else { ((TextView) findViewById(R.id.name)).setText(group.getGroupName()); } // conversation = // EMChatManager.getInstance().getConversation(toChatUsername,true); } conversation = EMChatManager.getInstance().getConversation(toChatUsername); // ?0 conversation.resetUnsetMsgCount(); adapter = new MessageAdapter(this, toChatUsername, ImageUrl, 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); emojiIconContainer.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); // ??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); } }