List of usage examples for android.content Intent getIntExtra
public int getIntExtra(String name, int defaultValue)
From source file:co.shunya.gita.player.MusicService.java
/** * Called when we receive an Intent. When we receive an intent sent to us via startService(), * this is the method that gets called. So here we react appropriately depending on the * Intent's action, which specifies what is being requested of us. */// w w w. j av a 2 s .co m @Override public int onStartCommand(Intent intent, int flags, int startId) { String action = intent.getAction(); if (action.equals(ACTION_TOGGLE_PLAYBACK)) processTogglePlaybackRequest(intent); else if (action.equals(ACTION_PLAY)) { String lName = intent.getStringExtra(INTENT_LANG_NAME_EXTRA); int album = intent.getIntExtra(INTENT_ALBUM_EXTRA, -1); if (lName == null || album < 1) { throw new IllegalArgumentException("Must Pass Lang Name in intent"); } if (!lName.equals(MusicRetriever.musicRetriever) || album == MusicRetriever.mAlbumId) { setState(State.Retrieving); mRetriever = MusicRetriever.getInstance(this, lName, album); new PrepareMusicRetrieverTask(mRetriever, this).execute(); } processPlayRequest(intent); } else if (action.equals(ACTION_PAUSE)) processPauseRequest(); else if (action.equals(ACTION_SKIP)) processSkipRequest(); else if (action.equals(ACTION_STOP)) processStopRequest(); else if (action.equals(ACTION_REWIND)) processRewindRequest(); else if (action.equals(ACTION_SEEKBAR_CHANGE)) { int progress = intent.getIntExtra(INTENT_PROGRESS_EXTRA, 0); processSeekbarChange(progress); } return START_NOT_STICKY; // Means we started the service, but don't want it to // restart in case it's killed. }
From source file:com.android.email.EmailNotificationController.java
@Override public void handleUpdateNotificationIntent(Context context, Intent intent) { final Uri accountUri = intent.getParcelableExtra(UIProvider.UpdateNotificationExtras.EXTRA_ACCOUNT); final Uri folderUri = intent.getParcelableExtra(UIProvider.UpdateNotificationExtras.EXTRA_FOLDER); final int unreadCount = intent.getIntExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNREAD_COUNT, 0);/*from w w w.j a v a2 s .c o m*/ final int unseenCount = intent.getIntExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNSEEN_COUNT, 0); final ContentResolver contentResolver = context.getContentResolver(); final Cursor accountCursor = contentResolver.query(accountUri, UIProvider.ACCOUNTS_PROJECTION, null, null, null); if (accountCursor == null) { LogUtils.e(LOG_TAG, "Null account cursor for account " + accountUri); return; } com.android.mail.providers.Account account = null; try { if (accountCursor.moveToFirst()) { account = com.android.mail.providers.Account.builder().buildFrom(accountCursor); } } finally { accountCursor.close(); } if (account == null) { LogUtils.d(LOG_TAG, "Tried to create a notification for a missing account " + accountUri); return; } final Cursor folderCursor = contentResolver.query(folderUri, UIProvider.FOLDERS_PROJECTION, null, null, null); if (folderCursor == null) { LogUtils.e(LOG_TAG, "Null folder cursor for account " + accountUri + ", mailbox " + folderUri); return; } Folder folder = null; try { if (folderCursor.moveToFirst()) { folder = new Folder(folderCursor); } else { LogUtils.e(LOG_TAG, "Empty folder cursor for account " + accountUri + ", mailbox " + folderUri); return; } } finally { folderCursor.close(); } // TODO: we don't always want getAttention to be true, but we don't necessarily have a // good heuristic for when it should or shouldn't be. NotificationUtils.sendSetNewEmailIndicatorIntent(context, unreadCount, unseenCount, account, folder, true /* getAttention */); }
From source file:com.etalio.android.EtalioBase.java
/** * Call this method in authenticating activity's onActivityResult to handle Etalio single sign on results. * @param requestCode/* w ww. ja v a2 s .c o m*/ * @param resultCode * @param data */ public void onActivityResult(int requestCode, int resultCode, Intent data, AuthenticationCallback callback) { if (requestCode == REQUEST_CODE_SSO && resultCode == Activity.RESULT_OK) { String accessToken = data.getStringExtra(EtalioBase.EXTRA_ACCESS_TOKEN); String refreshToken = data.getStringExtra(EtalioBase.EXTRA_REFRESH_TOKEN); int expiresIn = data.getIntExtra(EtalioBase.EXTRA_EXPIRES_IN, 0); setEtalioToken(new EtalioToken(accessToken, refreshToken, expiresIn)); callback.onAuthenticationSuccess(); } else { callback.onAuthenticationFailure( new EtalioTokenException(EtalioTokenException.TokensErrorResponse.INVALID_RESPONSE)); } }
From source file:com.nextgis.maplibui.service.LayerFillService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i("LayerFillService", "Received start id " + startId + ": " + intent); if (intent != null) { String action = intent.getAction(); if (!TextUtils.isEmpty(action)) { switch (action) { case ACTION_ADD_TASK: int layerGroupId = intent.getIntExtra(KEY_LAYER_GROUP_ID, Constants.NOT_FOUND); mLayerGroup = (LayerGroup) MapBase.getInstance().getLayerById(layerGroupId); Bundle extra = intent.getExtras(); int layerType = extra.getInt(KEY_INPUT_TYPE, Constants.NOT_FOUND); switch (layerType) { case VECTOR_LAYER: mQueue.add(new VectorLayerFillTask(extra)); break; case VECTOR_LAYER_WITH_FORM: mQueue.add(new UnzipForm(extra)); break; case TMS_LAYER: mQueue.add(new LocalTMSFillTask(extra)); break; case NGW_LAYER: mQueue.add(new NGWVectorLayerFillTask(extra)); break; }/*from ww w . ja v a 2 s .co m*/ if (!mIsRunning) { startNextTask(); } return START_STICKY; case ACTION_STOP: mQueue.clear(); mIsCanceled = true; break; case ACTION_SHOW: mProgressIntent.putExtra(KEY_STATUS, STATUS_SHOW).putExtra(KEY_TITLE, mBuilder.mContentTitle); sendBroadcast(mProgressIntent); break; } } } return START_STICKY; }
From source file:com.android.providers.downloads.DownloadService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { XLConfig.LOGD("in DownloadService onStartCommand"); int mCMD_Param = intent != null ? intent.getIntExtra("CMD_TYPE", 0) : 0; switch (mCMD_Param) { case 0://from w w w . j av a 2s.co m break; case 1: XLConfig.LOGD("xunlei Service ---> receive broadcast, executive getting token process"); startGetXlTokenEx(true); break; case 2: if (mXlDownloadManager != null) { mXlDownloadManager.XLNotifyNetWorkType(XLUtil.getNetwrokType(getApplicationContext()) + 1); } XLConfig.LOGD(Constants.TAG, "xunlei Service ---> XLNotifyNetWorkType networkType = " + (XLUtil.getNetwrokType(getApplicationContext()) + 1)); break; } int returnValue = super.onStartCommand(intent, flags, startId); mLastStartId = startId; if (mCMD_Param != 1) { enqueueUpdate(); } return returnValue; }
From source file:com.androidinspain.deskclock.timer.TimerFragment.java
@Override public void onStart() { super.onStart(); // Initialize the page indicators. updatePageIndicators();//from ww w .ja v a 2 s . c o m boolean createTimer = false; int showTimerId = -1; // Examine the intent of the parent activity to determine which view to display. final Intent intent = getActivity().getIntent(); if (intent != null) { // These extras are single-use; remove them after honoring them. createTimer = intent.getBooleanExtra(EXTRA_TIMER_SETUP, false); intent.removeExtra(EXTRA_TIMER_SETUP); showTimerId = intent.getIntExtra(TimerService.EXTRA_TIMER_ID, -1); intent.removeExtra(TimerService.EXTRA_TIMER_ID); } // Choose the view to display in this fragment. if (showTimerId != -1) { // A specific timer must be shown; show the list of timers. showTimersView(FAB_AND_BUTTONS_IMMEDIATE); } else if (!hasTimers() || createTimer || mTimerSetupState != null) { // No timers exist, a timer is being created, or the last view was timer setup; // show the timer setup view. showCreateTimerView(FAB_AND_BUTTONS_IMMEDIATE); if (mTimerSetupState != null) { mCreateTimerView.setState(mTimerSetupState); mTimerSetupState = null; } } else { // Otherwise, default to showing the list of timers. showTimersView(FAB_AND_BUTTONS_IMMEDIATE); } // If the intent did not specify a timer to show, show the last timer that expired. if (showTimerId == -1) { final Timer timer = DataModel.getDataModel().getMostRecentExpiredTimer(); showTimerId = timer == null ? -1 : timer.getId(); } // If a specific timer should be displayed, display the corresponding timer tab. if (showTimerId != -1) { final Timer timer = DataModel.getDataModel().getTimer(showTimerId); if (timer != null) { final int index = DataModel.getDataModel().getTimers().indexOf(timer); mViewPager.setCurrentItem(index); } } }
From source file:com.piusvelte.taplock.client.core.TapLockService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { String action = intent.getAction(); if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF); if (state == BluetoothAdapter.STATE_ON) { if (mStartedBT) { if (mUIInterface != null) { try { mUIInterface.setMessage("Bluetooth enabled"); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); }// ww w . j ava2s. co m } if ((mQueueAddress != null) && (mQueueState != null)) requestWrite(mQueueAddress, mQueueState, mQueuePassphrase); else if (mRequestDiscovery && !mBtAdapter.isDiscovering()) mBtAdapter.startDiscovery(); else if (mUIInterface != null) { try { mUIInterface.setBluetoothEnabled(); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } } } } else if (state == BluetoothAdapter.STATE_TURNING_OFF) { if (mUIInterface != null) { try { mUIInterface.setMessage("Bluetooth disabled"); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } } stopThreads(); } } else if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (device.getBondState() == BluetoothDevice.BOND_BONDED) { // connect if configured String address = device.getAddress(); for (JSONObject deviceJObj : mDevices) { try { if (deviceJObj.getString(KEY_ADDRESS).equals(address)) { // if queued mDeviceFound = (mQueueAddress != null) && mQueueAddress.equals(address) && (mQueueState != null); break; } } catch (JSONException e) { Log.e(TAG, e.getMessage()); } } } else if (mRequestDiscovery && (mUIInterface != null)) { String unpairedDevice = TapLock .createDevice(device.getName(), device.getAddress(), DEFAULT_PASSPHRASE).toString(); try { mUIInterface.setUnpairedDevice(unpairedDevice); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } } } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { if (mDeviceFound) { requestWrite(mQueueAddress, mQueueState, mQueuePassphrase); mDeviceFound = false; } else if (mRequestDiscovery) { mRequestDiscovery = false; if (mUIInterface != null) { try { mUIInterface.setDiscoveryFinished(); } catch (RemoteException e) { Log.e(TAG, e.toString()); } } } } else if (ACTION_TOGGLE.equals(action) && intent.hasExtra(EXTRA_DEVICE_ADDRESS)) { String address = intent.getStringExtra(EXTRA_DEVICE_ADDRESS); requestWrite(address, ACTION_TOGGLE, null); } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { // create widget if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (intent.hasExtra(EXTRA_DEVICE_NAME)) { // add a widget String deviceName = intent.getStringExtra(EXTRA_DEVICE_NAME); for (int i = 0, l = mDevices.size(); i < l; i++) { String name = null; try { name = mDevices.get(i).getString(KEY_NAME); } catch (JSONException e1) { e1.printStackTrace(); } if ((name != null) && name.equals(deviceName)) { JSONObject deviceJObj = mDevices.remove(i); JSONArray widgetsJArr; if (deviceJObj.has(KEY_WIDGETS)) { try { widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS); } catch (JSONException e) { widgetsJArr = new JSONArray(); } } else widgetsJArr = new JSONArray(); widgetsJArr.put(appWidgetId); try { deviceJObj.put(KEY_WIDGETS, widgetsJArr); } catch (JSONException e) { e.printStackTrace(); } mDevices.add(i, deviceJObj); TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices); break; } } } buildWidget(appWidgetId); } else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)) { int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null) { for (int appWidgetId : appWidgetIds) buildWidget(appWidgetId); } } } else if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); Log.d(TAG, "delete appWidgetId: " + appWidgetId); for (int i = 0, l = mDevices.size(); i < l; i++) { JSONObject deviceJObj = mDevices.get(i); if (deviceJObj.has(KEY_WIDGETS)) { JSONArray widgetsJArr = null; try { widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS); } catch (JSONException e) { e.printStackTrace(); } if (widgetsJArr != null) { boolean wasUpdated = false; JSONArray newWidgetsJArr = new JSONArray(); for (int widgetIdx = 0, wdigetsLen = widgetsJArr .length(); widgetIdx < wdigetsLen; widgetIdx++) { int widgetId; try { widgetId = widgetsJArr.getInt(widgetIdx); } catch (JSONException e) { widgetId = AppWidgetManager.INVALID_APPWIDGET_ID; e.printStackTrace(); } Log.d(TAG, "eval widgetId: " + widgetId); if ((widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) && (widgetId == appWidgetId)) { Log.d(TAG, "skip: " + widgetId); wasUpdated = true; } else { Log.d(TAG, "include: " + widgetId); newWidgetsJArr.put(widgetId); } } if (wasUpdated) { try { deviceJObj.put(KEY_WIDGETS, newWidgetsJArr); mDevices.remove(i); mDevices.add(i, deviceJObj); TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices); Log.d(TAG, "stored: " + deviceJObj.toString()); } catch (JSONException e) { e.printStackTrace(); } } } } else { JSONArray widgetsJArr = new JSONArray(); try { deviceJObj.put(KEY_WIDGETS, widgetsJArr); mDevices.remove(i); mDevices.add(i, deviceJObj); TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices); } catch (JSONException e) { e.printStackTrace(); } } } } } return START_STICKY; }
From source file:com.cttapp.bby.mytlc.layer8apps.CalendarHandler.java
/************ * PURPOSE: Handles the primary thread in the service * ARGUMENTS: Intent intent/*from w w w . j a va 2 s. c om*/ * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com> *************/ @Override protected void onHandleIntent(Intent intent) { // Get our stored data from the intent username = intent.getStringExtra("username"); password = intent.getStringExtra("password"); messenger = (Messenger) intent.getExtras().get("handler"); calID = intent.getIntExtra("calendarID", -1); String url = getApplicationContext().getResources().getString(R.string.url); // Create variables to be used through the application List<String[]> workDays = null; ConnectionManager conn = ConnectionManager.newConnection(); /************ * Once we verify that we have a valid token, we get the actual schedule *************/ updateStatus("Logging in..."); String tempToken = conn.getData(url + "/etm/login.jsp"); if (tempToken != null) { loginToken = parseToken(tempToken); } else { showError("Error connecting to MyTLC, make sure you have a valid network connection"); return; } String postResults = null; // This creates our login information List<NameValuePair> parameters = createParams(); if (loginToken != null) { // Here we send the information to the server and login postResults = conn.postData(url + "/etm/login.jsp", parameters); } else { showError("Error retrieving your login token"); return; } if (postResults != null && postResults.toLowerCase().contains("etmmenu.jsp") && !postResults.toLowerCase().contains("<font size=\"2\">")) { updateStatus("Retrieving schedule..."); postResults = conn.getData(url + "/etm/time/timesheet/etmTnsMonth.jsp"); } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("Error logging in, please verify your username and password"); } return; } // If we successfully got the information, then parse out the schedule to read it properly String secToken = null; if (postResults != null) { updateStatus("Parsing schedule..."); workDays = parseSchedule(postResults); secToken = parseSecureToken(postResults); wbat = parseWbat(postResults); } else { showError("Could not obtain user schedule"); return; } if (secToken != null) { parameters = createSecondParams(secToken); postResults = conn.postData(url + "/etm/time/timesheet/etmTnsMonth.jsp", parameters); } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("Error retrieving your security token"); } return; } List<String[]> secondMonth = null; if (postResults != null) { secondMonth = parseSchedule(postResults); } else { showError("Could not obtain user schedule"); return; } if (secondMonth != null) { if (workDays == null) { workDays = secondMonth; } else { workDays.addAll(secondMonth); } finalDays = workDays; } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("There was an error retrieving your schedule"); } return; } // Add our shifts to the calendar updateStatus("Adding shifts to calendar..."); int numShifts = addDays(); if (finalDays != null && numShifts > -1) { // Report back that we're successful! Message msg = Message.obtain(); Bundle b = new Bundle(); b.putString("status", "DONE"); b.putInt("count", numShifts); msg.setData(b); try { messenger.send(msg); } catch (Exception e) { // Nothing } } else { showError("Couldn't add your shifts to your calendar"); } }
From source file:com.digi.android.wva.VehicleInfoService.java
@Override public int onStartCommand(Intent intent, int code, int startid) { // Log.d(TAG, "VIS onStartCommand, got intent? " + (intent != null)); if (intent == null) { // Process was killed and is being restarted, and we previously // returned START_STICKY, so this method is getting a null Intent. // Since the app was killed we don't know who to talk to, so // don't talk to anyone. Log.e(TAG, "onStartCommand - null intent"); isConnected = false;//from w w w . jav a 2 s . c o m } else { int command = intent.getIntExtra(INTENT_CMD, -1); if (command == -1) { Log.e(TAG, "startService called without command"); isConnected = false; } else { parseIntent(intent, command); } } showNotificationIfRunning(); return START_STICKY; }
From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activityHelper = ActivityHelper.createInstance(getActivity()); parkingApp = (ParkingApp) getActivity().getApplicationContext(); Intent intent = getSherlockActivity().getIntent(); // TODO Optimize this using savedInstanceState to avoid reload of // identical data onResume if (Intent.ACTION_VIEW.equals(intent.getAction())) { mIdPost = getIdFromUri(intent.getData()); }/*from w w w . j a va2 s. c o m*/ // else if ((savedInstanceState != null) // && savedInstanceState.containsKey(Const.KEY_INSTANCE_RINK_ID)) { // mRinkId = savedInstanceState.getInt(Const.KEY_INSTANCE_RINK_ID); // } else { mIdPost = intent.getIntExtra(Const.INTENT_EXTRA_POST_ID, -1); } // mUriPost = Posts.buildPostUri(Integer.toString(mIdPost)); getLoaderManager().initLoader(PostDetailsQuery._TOKEN, null, this); }