List of usage examples for android.content Intent getSerializableExtra
public Serializable getSerializableExtra(String name)
From source file:at.jclehner.rxdroid.NotificationReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent == null) return;// w w w . ja v a2 s.c om Settings.init(); Database.init(); final boolean isAlarmRepetition = intent.getBooleanExtra(EXTRA_IS_ALARM_REPETITION, false); final int doseTime = intent.getIntExtra(EXTRA_DOSE_TIME, Schedule.TIME_INVALID); if (doseTime != Schedule.TIME_INVALID) { if (!isAlarmRepetition) { final Date date = (Date) intent.getSerializableExtra(EXTRA_DATE); final boolean isDoseTimeEnd = intent.getBooleanExtra(EXTRA_IS_DOSE_TIME_END, false); final String eventName = isDoseTimeEnd ? "onDoseTimeEnd" : "onDoseTimeBegin"; sEventMgr.post(eventName, EVENT_HANDLER_ARG_TYPES, date, doseTime); } } mContext = context; mAlarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mDoPostSilent = intent.getBooleanExtra(EXTRA_SILENT, false); mForceUpdate = isAlarmRepetition ? true : intent.getBooleanExtra(EXTRA_FORCE_UPDATE, false); mAllDrugs = Database.getAll(Drug.class); rescheduleAlarms(); updateCurrentNotifications(); }
From source file:com.davidmiguel.gobees.monitoring.MonitoringService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); // START action if (intent.getAction().equals(START_ACTION)) { // Calculate start time (to be use in chronometer) Date now = new Date(); long elapsedRealTimeOffset = System.currentTimeMillis() - SystemClock.elapsedRealtime(); startTime = now.getTime() - elapsedRealTimeOffset; // Get monitoring config monitoringSettings = (MonitoringSettings) intent.getSerializableExtra(ARGUMENT_MON_SETTINGS); // Get apiary apiary = goBeesRepository.getApiaryBlocking(monitoringSettings.getApiaryId()); // Configurations configBeeCounter();//from ww w . j a va2 s.c om configCamera(); Notification not = notificationsHelper.getMonitoringNotification(monitoringSettings.getApiaryId(), monitoringSettings.getHiveId()); configOpenCv(); // Start service in foreground startForeground(NOTIFICATION_ID, not); // STOP action } else if (intent.getAction().equals(STOP_ACTION)) { // Release camera androidCamera.release(); // Save records if (!records.isEmpty()) { // Clean records cleanRecords(); // Save records on db goBeesRepository.saveRecords(monitoringSettings.getHiveId(), records, new SaveRecordingCallback() { @Override public void onRecordingTooShort() { stopService(); callback.onRecordingTooShort(); } @Override public void onSuccess() { stopService(); callback.onSuccess(); } @Override public void onFailure() { stopService(); callback.onFailure(); } }); } else { stopService(); callback.onRecordingTooShort(); } } return START_STICKY; }
From source file:de.flyingsnail.ipv6droid.android.AyiyaVpnService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "received start command"); if (thread == null || !thread.isAlive()) { // Build the configuration object from the saved shared preferences. SharedPreferences myPreferences = PreferenceManager.getDefaultSharedPreferences(this); TicConfiguration ticConfiguration = loadTicConfiguration(myPreferences); RoutingConfiguration routingConfiguration = loadRoutingConfiguration(myPreferences); Log.d(TAG, "retrieved configuration"); // register receivers of broadcasts registerLocalCommandReceiver();/*ww w. j a v a 2s . c o m*/ registerGlobalConnectivityReceiver(); // Start a new session by creating a new thread. TicTunnel cachedTunnel = (TicTunnel) intent.getSerializableExtra(EXTRA_CACHED_TUNNEL); thread = new VpnThread(this, cachedTunnel, ticConfiguration, routingConfiguration, SESSION_NAME, startId); thread.start(); Log.i(TAG, "VpnThread started"); } else { Log.i(TAG, "VpnThread not started again - already running"); Toast.makeText(getApplicationContext(), R.id.vpnservice_already_running, Toast.LENGTH_LONG); } return START_REDELIVER_INTENT; }
From source file:net.exclaimindustries.geohashdroid.services.WikiService.java
@Override protected ReturnCode handleIntent(Intent i) { // First and foremost, if there's no network connection, just give up // now./*from w ww .ja v a 2 s . com*/ if (!AndroidUtil.isConnected(this)) { showWaitingForConnectionNotification(); return ReturnCode.PAUSE; } // Hey, there, Intent. Got some extras for me? Info info = (Info) i.getSerializableExtra(EXTRA_INFO); Location loc = (Location) i.getSerializableExtra(EXTRA_LOCATION); String message = i.getStringExtra(EXTRA_MESSAGE); Calendar timestamp = (Calendar) i.getSerializableExtra(EXTRA_TIMESTAMP); Uri imageLocation = (Uri) i.getParcelableExtra(EXTRA_IMAGE); // Prep an HttpClient for later... HttpClient client = new DefaultHttpClient(); // To Preferences! SharedPreferences prefs = getSharedPreferences(GHDConstants.PREFS_BASE, 0); String username = prefs.getString(GHDConstants.PREF_WIKI_USER, ""); String password = prefs.getString(GHDConstants.PREF_WIKI_PASS, ""); // If you're missing something vital, bail out. if (info == null || message == null || timestamp == null) { Log.e(DEBUG_TAG, "Intent was missing some vital data (either Info, message, or timestamp), giving up..."); return ReturnCode.CONTINUE; } try { // If we got a username/password combo, try to log in. if (!username.isEmpty() && !password.isEmpty()) { WikiUtils.login(client, username, password); } // Let's say there's an image specified. ImageInfo imageInfo; if (imageLocation != null) { // If so, see if the user's even specified a login. The wiki does // not allow anonymous uploads. if (username.equals("")) { // Aww. Failure. // TODO: Need a real PendingIntent here! showPausingErrorNotification(getText(R.string.wiki_conn_anon_pic_error).toString(), null, null, null); return ReturnCode.PAUSE; } // If that's all set, we can try to look it up on the system. imageInfo = readImageInfo(imageLocation, loc); // But, if said info remains null, we've got a problem. The user // wanted an image uploaded, but we can't do that, so we have to // abandon this intent. However, I don't think that's a showstopper // in terms of continuing the queue. if (imageInfo == null) { Log.e(DEBUG_TAG, "The user was somehow allowed to choose an image that can't be accessed via MediaStore!"); showImageErrorNotification(); return ReturnCode.CONTINUE; } // Now, the location that we're going to send for the image SHOULD // match up with where the user thinks they are, so we'll read what // got stuffed into the ImageInfo. Note that we just gave it the // user's current location in the event that MediaStore doesn't have // any idea, either, so we're not going to replace good data with a // null, if said good data exists. loc = imageInfo.location; // Make sure the image doesn't already exist. If it does, we // can skip the entire "shrink image, annotate it, and upload // it" steps. if (!WikiUtils.doesWikiPageExist(client, getImageWikiName(info, imageInfo, username))) { // TODO: Create bitmap and upload it. } } return ReturnCode.CONTINUE; } catch (WikiException we) { // TODO: Handle wiki exceptions. } catch (Exception e) { // Okay, first off, are we still connected? An Exception will get // thrown if the connection just goes poof while we're trying to do // something. if (!AndroidUtil.isConnected(this)) { // We're not! Go to disconnected mode and wait. showWaitingForConnectionNotification(); return ReturnCode.PAUSE; } else { // Otherwise, we're kinda stumped. Maybe the user will know // what to do? // TODO: Handle other exceptions. } } // We shouldn't be here. return ReturnCode.PAUSE; }
From source file:net.reichholf.dreamdroid.fragment.TimerEditFragment.java
@SuppressWarnings("unchecked") @Override/*from w w w . j av a2 s.c om*/ public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == Statics.REQUEST_PICK_SERVICE) { if (resultCode == Activity.RESULT_OK) { ExtendedHashMap map = new ExtendedHashMap(); map.putAll((HashMap<String, Object>) data.getSerializableExtra(sData)); mTimer.put(Timer.KEY_SERVICE_NAME, map.getString(Service.KEY_NAME)); mTimer.put(Timer.KEY_REFERENCE, map.getString(Service.KEY_REFERENCE)); mService.setText(mTimer.getString(Timer.KEY_SERVICE_NAME)); } } }
From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { final String METHOD = "onActivityResult(" + requestCode + ", " + resultCode + ", " + data + "): "; if (resultCode == Activity.RESULT_OK) { // Figure out which Result code we are dealing with. This method /// handles the results of all dialog fragments used to set the /// model data. switch (requestCode) { case REQUEST_BEGIN_DATE_PICKER: Date beginDate = (Date) data.getSerializableExtra(DateTimePickerFragment.RESULT_DATE_TIME); LocalDateTime ldtBeginDate = new LocalDateTime(beginDate.getTime()); if (ldtBeginDate.isBefore(new LocalDateTime(mHours.getEnd().getTime()))) { mHours.setBegin(beginDate); updateUI();/*from ww w .j a v a 2s .co m*/ } else { String message = "End date must be after begin date"; Log.e(TAG, METHOD + message); Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show(); } break; case REQUEST_END_DATE_PICKER: Date endDate = (Date) data.getSerializableExtra(DateTimePickerFragment.RESULT_DATE_TIME); LocalDateTime ldtEndDate = new LocalDateTime(endDate.getTime()); if (ldtEndDate.isAfter(new LocalDateTime(mHours.getBegin().getTime()))) { mHours.setEnd(endDate); updateUI(); } else { String message = "End date must be after begin date"; Log.e(TAG, METHOD + message); Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show(); } break; case REQUEST_BREAK: Integer breakTimeInMinutes = (Integer) data .getSerializableExtra(NumberPickerFragment.RESULT_MINUTES); mHours.setBreak(renderBreakForStorage(breakTimeInMinutes)); updateUI(); break; case REQUEST_CODE_MANAGE_PROJECTS: Project project = (Project) data.getSerializableExtra(ProjectListActivity.RESULT_PROJECT); mHours.setProject(project); updateUI(); break; default: break; } } }
From source file:com.androidquery.simplefeed.activity.PostActivity.java
private void handleFriends(Intent data) { List<Entity> tags = (List<Entity>) data.getSerializableExtra("selected"); if (tags == null || tags.size() == 0) return;/*w ww .j a va2 s.c o m*/ AQUtility.debug("friends", tags); this.tags = tags; attachFriends(tags); refreshButtons(); }
From source file:com.github.developerpaul123.filepickerlibrary.FilePickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; //get the theme type for this activity themeType = (ThemeType) getIntent().getSerializableExtra(THEME_TYPE); if (themeType == null) { themeType = ThemeType.ACTIVITY;/* w ww .j a v a 2 s . c o m*/ } setThemeType(themeType); areButtonsShowing = false; try { getActionBar().setDisplayHomeAsUpEnabled(true); } catch (NullPointerException e) { e.printStackTrace(); } //set up the mime type for the file. Object rawMimeTypeParameter = getIntent().getExtras().get(MIME_TYPE); if (rawMimeTypeParameter instanceof String) { mimeType = (String) rawMimeTypeParameter; } else if (rawMimeTypeParameter instanceof MimeType) { mimeType = ((MimeType) rawMimeTypeParameter).getMimeType(); } else { mimeType = null; } //set up the animations setUpAnimations(); Intent givenIntent = getIntent(); //get the scope type and request code. Defaults are all files and request of a directory //path. scopeType = (Scope) givenIntent.getSerializableExtra(SCOPE); if (scopeType == null) { //set default if it is null scopeType = Scope.ALL; } requestCode = (Request) givenIntent.getSerializableExtra(REQUEST); colorId = givenIntent.getIntExtra(INTENT_EXTRA_COLOR_ID, android.R.color.holo_blue_light); drawableId = givenIntent.getIntExtra(INTENT_EXTRA_DRAWABLE_ID, -1); fabColorId = givenIntent.getIntExtra(INTENT_EXTRA_FAB_COLOR_ID, -1); setContentView(R.layout.file_picker_activity_layout); listView = (ListView) findViewById(android.R.id.list); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (areButtonsShowing) { if (Math.abs(firstVisibleItem - mLastFirstVisibleItem) >= 3) { hideButtons(); adapter.setSelectedPosition(-1); mLastFirstVisibleItem = firstVisibleItem; } else if (firstVisibleItem > adapter.getSelectedPosition()) { hideButtons(); adapter.setSelectedPosition(-1); } } else { mLastFirstVisibleItem = firstVisibleItem; } } }); listHeaderView = getLayoutInflater().inflate(R.layout.file_list_header_view, null); listHeaderView.setFocusable(false); listHeaderView.setClickable(false); listHeaderView.setOnClickListener(null); listHeaderView.setActivated(false); initializeViews(); //drawable has not been set so set the color. setHeaderBackground(colorId, drawableId); //check for proper permissions. if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { //Show permission rationale. new MaterialDialog.Builder(this).title(R.string.file_picker_permission_rationale_dialog_title) .content(R.string.file_picker_permission_rationale_dialog_content) .positiveText(R.string.file_picker_ok).negativeText(R.string.file_picker_cancel) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { ActivityCompat.requestPermissions(FilePickerActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_FOR_READ_EXTERNAL_STORAGE); } }).onNegative(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { setResult(RESULT_CANCELED); finish(); } }).show(); } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_FOR_READ_EXTERNAL_STORAGE); } } else { init(); } } else { init(); } }
From source file:com.misczak.joinmybridge.PhoneBookFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "onActivityResult"); listView.invalidateViews();//ww w. j a v a 2 s . com UUID bridgeId; if (resultCode != Activity.RESULT_OK) return; if (requestCode == REQUEST_CALL) { boolean[] options = data.getBooleanArrayExtra(EXTRA_CALL_OPTIONS); bridgeId = (UUID) data.getSerializableExtra(EXTRA_BRIDGE_ID); Log.d(TAG, " onActivityResult arr: " + Arrays.toString(options)); CallUtilities utils = new CallUtilities(); phoneNumber = utils.getCompleteNumber(bridgeId, mBridgeList, options[0], options[1]); placePhoneCall(phoneNumber); } //Read the selected data from the contacts application if (requestCode == REQUEST_CONTACT) { Uri contactUri = data.getData(); String[] queryFields = { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }; Cursor c = getActivity().getContentResolver().query(contactUri, queryFields, null, null, null); if (c.getCount() == 0) { c.close(); return; } c.moveToFirst(); int phoneNumberColumn = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); int displayNameColumn = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); String contactPhoneNumber = c.getString(phoneNumberColumn).trim(); String contactDisplayName = c.getString(displayNameColumn); Log.d(TAG, contactDisplayName); Log.d(TAG, contactPhoneNumber); Intent i = new Intent(getActivity(), BridgeActivity.class); i.putExtra(BridgeFragment.EXTRA_BRIDGE_NAME, contactDisplayName); ImportUtilities iu = new ImportUtilities(); String[] bridgeComponents = iu.getNumberArray(contactPhoneNumber); if (bridgeComponents[0] != null && !bridgeComponents[0].isEmpty()) { i.putExtra(BridgeFragment.EXTRA_BRIDGE_NUMBER, bridgeComponents[0]); } if (bridgeComponents[1] != null && !bridgeComponents[1].isEmpty()) { i.putExtra(BridgeFragment.EXTRA_PARTICIPANT_CODE, bridgeComponents[1]); } if (bridgeComponents[2] != null && !bridgeComponents[2].isEmpty()) { i.putExtra(BridgeFragment.EXTRA_HOST_CODE, bridgeComponents[2]); } if (bridgeComponents[3] != null && !bridgeComponents[3].isEmpty()) { i.putExtra(BridgeFragment.EXTRA_FIRST_TONE, bridgeComponents[3]); } if (bridgeComponents[4] != null && !bridgeComponents[4].isEmpty()) { i.putExtra(BridgeFragment.EXTRA_SECOND_TONE, bridgeComponents[4]); } startActivityForResult(i, 0); } }
From source file:com.devpaul.filepickerlibrary.FilePickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; //get the theme type for this activity themeType = (ThemeType) getIntent().getSerializableExtra(THEME_TYPE); if (themeType == null) { themeType = ThemeType.ACTIVITY;//from w w w.j ava 2 s .co m } setThemeType(themeType); areButtonsShowing = false; try { getActionBar().setDisplayHomeAsUpEnabled(true); } catch (NullPointerException e) { e.printStackTrace(); } //set up the mime type for the file. Object rawMimeTypeParameter = getIntent().getExtras().get(MIME_TYPE); if (rawMimeTypeParameter instanceof String) { mimeType = (String) rawMimeTypeParameter; } else if (rawMimeTypeParameter instanceof FileType) { mimeType = ((FileType) rawMimeTypeParameter).getMimeType(); } else { mimeType = null; } //set up the animations setUpAnimations(); Intent givenIntent = getIntent(); //get the scope type and request code. Defaults are all files and request of a directory //path. scopeType = (FileScopeType) givenIntent.getSerializableExtra(SCOPE_TYPE); if (scopeType == null) { //set default if it is null scopeType = FileScopeType.ALL; } requestCode = givenIntent.getIntExtra(REQUEST_CODE, REQUEST_DIRECTORY); colorId = givenIntent.getIntExtra(INTENT_EXTRA_COLOR_ID, android.R.color.holo_blue_light); drawableId = givenIntent.getIntExtra(INTENT_EXTRA_DRAWABLE_ID, -1); fabColorId = givenIntent.getIntExtra(INTENT_EXTRA_FAB_COLOR_ID, -1); setContentView(R.layout.file_picker_activity_layout); listView = (ListView) findViewById(android.R.id.list); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (areButtonsShowing) { if (Math.abs(firstVisibleItem - mLastFirstVisibleItem) >= 3) { hideButtons(); adapter.setSelectedPosition(-1); mLastFirstVisibleItem = firstVisibleItem; } else if (firstVisibleItem > adapter.getSelectedPosition()) { hideButtons(); adapter.setSelectedPosition(-1); } } else { mLastFirstVisibleItem = firstVisibleItem; } } }); listHeaderView = getLayoutInflater().inflate(R.layout.file_list_header_view, null); listHeaderView.setFocusable(false); listHeaderView.setClickable(false); listHeaderView.setOnClickListener(null); listHeaderView.setActivated(false); initializeViews(); //drawable has not been set so set the color. setHeaderBackground(colorId, drawableId); //check for proper permissions. if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { //Show permission rationale. new MaterialDialog.Builder(FilePickerActivity.this) .title(R.string.file_picker_permission_rationale_dialog_title) .content(R.string.file_picker_permission_rationale_dialog_content) .positiveText(R.string.file_picker_ok).negativeText(R.string.file_picker_cancel) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { ActivityCompat.requestPermissions(FilePickerActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_FOR_READ_EXTERNAL_STORAGE); } @Override public void onNegative(MaterialDialog dialog) { setResult(RESULT_CANCELED); finish(); } }).show(); } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_FOR_READ_EXTERNAL_STORAGE); } } else { init(); } } else { init(); } }