List of usage examples for android.content IntentFilter IntentFilter
public IntentFilter(Parcel source)
From source file:com.hhunj.hhudata.SearchBookContentsActivity.java
private void sendSMS(String phoneNumber, String message) { // ---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/*from w ww . j av a 2s . c o m*/ 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() if (message.length() > 70) { ArrayList<String> msgs = sms.divideMessage(message); for (String msg : msgs) { sms.sendTextMessage(phoneNumber, null, msg, sentPI, deliverPI); } } else { sms.sendTextMessage(phoneNumber, null, message, sentPI, deliverPI); } }
From source file:com.heneryh.aquanotes.ui.controllers.ControllersActivity.java
@Override public void onResume() { super.onResume(); IntentFilter intentFilter = new IntentFilter(SyncService.STATUS_UPDATE); registerReceiver(statusIntentReceiver, intentFilter); updateRefreshStatus(false);/* w w w. j a v a2 s . co m*/ /** * Since we build our views manually instead of using an adapter, we * need to manually requery every time launched. */ requery(); }
From source file:org.linphone.LinphoneService.java
@Override public void onCreate() { super.onCreate(); theLinphone = this; // Dump some debugging information to the logs Hacks.dumpDeviceInformation();//w w w.j av a 2 s . com addCallListner(); // tryTogetLastReceive(); // tryTogetLastRequest(); tryKeepOnline(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotification = new Notification(R.drawable.status_level, "", System.currentTimeMillis()); mNotification.iconLevel = IC_LEVEL_ORANGE; mNotification.flags |= Notification.FLAG_ONGOING_EVENT; Intent notificationIntent = new Intent(this, MainViewActivity.class); mNofificationContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE, "", mNofificationContentIntent); mNotificationManager.notify(NOTIFICATION_ID, mNotification); mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mAudioManager = ((AudioManager) getSystemService(Context.AUDIO_SERVICE)); mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); try { copyAssetsFromPackage(); mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore(this, LINPHONE_RC, LINPHONE_FACTORY_RC, null); mLinphoneCore.setPlaybackGain(3); mLinphoneCore.setRing(null); try { initFromConf(); } catch (LinphoneException e) { Log.w(TAG, "no config ready yet"); } TimerTask lTask = new TimerTask() { @Override public void run() { mLinphoneCore.iterate(); } }; mTimer.scheduleAtFixedRate(lTask, 0, 100); IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON); lFilter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(mKeepAliveMgrReceiver, lFilter); } catch (Exception e) { Log.e(TAG, "Cannot start linphone", e); } }
From source file:org.universAAL.android.proxies.ServiceCalleeProxy.java
@Override public void handleRequest(BusMessage m) { ServiceCall call = (ServiceCall) m.getContent(); // Extract the origin action and category from the call String fromAction = (String) call.getNonSemanticInput(AppConstants.UAAL_META_PROP_FROMACTION); String fromCategory = (String) call.getNonSemanticInput(AppConstants.UAAL_META_PROP_FROMCATEGORY); Boolean needsOuts = (Boolean) call.getNonSemanticInput(AppConstants.UAAL_META_PROP_NEEDSOUTPUTS); boolean isNonIntrusive = fromAction != null && fromAction.equals(action) && fromCategory != null && fromCategory.equals(category); // This means the serv Intent in the caller proxy is the same as the // serv Intent in destination native app. Therefore the destination will // already have received it and we must not send the intent to avoid // duplication or infinite loops. if (!isNonIntrusive) { // In this case the serv intents are different because the origin // action+cat is being used as a kind of API to call the SCaller. // In this case we have to relay the call to the destination native app. Context ctxt = contextRef.get(); if (ctxt != null) { // Prepare an intent for sending to Android grounded service Intent serv = new Intent(action); serv.addCategory(category);//from w ww. ja v a 2s . com 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 ServiceCalleeProxyReceiver(m);// TODO Can only handle 1 call at a time per proxy 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 ServiceCalleeProxyReceiver(m); 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(call, 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 = ctxt.startService(serv);//Not allowed in Android 5.0 (fall back to broadcast) 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); sendResponse(m, resp); } //TODO Handle timeout } } }
From source file:com.iss.android.wearable.datalayer.MainActivity.java
private void initializeSWBatteryChecker() { final TextView SWBatteryStatus = (TextView) findViewById(R.id.SWbatteryLabel); final Handler h = new Handler(); final int delay = 20000; //milliseconds final boolean[] warned_evening = { false }; // Timer's fine for Java, but kills android apps. h.postDelayed(new Runnable() { public void run() { IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = registerReceiver(null, ifilter); int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); int batteryPct = (int) (level / (float) scale * 100); SWBatteryStatus.setText("SW: " + batteryPct + "%"); Calendar clnd = Calendar.getInstance(); if (clnd.get(Calendar.HOUR_OF_DAY) >= 20) { if (batteryPct < 75 && !warned_evening[0]) { warned_evening[0] = true; displaySWBatteryWarning(); } else if (batteryPct >= 75 && warned_evening[0]) { warned_evening[0] = false; }/*from w ww. j a v a 2s. co m*/ } h.postDelayed(this, delay); } }, 0); }
From source file:net.sf.asap.PlayerService.java
@Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); registerReceiver(headsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); registerMediaButtonEventReceiver("registerMediaButtonEventReceiver"); TelephonyManager telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); telephony.listen(new PhoneStateListener() { public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) pause();/* w w w. ja v a2s.c o m*/ } }, PhoneStateListener.LISTEN_CALL_STATE); Uri uri = intent.getData(); String playlistUri = intent.getStringExtra(EXTRA_PLAYLIST); if (playlistUri != null) setPlaylist(Uri.parse(playlistUri), false); else if ("file".equals(uri.getScheme())) { if (ASAPInfo.isOurFile(uri.toString())) setPlaylist(Util.getParent(uri), false); else { setPlaylist(uri, true); uri = playlist.get(0); } } playFile(uri, SONG_DEFAULT); }
From source file:com.scoreflex.ScoreflexView.java
/** * The constructor of the view.//from w ww . j a v a 2 s . c om * @param activity The activity holding the view. * @param attrs * @param defStyle */ @SuppressWarnings("deprecation") public ScoreflexView(Activity activity, AttributeSet attrs, int defStyle) { super(activity, attrs, defStyle); // Keep a reference on the activity mParentActivity = activity; // Default layout params if (null == getLayoutParams()) { setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Scoreflex.getDensityIndependantPixel(R.dimen.scoreflex_panel_height))); } // Set our background color setBackgroundColor(getContext().getResources().getColor(R.color.scoreflex_background_color)); // Create the top bar View topBar = new View(getContext()); topBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height), Gravity.TOP)); topBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.scoreflex_gradient_background)); addView(topBar); // Create the retry button LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); mErrorLayout = (ViewGroup) inflater.inflate(R.layout.scoreflex_error_layout, null); if (mErrorLayout != null) { // Configure refresh button Button refreshButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_retry_button); if (null != refreshButton) { refreshButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (null == Scoreflex.getPlayerId()) { setUserInterfaceState(new LoadingState()); loadUrlAfterLoggedIn(mInitialResource, mInitialRequestParams); } else if (null == mWebView.getUrl()) { setResource(mInitialResource); } else { mWebView.reload(); } } }); } // Configure cancel button Button cancelButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_cancel_button); if (null != cancelButton) { cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { close(); } }); } // Get hold of the message view mMessageView = (TextView) mErrorLayout.findViewById(R.id.scoreflex_error_message_view); addView(mErrorLayout); } // Create the close button mCloseButton = new ImageButton(getContext()); Drawable closeButtonDrawable = getResources().getDrawable(R.drawable.scoreflex_close_button); int closeButtonMargin = (int) ((getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height) - closeButtonDrawable.getIntrinsicHeight()) / 2.0f); FrameLayout.LayoutParams closeButtonLayoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT); closeButtonLayoutParams.setMargins(0, closeButtonMargin, closeButtonMargin, 0); mCloseButton.setLayoutParams(closeButtonLayoutParams); mCloseButton.setImageDrawable(closeButtonDrawable); mCloseButton.setBackgroundDrawable(null); mCloseButton.setPadding(0, 0, 0, 0); mCloseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { close(); } }); addView(mCloseButton); // Create the web view mWebView = new WebView(mParentActivity); mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // mWebView.setBackgroundColor(Color.RED); mWebView.setWebViewClient(new ScoreflexWebViewClient()); mWebView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage cm) { Log.d("Scoreflex", "javascript Error: " + String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId())); return true; } public void openFileChooser(ValueCallback<Uri> uploadMsg) { // mtbActivity.mUploadMessage = uploadMsg; mUploadMessage = uploadMsg; String fileName = "picture.jpg"; ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, fileName); // mOutputFileUri = mParentActivity.getContentResolver().insert( // MediaStore.Images.Media.DATA, values); final List<Intent> cameraIntents = new ArrayList<Intent>(); final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = mParentActivity.getPackageManager(); final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(packageName); cameraIntents.add(intent); } // Filesystem. final Intent galleryIntent = new Intent(); galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_GET_CONTENT); // Chooser of filesystem options. final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source please"); // Add the camera options. chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {})); mParentActivity.startActivityForResult(chooserIntent, Scoreflex.FILECHOOSER_RESULTCODE); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { openFileChooser(uploadMsg); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg); } }); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setDomStorageEnabled(true); mWebView.getSettings().setDatabasePath( getContext().getFilesDir().getPath() + "/data/" + getContext().getPackageName() + "/databases/"); addView(mWebView); TypedArray a = mParentActivity.obtainStyledAttributes(attrs, R.styleable.ScoreflexView, defStyle, 0); String resource = a.getString(R.styleable.ScoreflexView_resource); if (null != resource) setResource(resource); a.recycle(); // Create the animated spinner mProgressBar = (ProgressBar) ((LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.scoreflex_progress_bar, null); mProgressBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER)); addView(mProgressBar); LocalBroadcastManager.getInstance(activity).registerReceiver(mLoginReceiver, new IntentFilter(Scoreflex.INTENT_USER_LOGED_IN)); setUserInterfaceState(new InitialState()); }
From source file:com.appolis.receiving.AcReceiveOptionMove.java
@Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); // register to receive notifications from SingleEntryApplication // these notifications originate from ScanAPI IntentFilter filter;//from www. jav a 2s.c o m 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.oakesville.mythling.MediaActivity.java
private void registerDownloadReceiver(Item item, long downloadId) { if (downloadReceivers == null) downloadReceivers = new HashMap<Long, DownloadBroadcastReceiver>(); DownloadBroadcastReceiver receiver = downloadReceivers.get(downloadId); if (receiver != null) { unregisterDownloadReceiver(downloadId); downloadReceivers.remove(downloadId); }// ww w . j a v a2 s .c o m receiver = new DownloadBroadcastReceiver(item, downloadId); registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); downloadReceivers.put(downloadId, receiver); }
From source file:com.balakrish.gpstracker.WaypointsListActivity.java
/** * onResume event handler/* w w w . j a v a2 s . co m*/ */ @Override protected void onResume() { super.onResume(); // registering receiver for compass updates registerReceiver(compassBroadcastReceiver, new IntentFilter(Constants.ACTION_COMPASS_UPDATES)); // registering receiver for location updates registerReceiver(locationBroadcastReceiver, new IntentFilter(Constants.ACTION_LOCATION_UPDATES)); // bind to AppService // appServiceConnectionCallback will be called once bound serviceConnection.bindAppService(); }