List of usage examples for android.content Intent getSerializableExtra
public Serializable getSerializableExtra(String name)
From source file:com.msopentech.applicationgateway.EnterpriseBrowserActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { try {// w ww. j av a 2 s . c o m super.onActivityResult(requestCode, resultCode, data); // The data argument can be null if the user simply exited the // activity by clicking back or cancel. if (data == null) { return; } Bundle extras = data.getExtras(); if (extras == null) { return; } switch (requestCode) { case ACTIVITY_SIGN_IN: { if (resultCode != RESULT_CANCELED) { mCustomTabHost.clearAllHistory(); mTraits = (ConnectionTraits) data .getSerializableExtra(EnterpriseBrowserActivity.EXTRAS_TRAITS_KEY); if (mTraits.sessionID == null && mTraits.token == null && mTraits.agent.getAgentId() == null) { // Authentication failed. Have to make user make another attempt while informing of error reason. showSignIn(null, true); } else { mStatusButtonView.setImageResource(R.drawable.connection_green); if (mIsSigninRequired) { mIsSigninRequired = false; } // Switch to agent specific stored data. PersistenceManager.initialize(mTraits.agent.getAgentId()); } } else { if (mTraits == null || mTraits.isError()) { // Will get here if error was received on signIn screen and user pressed 'cancel' there. mIsSigninRequired = true; if (mTraits != null) { mTraits.sessionID = null; mTraits.token = null; } } } break; } case ACTIVITY_ADVANCED_ROUTER_SETTINGS: { String url = data.getStringExtra(CLOUD_CONNECTION_HOST_PREFIX); Boolean useSmartBrowser = data.getBooleanExtra(EXTRAS_SMART_BROWSER_ON, false); if (!CLOUD_CONNECTION_HOST_PREFIX.contentEquals(url) || mUseSmartBrowser != useSmartBrowser) { CLOUD_CONNECTION_HOST_PREFIX = url; CLOUD_BROWSER_URL = CLOUD_CONNECTION_HOST_PREFIX; mUseSmartBrowser = useSmartBrowser; AuthPreferences.storeUseSmartBrowser(mUseSmartBrowser); if (useSmartBrowser) { CLOUD_BROWSER_URL = CLOUD_BROWSER_URL + CLOUD_CONNECTION_HOST_SMARTBROWSER_POSTFIX; } else { CLOUD_BROWSER_URL = CLOUD_BROWSER_URL + CLOUD_CONNECTION_HOST_BROWSER_POSTFIX; } AuthPreferences.storePreferredRouter(url); mStatusButtonView.setImageResource(R.drawable.connection_red); mCustomTabHost.clearAllHistory(); showSignIn(null, false); } Boolean clearCookies = data.getBooleanExtra(EXTRAS_CLEAR_COOKIES_ON, false); if (clearCookies) { CookieManager.getInstance().removeAllCookie(); } break; } case ACTIVITY_BOOKMARKS_AND_HISTORY: { String url = data.getStringExtra(EXTRAS_URL_KEY); if (!TextUtils.isEmpty(url)) { goToUrl(url); } break; } case ACTIVITY_AGENTS: { // Since the agent has changed, we can no longer use the old // history in WebViewClient with the old SessionID. mCustomTabHost.clearAllHistory(); mReloadButtonView.setEnabled(false); ConnectionTraits traits = (ConnectionTraits) data.getSerializableExtra(EXTRAS_TRAITS_KEY); if (traits != null && traits.sessionID != null) { mTraits.sessionID = traits.sessionID; mStatusButtonView.setImageResource(R.drawable.connection_green); // Should never be null if (traits.agent != null) { if (traits.agent.getAgentId() != null) { mTraits.agent.setAgentId(traits.agent.getAgentId()); // Switch to agent specific stored data. PersistenceManager.dropContent(PersistenceManager.ContentType.HISTORY); PersistenceManager.initialize(mTraits.agent.getAgentId()); } if (traits.agent.getDisplayName() != null) { mTraits.agent.setDisplayName(traits.agent.getDisplayName()); } } } break; } case ACTIVITY_CLIENT_STATUS_AND_DIAGNOSTICS: { String browse = data.getStringExtra(EXTRAS_BROWSE_TO_ROUTER_SYSTEM_PAGE_KEY); if (!(browse == null || browse.isEmpty())) mActiveWebView.loadUrl(CLOUD_CONNECTION_HOST_PREFIX + "system"); break; } } } catch (Exception e) { Utility.showAlertDialog(EnterpriseBrowserActivity.class.getSimpleName() + ".onActivityResult(): Failed. " + e.toString(), EnterpriseBrowserActivity.this); } }
From source file:com.nttec.everychan.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Logger.d(TAG, "main activity creating"); settings = MainApplication.getInstance().settings.getStaticSettings(); autohideRulesHash = MainApplication.getInstance().settings.getAutohideRulesJson().hashCode(); rootViewWeight = MainApplication.getInstance().settings.getRootViewWeight(); tabsPanelRight = MainApplication.getInstance().settings.isTabsPanelOnRight(); openSpoilers = MainApplication.getInstance().settings.openSpoilers(); highlightSubscriptions = MainApplication.getInstance().settings.highlightSubscriptions(); swipeToHideThread = MainApplication.getInstance().settings.swipeToHideThread(); isHorizontalOrientation = getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; (theme = MainApplication.getInstance().settings.getTheme()).setTo(this); super.onCreate(savedInstanceState); if (MainApplication.getInstance().settings.showSidePanel()) { setContentView(tabsPanelRight ? R.layout.main_activity_tablet_right : R.layout.main_activity_tablet); LinearLayout.LayoutParams sidebarLayoutParams = (LinearLayout.LayoutParams) findViewById(R.id.sidebar) .getLayoutParams();/*from ww w .j a v a2s. c o m*/ Point displaySize = AppearanceUtils.getDisplaySize(getWindowManager().getDefaultDisplay()); int rootWidth = (int) (displaySize.x * rootViewWeight); sidebarLayoutParams.width = displaySize.x - rootWidth; findViewById(R.id.sidebar).setLayoutParams(sidebarLayoutParams); } else { setContentView(R.layout.main_activity_drawer); updateTabPanelTabletWeight(); } initDrawer(); View[] sidebarButtons = new View[] { findViewById(R.id.sidebar_btn_newtab), findViewById(R.id.sidebar_btn_history), findViewById(R.id.sidebar_btn_favorites) }; hiddenTabsSection = new HiddenTabsSection(sidebarButtons); DragSortListView list = (DragSortListView) findViewById(R.id.sidebar_tabs_list); TabsState state = MainApplication.getInstance().tabsState; tabsAdapter = initTabsListView(list, state); handleUriIntent(getIntent()); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) { Logger.e(TAG, "received broadcast with NULL action"); return; } if (action.equals(PostingService.BROADCAST_ACTION_STATUS)) { int progress = intent.getIntExtra(PostingService.EXTRA_BROADCAST_PROGRESS_STATUS, -1); switch (progress) { case PostingService.BROADCAST_STATUS_SUCCESS: UrlHandler.open(intent.getStringExtra(PostingService.EXTRA_TARGET_URL), MainActivity.this); notificationManager.cancel(PostingService.POSTING_NOTIFICATION_ID); break; case PostingService.BROADCAST_STATUS_ERROR: Intent toPostForm = new Intent(MainActivity.this, PostFormActivity.class); toPostForm.putExtra(PostingService.EXTRA_PAGE_HASH, intent.getStringExtra(PostingService.EXTRA_PAGE_HASH)); toPostForm.putExtra(PostingService.EXTRA_SEND_POST_MODEL, intent.getSerializableExtra(PostingService.EXTRA_SEND_POST_MODEL)); toPostForm.putExtra(PostingService.EXTRA_BOARD_MODEL, intent.getSerializableExtra(PostingService.EXTRA_BOARD_MODEL)); toPostForm.putExtra(PostingService.EXTRA_RETURN_FROM_SERVICE, true); toPostForm.putExtra(PostingService.EXTRA_RETURN_REASON, intent.getIntExtra(PostingService.EXTRA_RETURN_REASON, 0)); String error = intent.getStringExtra(PostingService.EXTRA_RETURN_REASON_ERROR); Serializable interactiveException = intent .getSerializableExtra(PostingService.EXTRA_RETURN_REASON_INTERACTIVE_EXCEPTION); if (error != null) { toPostForm.putExtra(PostingService.EXTRA_RETURN_REASON_ERROR, error); } if (interactiveException != null) { toPostForm.putExtra(PostingService.EXTRA_RETURN_REASON_INTERACTIVE_EXCEPTION, interactiveException); } startActivity(toPostForm); notificationManager.cancel(PostingService.POSTING_NOTIFICATION_ID); break; } } else if (action.equals(TabsTrackerService.BROADCAST_ACTION_NOTIFY)) { tabsAdapter.notifyDataSetChanged(false); TabsTrackerService.clearUnread(); } } }; intentFilter = new IntentFilter(); intentFilter.addAction(PostingService.BROADCAST_ACTION_STATUS); intentFilter.addAction(TabsTrackerService.BROADCAST_ACTION_NOTIFY); if (!TabsTrackerService.isRunning() && MainApplication.getInstance().settings.isAutoupdateEnabled()) startService(new Intent(this, TabsTrackerService.class)); if (MainApplication.getInstance().settings.isSFWRelease()) NewsReader.checkNews(this); }
From source file:com.quran.labs.androidquran.service.AudioService.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.//from w w w.ja va 2 s.com */ @Override public int onStartCommand(Intent intent, int flags, int startId) { String action = intent.getAction(); if (action.equals(ACTION_CONNECT)) { if (mState == State.Stopped) { processStopRequest(); } else { int sura = -1; int ayah = -1; int state = AudioUpdateIntent.STOPPED; if (mState == State.Paused) { state = AudioUpdateIntent.PAUSED; } else if (mState != State.Stopped) { state = AudioUpdateIntent.PLAYING; } if (mState != State.Stopped) { if (mAudioRequest != null) { sura = mAudioRequest.getCurrentSura(); ayah = mAudioRequest.getCurrentAyah(); } } Intent updateIntent = new Intent(AudioUpdateIntent.INTENT_NAME); updateIntent.putExtra(AudioUpdateIntent.STATUS, state); updateIntent.putExtra(AudioUpdateIntent.SURA, sura); updateIntent.putExtra(AudioUpdateIntent.AYAH, ayah); mBroadcastManager.sendBroadcast(updateIntent); } } else if (action.equals(ACTION_PLAYBACK)) { Serializable playInfo = intent.getSerializableExtra(EXTRA_PLAY_INFO); if (playInfo != null && playInfo instanceof AudioRequest) { if (mState == State.Stopped || !intent.getBooleanExtra(EXTRA_IGNORE_IF_PLAYING, false)) { mAudioRequest = (AudioRequest) playInfo; } } if (intent.getBooleanExtra(EXTRA_STOP_IF_PLAYING, false)) { if (mPlayer != null) { mPlayer.stop(); } mState = State.Stopped; } processTogglePlaybackRequest(); } else if (action.equals(ACTION_PLAY)) { processPlayRequest(); } 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_UPDATE_REPEAT)) { Serializable repeatInfo = intent.getSerializableExtra(EXTRA_REPEAT_INFO); if (repeatInfo != null && mAudioRequest != null) { if (repeatInfo instanceof RepeatInfo) { mAudioRequest.setRepeatInfo((RepeatInfo) repeatInfo); } } } return START_NOT_STICKY; // Means we started the service, but don't want // it to restart in case it's killed. }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null && intent.hasExtra(EXTRA_COMMAND) && intent.getSerializableExtra(EXTRA_COMMAND) == Command.set) { set(intent);// w w w . ja v a 2 s . c om return START_STICKY; } // Keep awake getLock(this).acquire(); // Handle service restart if (intent == null) { Log.i(TAG, "Restart"); // Get enabled SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean enabled = prefs.getBoolean("enabled", false); // Recreate intent intent = new Intent(this, ServiceSinkhole.class); intent.putExtra(EXTRA_COMMAND, enabled ? Command.start : Command.stop); } if (ACTION_HOUSE_HOLDING.equals(intent.getAction())) intent.putExtra(EXTRA_COMMAND, Command.householding); Command cmd = (Command) intent.getSerializableExtra(EXTRA_COMMAND); String reason = intent.getStringExtra(EXTRA_REASON); Log.i(TAG, "Start intent=" + intent + " command=" + cmd + " reason=" + reason + " vpn=" + (vpn != null) + " user=" + (Process.myUid() / 100000)); commandHandler.queue(intent); return START_STICKY; }
From source file:com.trk.aboutme.facebook.Session.java
/** * Provides an implementation for {@link Activity#onActivityResult * onActivityResult} that updates the Session based on information returned * during the authorization flow. The Activity that calls open or * requestNewPermissions should forward the resulting onActivityResult call here to * update the Session state based on the contents of the resultCode and * data.//from w w w.ja v a2s .com * * @param currentActivity The Activity that is forwarding the onActivityResult call. * @param requestCode The requestCode parameter from the forwarded call. When this * onActivityResult occurs as part of Facebook authorization * flow, this value is the activityCode passed to open or * authorize. * @param resultCode An int containing the resultCode parameter from the forwarded * call. * @param data The Intent passed as the data parameter from the forwarded * call. * @return A boolean indicating whether the requestCode matched a pending * authorization request for this Session. */ public final boolean onActivityResult(Activity currentActivity, int requestCode, int resultCode, Intent data) { Validate.notNull(currentActivity, "currentActivity"); initializeStaticContext(currentActivity); synchronized (lock) { if (pendingRequest == null || (requestCode != pendingRequest.getRequestCode())) { return false; } } AccessToken newToken = null; Exception exception = null; if (data != null) { AuthorizationClient.Result result = (AuthorizationClient.Result) data .getSerializableExtra(LoginActivity.RESULT_KEY); if (result != null) { // This came from LoginActivity. handleAuthorizationResult(resultCode, result); return true; } else if (authorizationClient != null) { // Delegate to the auth client. authorizationClient.onActivityResult(requestCode, resultCode, data); return true; } } else if (resultCode == Activity.RESULT_CANCELED) { exception = new FacebookOperationCanceledException("User canceled operation."); } finishAuthOrReauth(newToken, exception); return true; }
From source file:im.getsocial.testapp.MainActivity.java
private void handleInviteActivityResult(int resultCode, Intent data) { if (resultCode == RESULT_OK) { SmartInviteViewBuilder smartInviteViewBuilder = getSocial.createSmartInviteView(); if (data.hasExtra(InviteActivity.EXTRA_SUBJECT)) { smartInviteViewBuilder.setSubject(data.getStringExtra(InviteActivity.EXTRA_SUBJECT)); }// w w w . j a v a 2 s.c o m if (data.hasExtra(InviteActivity.EXTRA_TEXT)) { smartInviteViewBuilder.setText(data.getStringExtra(InviteActivity.EXTRA_TEXT)); } if (data.hasExtra(InviteActivity.EXTRA_BUNDLE)) { smartInviteViewBuilder.setReferralData( (HashMap<String, String>) data.getSerializableExtra(InviteActivity.EXTRA_BUNDLE)); } if (data.hasExtra(InviteActivity.EXTRA_IMAGE)) { smartInviteViewBuilder.setImageUrl(data.getStringExtra(InviteActivity.EXTRA_IMAGE)); } smartInviteViewBuilder.show(); } }
From source file:dentex.youtube.downloader.DashboardActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { BugSenseHandler.leaveBreadcrumb("DashboardActivity_filechooser_RESULT_OK"); @SuppressWarnings("unchecked") List<LocalFile> files = (List<LocalFile>) data.getSerializableExtra(FileChooserActivity._Results); String path = data.getStringExtra("path"); String name = data.getStringExtra("name"); File in = new File(path, name); final File chooserSelection = files.get(0); //Utils.logger("d", "file-chooser selection: " + chooserFolder.getPath(), DEBUG_TAG); //Utils.logger("d", "origin file's folder: " + currentItem.getPath(), DEBUG_TAG); switch (requestCode) { case 1: // ------------- > COPY File out1 = new File(chooserSelection, name); if (chooserSelection.getPath().equals(currentItem.getPath())) { out1 = new File(chooserSelection, "copy_" + currentItem.getFilename()); }/* www .j a v a 2s. com*/ if (!out1.exists()) { switch (Utils.pathCheck(chooserSelection)) { case 0: // Path on standard sdcard new AsyncCopy().execute(in, out1); break; case 1: // Path not writable PopUps.showPopUp(getString(R.string.system_warning_title), getString(R.string.system_warning_msg), "alert", DashboardActivity.this); break; case 2: // Path not mounted Toast.makeText(DashboardActivity.this, getString(R.string.sdcard_unmounted_warning), Toast.LENGTH_SHORT).show(); } } else { PopUps.showPopUp(getString(R.string.long_press_warning_title), getString(R.string.long_press_warning_msg2), "info", DashboardActivity.this); } break; case 2: // ------------- > MOVE File out2 = new File(chooserSelection, name); if (!chooserSelection.getPath().equals(currentItem.getPath())) { if (!out2.exists()) { switch (Utils.pathCheck(chooserSelection)) { case 0: // Path on standard sdcard new AsyncMove().execute(in, out2); break; case 1: // Path not writable PopUps.showPopUp(getString(R.string.system_warning_title), getString(R.string.system_warning_msg), "alert", DashboardActivity.this); break; case 2: // Path not mounted Toast.makeText(DashboardActivity.this, getString(R.string.sdcard_unmounted_warning), Toast.LENGTH_SHORT).show(); } } else { PopUps.showPopUp(getString(R.string.long_press_warning_title), getString(R.string.long_press_warning_msg2), "info", DashboardActivity.this); } } else { PopUps.showPopUp(getString(R.string.long_press_warning_title), getString(R.string.long_press_warning_msg), "info", DashboardActivity.this); } break; case 3: // ------------- > MENU_BACKUP new Thread(new Runnable() { @Override public void run() { Looper.prepare(); String date = new SimpleDateFormat("yyyy-MM-dd'_'HH-mm-ss", Locale.US).format(new Date()); final File backup = new File(chooserSelection, date + "_" + YTD.JSON_FILENAME); try { Utils.copyFile(YTD.JSON_FILE, backup); Toast.makeText(sDashboard, getString(R.string.menu_backup_result_ok), Toast.LENGTH_SHORT).show(); } catch (IOException e) { Log.e(DEBUG_TAG, "IOException @ MENU_BACKUP: " + e.getMessage()); Toast.makeText(sDashboard, getString(R.string.menu_backup_result_failed), Toast.LENGTH_LONG).show(); } Looper.loop(); } }).start(); break; case 4: // ------------- > MENU_RESTORE AsyncRestore ar = new AsyncRestore(); ar.execute(chooserSelection); break; case 5: // ------------- > MENU_IMPORT AsyncImport ai = new AsyncImport(); ai.execute(chooserSelection); } } }
From source file:com.facebook.Session.java
/** * Provides an implementation for {@link Activity#onActivityResult * onActivityResult} that updates the Session based on information returned * during the authorization flow. The Activity that calls open or * requestNewPermissions should forward the resulting onActivityResult call here to * update the Session state based on the contents of the resultCode and * data.//from w w w. ja va 2s. com * * @param currentActivity The Activity that is forwarding the onActivityResult call. * @param requestCode The requestCode parameter from the forwarded call. When this * onActivityResult occurs as part of Facebook authorization * flow, this value is the activityCode passed to open or * authorize. * @param resultCode An int containing the resultCode parameter from the forwarded * call. * @param data The Intent passed as the data parameter from the forwarded * call. * @return A boolean indicating whether the requestCode matched a pending * authorization request for this Session. */ public final boolean onActivityResult(Activity currentActivity, int requestCode, int resultCode, Intent data) { Validate.notNull(currentActivity, "currentActivity"); initializeStaticContext(currentActivity); synchronized (lock) { if (pendingAuthorizationRequest == null || (requestCode != pendingAuthorizationRequest.getRequestCode())) { return false; } } Exception exception = null; AuthorizationClient.Result.Code code = AuthorizationClient.Result.Code.ERROR; if (data != null) { AuthorizationClient.Result result = (AuthorizationClient.Result) data .getSerializableExtra(LoginActivity.RESULT_KEY); if (result != null) { // This came from LoginActivity. handleAuthorizationResult(resultCode, result); return true; } else if (authorizationClient != null) { // Delegate to the auth client. authorizationClient.onActivityResult(requestCode, resultCode, data); return true; } } else if (resultCode == Activity.RESULT_CANCELED) { exception = new FacebookOperationCanceledException("User canceled operation."); code = AuthorizationClient.Result.Code.CANCEL; } if (exception == null) { exception = new FacebookException("Unexpected call to Session.onActivityResult"); } logAuthorizationComplete(code, null, exception); finishAuthOrReauth(null, exception); return true; }