List of usage examples for android.content Intent getBundleExtra
public Bundle getBundleExtra(String name)
From source file:com.android.contacts.ContactSaveService.java
private void undo(Intent intent) { final String actionToUndo = intent.getStringExtra(EXTRA_UNDO_ACTION); if (ACTION_DELETE_GROUP.equals(actionToUndo)) { mGroupsDao.undoDeletion(intent.getBundleExtra(EXTRA_UNDO_DATA)); }//from w w w .ja v a 2s.com }
From source file:uk.org.downiesoft.slideshow.GridViewFragment.java
/** * {@inheritDoc}//from www . j a v a2 s .co m */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { SlideShowActivity.debug(1, TAG, "onActivityResult(%s,%s)", requestCode, resultCode); switch (requestCode) { case SlideShowActivity.REQUEST_FAVOURITES: if (resultCode == Activity.RESULT_OK) { File file = new File(data.getStringExtra("file")); onFavouritesChanged(file); } break; case SlideShowActivity.REQUEST_SLIDESHOW: if (data != null) { int image = data.getIntExtra("currentImage", mCurrentImage); SlideShowActivity.debug(1, TAG, "onActivityResult: %d %d", requestCode, image); if (image != mCurrentImage) { mCurrentImage = image; int first = mGridView.getFirstVisiblePosition(); int last = mGridView.getLastVisiblePosition(); if (image < first || image > last) { mCurrentScrollY = image; } mGridView.setSelection(mCurrentImage); if (mPreview != null) { //mPreview.setImage(mCurrentImage); } } } break; case SlideShowActivity.REQUEST_BROWSER: if (resultCode == Activity.RESULT_OK) { ZFile zfile = new ZFile(data.getBundleExtra(BrowserDialog.ARG_ZFILE)); if (!zfile.equals(mCurrentFile)) { fileChanged(zfile, 0, 0, false); } } break; default: super.onActivityResult(requestCode, resultCode, data); } }
From source file:RhodesService.java
private void handleCommand(Intent intent, int startId) { if (intent == null) { return;//from w w w . j ava2 s . c o m } String source = intent.getStringExtra(INTENT_SOURCE); Logger.I(TAG, "handleCommand: startId=" + startId + ", source=" + source); if (source == null) throw new IllegalArgumentException("Service command received from empty source"); if (source.equals(BaseActivity.INTENT_SOURCE)) { Logger.D(TAG, "New activity was created"); } else if (source.equals(PushContract.INTENT_SOURCE)) { int type = intent.getIntExtra(PushContract.INTENT_TYPE, PushContract.INTENT_TYPE_UNKNOWN); switch (type) { case PushContract.INTENT_TYPE_REGISTRATION_ID: { String id = intent.getStringExtra(PushContract.INTENT_REGISTRATION_ID); String pushType = intent.getStringExtra(PushContract.INTENT_PUSH_CLIENT); if (id == null) throw new IllegalArgumentException("Empty registration id received in service command"); Logger.I(TAG, "Received PUSH registration id: " + id); setPushRegistrationId(pushType, id); } break; case PushContract.INTENT_TYPE_MESSAGE: if (intent.hasExtra(PushContract.INTENT_MESSAGE_EXTRAS)) { final String pushType = intent.getStringExtra(PushContract.INTENT_PUSH_CLIENT); final Bundle extras = intent.getBundleExtra(PushContract.INTENT_MESSAGE_EXTRAS); Logger.D(TAG, "Received PUSH message: " + extras); RhodesApplication.runWhen(RhodesApplication.AppState.AppStarted, new RhodesApplication.StateHandler(true) { @Override public void run() { handlePushMessage(pushType, extras); } }); break; } else if (intent.hasExtra(PushContract.INTENT_MESSAGE_JSON)) { final String pushType = intent.getStringExtra(PushContract.INTENT_PUSH_CLIENT); final String json = intent.getStringExtra(PushContract.INTENT_MESSAGE_JSON); if (json != null) { Logger.D(TAG, "Received PUSH message (JSON): " + json); RhodesApplication.runWhen(RhodesApplication.AppState.AppStarted, new RhodesApplication.StateHandler(true) { @Override public void run() { handlePushMessage(pushType, json); } }); } break; } default: Logger.W(TAG, "Unknown command type received from " + source + ": " + type); } } }
From source file:com.bullmobi.base.ui.activities.SettingsActivity.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); // Should happen before any call to getIntent() getMetaData();/* w w w . jav a2s.co m*/ final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_UI_OPTIONS)) { getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); } // Getting Intent properties can only be done after the super.onCreate(...) final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); final ComponentName cn = intent.getComponent(); final String className = cn.getClassName(); boolean isShowingDashboard = className.equals(Settings2.class.getName()); // This is a "Sub Settings" when: // - this is a real SubSettings // - or :settings:show_fragment_as_subsetting is passed to the Intent final boolean isSubSettings = className.equals(SubSettings.class.getName()) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets if (isSubSettings) { // Check also that we are not a Theme Dialog as we don't want to override them /* final int themeResId = getTheme(). getThemeResId(); if (themeResId != R.style.Theme_DialogWhenLarge && themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { setTheme(R.style.Theme_SubSettings); } */ } setContentView(R.layout.settings_main_dashboard); mContent = (ViewGroup) findViewById(R.id.main_content); getSupportFragmentManager().addOnBackStackChangedListener(this); if (savedState != null) { // We are restarting from a previous saved state; used that to initialize, instead // of starting fresh. setTitleFromIntent(intent); ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); if (categories != null) { mCategories.clear(); mCategories.addAll(categories); setTitleFromBackStack(); } mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); } else { if (!isShowingDashboard) { mDisplayHomeAsUpEnabled = isSubSettings; setTitleFromIntent(intent); Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); switchToFragment(initialFragmentName, initialArguments, true, false, mInitialTitleResId, mInitialTitle, false); } else { mDisplayHomeAsUpEnabled = false; mInitialTitleResId = R.string.app_name; switchToFragment(DashboardFragment.class.getName(), null, false, false, mInitialTitleResId, mInitialTitle, false); } } ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); } }
From source file:com.achep.base.ui.activities.SettingsActivity.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); // Should happen before any call to getIntent() getMetaData();/* w w w . j av a2 s. com*/ final Intent intent = getIntent(); if (intent.hasExtra(EXTRA_UI_OPTIONS)) { getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); } // Getting Intent properties can only be done after the super.onCreate(...) final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); final ComponentName cn = intent.getComponent(); final String className = cn.getClassName(); boolean isShowingDashboard = className.equals(Settings2.class.getName()); // This is a "Sub Settings" when: // - this is a real SubSettings // - or :settings:show_fragment_as_subsetting is passed to the Intent final boolean isSubSettings = className.equals(SubSettings.class.getName()) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets if (isSubSettings) { // Check also that we are not a Theme Dialog as we don't want to override them /* final int themeResId = getTheme(). getThemeResId(); if (themeResId != R.style.Theme_DialogWhenLarge && themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { setTheme(R.style.Theme_SubSettings); } */ } setContentView(R.layout.settings_main_dashboard); mContent = (ViewGroup) findViewById(android.R.id.content); getSupportFragmentManager().addOnBackStackChangedListener(this); if (savedState != null) { // We are restarting from a previous saved state; used that to initialize, instead // of starting fresh. setTitleFromIntent(intent); ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); if (categories != null) { mCategories.clear(); mCategories.addAll(categories); setTitleFromBackStack(); } mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); } else { if (!isShowingDashboard) { mDisplayHomeAsUpEnabled = isSubSettings; setTitleFromIntent(intent); Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); switchToFragment(initialFragmentName, initialArguments, true, false, mInitialTitleResId, mInitialTitle, false); } else { mDisplayHomeAsUpEnabled = false; mInitialTitleResId = R.string.app_name; switchToFragment(DashboardFragment.class.getName(), null, false, false, mInitialTitleResId, mInitialTitle, false); } } ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); } }
From source file:com.fenlisproject.elf.core.framework.ElfBinder.java
public static void bindIntentExtra(Object receiver) { Field[] fields = receiver.getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true);//ww w. jav a2 s. co m IntentExtra intentExtra = field.getAnnotation(IntentExtra.class); if (intentExtra != null) { try { Intent intent = null; if (receiver instanceof Activity) { intent = ((Activity) receiver).getIntent(); } else if (receiver instanceof Fragment) { intent = ((Fragment) receiver).getActivity().getIntent(); } if (intent != null) { Class<?> type = field.getType(); if (type == Boolean.class || type == boolean.class) { field.set(receiver, intent.getBooleanExtra(intentExtra.value(), false)); } else if (type == Byte.class || type == byte.class) { field.set(receiver, intent.getByteExtra(intentExtra.value(), (byte) 0)); } else if (type == Character.class || type == char.class) { field.set(receiver, intent.getCharExtra(intentExtra.value(), '\u0000')); } else if (type == Double.class || type == double.class) { field.set(receiver, intent.getDoubleExtra(intentExtra.value(), 0.0d)); } else if (type == Float.class || type == float.class) { field.set(receiver, intent.getFloatExtra(intentExtra.value(), 0.0f)); } else if (type == Integer.class || type == int.class) { field.set(receiver, intent.getIntExtra(intentExtra.value(), 0)); } else if (type == Long.class || type == long.class) { field.set(receiver, intent.getLongExtra(intentExtra.value(), 0L)); } else if (type == Short.class || type == short.class) { field.set(receiver, intent.getShortExtra(intentExtra.value(), (short) 0)); } else if (type == String.class) { field.set(receiver, intent.getStringExtra(intentExtra.value())); } else if (type == Boolean[].class || type == boolean[].class) { field.set(receiver, intent.getBooleanArrayExtra(intentExtra.value())); } else if (type == Byte[].class || type == byte[].class) { field.set(receiver, intent.getByteArrayExtra(intentExtra.value())); } else if (type == Character[].class || type == char[].class) { field.set(receiver, intent.getCharArrayExtra(intentExtra.value())); } else if (type == Double[].class || type == double[].class) { field.set(receiver, intent.getDoubleArrayExtra(intentExtra.value())); } else if (type == Float[].class || type == float[].class) { field.set(receiver, intent.getFloatArrayExtra(intentExtra.value())); } else if (type == Integer[].class || type == int[].class) { field.set(receiver, intent.getIntArrayExtra(intentExtra.value())); } else if (type == Long[].class || type == long[].class) { field.set(receiver, intent.getLongArrayExtra(intentExtra.value())); } else if (type == Short[].class || type == short[].class) { field.set(receiver, intent.getShortArrayExtra(intentExtra.value())); } else if (type == String[].class) { field.set(receiver, intent.getStringArrayExtra(intentExtra.value())); } else if (Serializable.class.isAssignableFrom(type)) { field.set(receiver, intent.getSerializableExtra(intentExtra.value())); } else if (type == Bundle.class) { field.set(receiver, intent.getBundleExtra(intentExtra.value())); } } } catch (IllegalAccessException e) { e.printStackTrace(); } } } }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
/** * Returns true if the Intent was "Handled" * @param intent Input Intent//from w w w .j av a 2s .com */ public boolean handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { OpenPath searchIn = new OpenFile("/"); Bundle bundle = intent.getBundleExtra(SearchManager.APP_DATA); if (bundle != null && bundle.containsKey("path")) try { searchIn = FileManager.getOpenCache(bundle.getString("path"), false, null); } catch (IOException e) { searchIn = new OpenFile(bundle.getString("path")); } String query = intent.getStringExtra(SearchManager.QUERY); Logger.LogDebug("ACTION_SEARCH for \"" + query + "\" in " + searchIn); SearchResultsFragment srf = SearchResultsFragment.getInstance(searchIn, query); if (mViewPagerEnabled && mViewPagerAdapter != null) { mViewPagerAdapter.add(srf); setViewPageAdapter(mViewPagerAdapter, true); setCurrentItem(mViewPagerAdapter.getCount() - 1, true); } else { getSupportFragmentManager().beginTransaction().replace(R.id.content_frag, srf).commit(); } } else if ((Intent.ACTION_VIEW.equals(intent.getAction()) || Intent.ACTION_EDIT.equals(intent.getAction())) && intent.getData() != null) { OpenPath path = FileManager.getOpenCache(intent.getDataString(), this); if (editFile(path)) return true; } else if (intent.hasExtra("state")) { Bundle state = intent.getBundleExtra("state"); onRestoreInstanceState(state); } return false; }
From source file:android.app.Activity.java
/** * Called when the activity is starting. This is where most initialization * should go: calling {@link #setContentView(int)} to inflate the * activity's UI, using {@link #findViewById} to programmatically interact * with widgets in the UI, calling//from ww w . j a v a2 s .co m * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve * cursors for data being displayed, etc. * * <p>You can call {@link #finish} from within this function, in * which case onDestroy() will be immediately called without any of the rest * of the activity lifecycle ({@link #onStart}, {@link #onResume}, * {@link #onPause}, etc) executing. * * <p><em>Derived classes must call through to the super class's * implementation of this method. If they do not, an exception will be * thrown.</em></p> * * @param savedInstanceState If the activity is being re-initialized after * previously being shut down then this Bundle contains the data it most * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> * * @see #onStart * @see #onSaveInstanceState * @see #onRestoreInstanceState * @see #onPostCreate */ protected void onCreate(Bundle savedInstanceState) { if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); if (mLastNonConfigurationInstances != null) { mAllLoaderManagers = mLastNonConfigurationInstances.loaders; } if (mActivityInfo.parentActivityName != null) { if (mActionBar == null) { mEnableDefaultActionBarUp = true; } else { mActionBar.setDefaultDisplayHomeAsUpEnabled(true); } } if (isAvailable()) { /* if this device can use the platform */ Log.w("MIGRATOR", "This is " + getLocalClassName()); Intent intent = getIntent(); Bundle tmpBundle = intent.getBundleExtra("MIGRATED"); ArrayList<Bundle> stacked = intent.getParcelableArrayListExtra("MIGRATED STACK"); if (tmpBundle != null) { /* true if this Activity was migrated */ if (stacked != null) { /* true if this Activity called next Activity */ Intent next = new Intent(); Bundle nextBundle = stacked.get(0); next.setClassName(nextBundle.getString("MIGRATED PNAME"), nextBundle.getString("MIGRATED CNAME")); next.putExtra("MIGRATED", nextBundle); stacked.remove(0); int code = tmpBundle.getInt("MIGRATED REQUEST CODE"); Bundle option = nextBundle.getBundle("MIGRATED REQUEST OPTIONS"); if (!stacked.isEmpty()) { /* store for next Activity */ next.putParcelableArrayListExtra("MIGRATED STACK", stacked); } Log.w("MIGRATOR", "Start ForResult: code=" + code); mReceiverStackFlag = true; mStackedNextIntent = next; mStackedNextCode = code; mStackedNextOption = option; } else { /* for debug */ Log.w("MIGRATOR", "stack is null"); } savedInstanceState = null; mMigFlag = true; migratedState = tmpBundle; Intent tmpIntent = tmpBundle.getParcelable("MIGRATED_INTENT"); if (tmpIntent != null) { tmpIntent.setAction(Intent.ACTION_MIGRATE); setIntent(tmpIntent); } /* File handling */ ArrayList<String> tmpNames = tmpBundle.getStringArrayList("TARGET_FILE_NAME"); if (tmpNames != null) { FileWorker fw = new FileWorker(tmpNames.toArray(new String[tmpNames.size()]), FileWorker.WRITE_MODE); fw.start(); tmpNames = null; } Log.w("MIGRATOR", "successed migaration: " + tmpBundle.toString()); tmpBundle = null; } else { /* for debug */ Log.w("MIGRATOR", "tmpBundle is null"); } } if (savedInstanceState != null) { Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); mFragments.restoreAllState(p, mLastNonConfigurationInstances != null ? mLastNonConfigurationInstances.fragments : null); } mFragments.dispatchCreate(); getApplication().dispatchActivityCreated(this, savedInstanceState); mCalled = true; }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
private boolean decodeExtras(Intent intent) { String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null) { Uri uri = intent.getData();/* w w w. j a v a2 s. c o m*/ List<String> segmentList = uri.getPathSegments(); String accountId = segmentList.get(0); Collection<Account> accounts = Preferences.getPreferences(this).getAvailableAccounts(); for (Account account : accounts) { if (String.valueOf(account.getAccountNumber()).equals(accountId)) { mMessageReference = new MessageReference(); mMessageReference.accountUuid = account.getUuid(); mMessageReference.folderName = segmentList.get(1); mMessageReference.uid = segmentList.get(2); break; } } } else if (ACTION_SHORTCUT.equals(action)) { // Handle shortcut intents String specialFolder = intent.getStringExtra(EXTRA_SPECIAL_FOLDER); if (SearchAccount.UNIFIED_INBOX.equals(specialFolder)) { mSearch = SearchAccount.createUnifiedInboxAccount(this).getRelatedSearch(); } else if (SearchAccount.ALL_MESSAGES.equals(specialFolder)) { mSearch = SearchAccount.createAllMessagesAccount(this).getRelatedSearch(); } } else if (intent.getStringExtra(SearchManager.QUERY) != null) { // check if this intent comes from the system search ( remote ) if (Intent.ACTION_SEARCH.equals(intent.getAction())) { // Query was received from Search Dialog String query = intent.getStringExtra(SearchManager.QUERY); mSearch = new LocalSearch(getString(R.string.search_results)); mSearch.setManualSearch(true); mNoThreading = true; mSearch.or(new SearchCondition(Searchfield.SENDER, Attribute.CONTAINS, query)); mSearch.or(new SearchCondition(Searchfield.SUBJECT, Attribute.CONTAINS, query)); mSearch.or(new SearchCondition(Searchfield.MESSAGE_CONTENTS, Attribute.CONTAINS, query)); Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA); if (appData != null) { mSearch.addAccountUuid(appData.getString(EXTRA_SEARCH_ACCOUNT)); // searches started from a folder list activity will provide // an account, but no folder if (appData.getString(EXTRA_SEARCH_FOLDER) != null) { mSearch.addAllowedFolder(appData.getString(EXTRA_SEARCH_FOLDER)); } } else { mSearch.addAccountUuid(SearchSpecification.ALL_ACCOUNTS); } } } else { // regular LocalSearch object was passed mSearch = intent.getParcelableExtra(EXTRA_SEARCH); mNoThreading = intent.getBooleanExtra(EXTRA_NO_THREADING, false); } if (mMessageReference == null) { mMessageReference = intent.getParcelableExtra(EXTRA_MESSAGE_REFERENCE); } if (mMessageReference != null) { mSearch = new LocalSearch(); mSearch.addAccountUuid(mMessageReference.accountUuid); mSearch.addAllowedFolder(mMessageReference.folderName); } if (mSearch == null) { // We've most likely been started by an old unread widget String accountUuid = intent.getStringExtra("account"); String folderName = intent.getStringExtra("folder"); mSearch = new LocalSearch(folderName); mSearch.addAccountUuid((accountUuid == null) ? "invalid" : accountUuid); if (folderName != null) { mSearch.addAllowedFolder(folderName); } } Preferences prefs = Preferences.getPreferences(getApplicationContext()); String[] accountUuids = mSearch.getAccountUuids(); if (mSearch.searchAllAccounts()) { Account[] accounts = prefs.getAccounts(); mSingleAccountMode = (accounts.length == 1); if (mSingleAccountMode) { mAccount = accounts[0]; } } else { mSingleAccountMode = (accountUuids.length == 1); if (mSingleAccountMode) { mAccount = prefs.getAccount(accountUuids[0]); } } mSingleFolderMode = mSingleAccountMode && (mSearch.getFolderNames().size() == 1); if (mSingleAccountMode && (mAccount == null || !mAccount.isAvailable(this))) { Log.i(K9.LOG_TAG, "not opening MessageList of unavailable account"); onAccountUnavailable(); return false; } if (mSingleFolderMode) { mFolderName = mSearch.getFolderNames().get(0); } // now we know if we are in single account mode and need a subtitle mActionBarSubTitle.setVisibility((!mSingleFolderMode) ? View.GONE : View.VISIBLE); return true; }