List of usage examples for android.os Bundle putString
public void putString(@Nullable String key, @Nullable String value)
From source file:com.google.android.apps.iosched2.service.SyncService.java
@Override protected void onHandleIntent(Intent intent) { Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")"); final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER); if (receiver != null) receiver.send(STATUS_RUNNING, Bundle.EMPTY); final Context context = this; final SharedPreferences prefs = getSharedPreferences(Prefs.SCHED_SYNC, Context.MODE_PRIVATE); final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, VERSION_NONE); try {/*from w ww. j a v a 2 s . c o m*/ // Bulk of sync work, performed by executing several fetches from // local and online sources. final long startLocal = System.currentTimeMillis(); final boolean localParse = localVersion < VERSION_CURRENT; Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT); if (localParse) { // Load static local data mLocalExecutor.execute(Setup.BLOCKS_XML, new LocalBlocksHandler()); mLocalExecutor.execute(Setup.ROOMS_XML, new LocalRoomsHandler()); // mLocalExecutor.execute(R.xml.blocks, new LocalBlocksHandler()); // mLocalExecutor.execute(R.xml.rooms, new LocalRoomsHandler()); mLocalExecutor.execute(R.xml.tracks, new LocalTracksHandler()); mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler()); mLocalExecutor.execute(R.xml.sessions, new LocalSessionsHandler()); // Parse values from local cache first, since spreadsheet copy // or network might be down. mLocalExecutor.execute(context, Setup.EVENT_PREFIX + "cache-sessions.xml", new RemoteSessionsHandler()); mLocalExecutor.execute(context, Setup.EVENT_PREFIX + "cache-speakers.xml", new RemoteSpeakersHandler()); if (Setup.FEATURE_VENDORS_ON) { mLocalExecutor.execute(context, Setup.EVENT_PREFIX + "cache-vendors.xml", new RemoteVendorsHandler()); } // Save local parsed version prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit(); } Log.d(TAG, "local sync took " + (System.currentTimeMillis() - startLocal) + "ms"); // Always hit remote spreadsheet for any updates final long startRemote = System.currentTimeMillis(); mRemoteExecutor.executeGet(WORKSHEETS_URL, new RemoteWorksheetsHandler(mRemoteExecutor)); Log.d(TAG, "remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); } catch (Exception e) { Log.e(TAG, "Problem while syncing", e); if (receiver != null) { // Pass back error to surface listener final Bundle bundle = new Bundle(); bundle.putString(Intent.EXTRA_TEXT, e.toString()); receiver.send(STATUS_ERROR, bundle); } } // Announce success to any surface listener Log.d(TAG, "sync finished"); if (receiver != null) receiver.send(STATUS_FINISHED, Bundle.EMPTY); }
From source file:com.facebook.android.Example.java
/** Called when the activity is first created. */ @Override/* ww w. j a v a2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (APP_ID == null) { Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + "specified before running this example: see Example.java"); } setContentView(R.layout.main); mLoginButton = (LoginButton) findViewById(R.id.login); mText = (TextView) Example.this.findViewById(R.id.txt); mRequestButton = (Button) findViewById(R.id.requestButton); mPostButton = (Button) findViewById(R.id.postButton); mDeleteButton = (Button) findViewById(R.id.deletePostButton); mUploadButton = (Button) findViewById(R.id.uploadButton); mFacebook = new Facebook(APP_ID); mAsyncRunner = new AsyncFacebookRunner(mFacebook); SessionStore.restore(mFacebook, this); SessionEvents.addAuthListener(new SampleAuthListener()); SessionEvents.addLogoutListener(new SampleLogoutListener()); mLoginButton.init(this, mFacebook); mRequestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mAsyncRunner.request("me", new SampleRequestListener()); } }); mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); mUploadButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Bundle params = new Bundle(); params.putString("method", "photos.upload"); URL uploadFileUrl = null; try { uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); int length = conn.getContentLength(); byte[] imgData = new byte[length]; InputStream is = conn.getInputStream(); is.read(imgData); params.putByteArray("picture", imgData); } catch (IOException e) { e.printStackTrace(); } mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null); } }); mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); mPostButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mFacebook.dialog(Example.this, "feed", new SampleDialogListener()); } }); mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); }
From source file:com.jittr.android.facebook.Example.java
/** Called when the activity is first created. */ @Override//from w ww.ja v a2s .com public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (APP_ID == null) { Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + "specified before running this example: see Example.java"); } // mFacebook. setContentView(R.layout.mainfacebook); mLoginButton = (LoginButton) findViewById(R.id.login); mText = (TextView) Example.this.findViewById(R.id.txt); mRequestButton = (Button) findViewById(R.id.requestButton); mPostButton = (Button) findViewById(R.id.postButton); mDeleteButton = (Button) findViewById(R.id.deletePostButton); mUploadButton = (Button) findViewById(R.id.uploadButton); mFacebook = new Facebook(); mAsyncRunner = new AsyncFacebookRunner(mFacebook); SessionStore.restore(mFacebook, this); SessionEvents.addAuthListener(new SampleAuthListener()); SessionEvents.addLogoutListener(new SampleLogoutListener()); mLoginButton.init(mFacebook, PERMISSIONS); mRequestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mAsyncRunner.request("me", new SampleRequestListener()); } }); mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); mUploadButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Bundle params = new Bundle(); params.putString("method", "photos.upload"); URL uploadFileUrl = null; try { uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); int length = conn.getContentLength(); byte[] imgData = new byte[length]; InputStream is = conn.getInputStream(); is.read(imgData); params.putByteArray("picture", imgData); } catch (IOException e) { e.printStackTrace(); } mAsyncRunner.request(null, params, "POST", new SampleUploadListener()); } }); mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); mPostButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mFacebook.dialog(Example.this, "stream.publish", new SampleDialogListener()); } }); mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); }
From source file:edu.stanford.mobisocial.dungbeetle.facebook.FacebookInterfaceActivity.java
/** Called when the activity is first created. */ @Override/* www . ja v a2 s. c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (APP_ID == null) { Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + "specified before running this example: see FacebookInterfaceActivity.java"); } setContentView(R.layout.facebook); mLoginButton = (LoginButton) findViewById(R.id.login); mText = (TextView) FacebookInterfaceActivity.this.findViewById(R.id.txt); mRequestButton = (Button) findViewById(R.id.requestButton); mPostButton = (Button) findViewById(R.id.postButton); mDeleteButton = (Button) findViewById(R.id.deletePostButton); mUploadButton = (Button) findViewById(R.id.uploadButton); mFacebook = new Facebook(APP_ID); mAsyncRunner = new AsyncFacebookRunner(mFacebook); SessionStore.restore(mFacebook, this); SessionEvents.addAuthListener(new SampleAuthListener()); SessionEvents.addLogoutListener(new SampleLogoutListener()); mLoginButton.init(this, mFacebook); mRequestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mAsyncRunner.request("me", new SampleRequestListener()); } }); mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); mUploadButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Bundle params = new Bundle(); params.putString("method", "photos.upload"); URL uploadFileUrl = null; try { uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); int length = conn.getContentLength(); byte[] imgData = new byte[length]; InputStream is = conn.getInputStream(); is.read(imgData); params.putByteArray("picture", imgData); } catch (IOException e) { e.printStackTrace(); } mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null); } }); mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); mPostButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mFacebook.dialog(FacebookInterfaceActivity.this, "feed", new SampleDialogListener()); } }); mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); }
From source file:ch.christofbuechi.testgcm.MainActivity.java
public void onClick(final View view) { if (view == findViewById(R.id.send)) { new AsyncTask<Void, Void, String>() { @Override/*from w w w . j av a 2 s. com*/ protected String doInBackground(Void... params) { String msg = ""; try { Bundle data = new Bundle(); data.putString("my_message", "Hello World"); data.putString("my_action", "com.google.android.gcm.demo.app.ECHO_NOW"); String id = Integer.toString(msgId.incrementAndGet()); gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data); Log.i(this.getClass().getName(), "Button pressed"); msg = "Sent message"; sendRegistrationIdToBackend(); } catch (IOException ex) { msg = "Error :" + ex.getMessage(); } return msg; } @Override protected void onPostExecute(String msg) { mDisplay.append(msg + "\n"); } }.execute(null, null, null); } else if (view == findViewById(R.id.clear)) { mDisplay.setText(""); } }
From source file:com.DGSD.DGUtils.ImageDownloader.ImageLoader.java
public void notifyImageLoaded(String url, Bitmap bitmap) { Message message = new Message(); message.what = HANDLER_MESSAGE_ID;//from w w w . ja va2s . c o m Bundle data = new Bundle(); data.putString(IMAGE_URL_EXTRA, url); Bitmap image = bitmap; data.putParcelable(BITMAP_EXTRA, image); message.setData(data); handler.sendMessage(message); }
From source file:com.geozen.demo.foursquare.jiramot.Foursquare.java
public void dialog(Context context, String action, Bundle parameters, final DialogListener listener) { String endpoint = ""; parameters.putString("client_id", mClientId); parameters.putString("display", "touch"); if (action.equals(LOGIN)) { endpoint = AUTHENTICATE_URL; parameters.putString("client_secret", mClientSecret); parameters.putString("response_type", "token"); parameters.putString("redirect_uri", REDIRECT_URI); }/*w w w. java 2 s .c o m*/ String url = endpoint + "?" + Util.encodeUrl(parameters); if (context .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { Util.showAlert(context, "Error", "Application requires permission to access the Internet"); } else { mDialog = new FoursquareDialog(context, url, listener); mDialog.show(); } }
From source file:com.team1.soccerplayers.layout.PlayerInfoActivity.java
@Override public void onSaveInstanceState(Bundle savedInstanceState) { // Always call the superclass so it can save the view hierarchy state savedInstanceState.putString(STATE_PLAYER, playerName); super.onSaveInstanceState(savedInstanceState); // Parcelable state = c }
From source file:br.com.ufc.palestrasufc.twitter.Util.java
/** * Connect to an HTTP URL and return the response as a string. * /* ww w. j a va 2 s. c o m*/ * Note that the HTTP method override is used on non-GET requests. (i.e. * requests are made as "POST" with method specified in the body). * * @param url - the resource to open: must be a welformed URL * @param method - the HTTP method to use ("GET", "POST", etc.) * @param params - the query parameter for the URL (e.g. access_token=foo) * @return the URL contents as a String * @throws MalformedURLException - if the URL format is invalid * @throws IOException - if a network problem occurs */ public static String openUrl(String url, String method, Bundle params) throws MalformedURLException, IOException { // random string as boundary for multi-part http post String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; String endLine = "\r\n"; OutputStream os; if (method.equals("GET")) { url = url + "?" + encodeUrl(params); } Log.d("Twitter-Util", method + " URL: " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " TwitterAndroidSDK"); if (!method.equals("GET")) { Bundle dataparams = new Bundle(); for (String key : params.keySet()) { if (params.getByteArray(key) != null) { dataparams.putByteArray(key, params.getByteArray(key)); } } // use method override if (!params.containsKey("method")) { params.putString("method", method); } if (params.containsKey("access_token")) { String decoded_token = URLDecoder.decode(params.getString("access_token")); params.putString("access_token", decoded_token); } conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Connection", "Keep-Alive"); conn.connect(); os = new BufferedOutputStream(conn.getOutputStream()); os.write(("--" + strBoundary + endLine).getBytes()); os.write((encodePostBody(params, strBoundary)).getBytes()); os.write((endLine + "--" + strBoundary + endLine).getBytes()); if (!dataparams.isEmpty()) { for (String key : dataparams.keySet()) { os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes()); os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes()); os.write(dataparams.getByteArray(key)); os.write((endLine + "--" + strBoundary + endLine).getBytes()); } } os.flush(); } String response = ""; try { response = read(conn.getInputStream()); } catch (FileNotFoundException e) { // Error Stream contains JSON that we can parse to a FB error response = read(conn.getErrorStream()); } return response; }
From source file:com.facebook.FacebookAppLinkResolver.java
/** * Asynchronously resolves App Link data for multiple Urls * * @param uris A list of Uri objects to resolve into App Links * @return A Task that, when successful, will return a Map of Uri->AppLink for each Uri that was successfully * resolved into an App Link. Uris that could not be resolved into App Links will not be present in the Map. * In the case of general server errors, the task will be completed with the corresponding error. *///from ww w. j a v a 2 s.c o m public Task<Map<Uri, AppLink>> getAppLinkFromUrlsInBackground(List<Uri> uris) { final Map<Uri, AppLink> appLinkResults = new HashMap<Uri, AppLink>(); final HashSet<Uri> urisToRequest = new HashSet<Uri>(); StringBuilder graphRequestFields = new StringBuilder(); for (Uri uri : uris) { AppLink appLink = null; synchronized (cachedAppLinks) { appLink = cachedAppLinks.get(uri); } if (appLink != null) { appLinkResults.put(uri, appLink); } else { if (!urisToRequest.isEmpty()) { graphRequestFields.append(','); } graphRequestFields.append(uri.toString()); urisToRequest.add(uri); } } if (urisToRequest.isEmpty()) { return Task.forResult(appLinkResults); } final Task<Map<Uri, AppLink>>.TaskCompletionSource taskCompletionSource = Task.create(); Bundle appLinkRequestParameters = new Bundle(); appLinkRequestParameters.putString("ids", graphRequestFields.toString()); appLinkRequestParameters.putString("fields", String.format("%s.fields(%s,%s)", APP_LINK_KEY, APP_LINK_ANDROID_TARGET_KEY, APP_LINK_WEB_TARGET_KEY)); Request appLinkRequest = new Request(null, /* Session */ "", /* Graph path */ appLinkRequestParameters, /* Query parameters */ null, /* HttpMethod */ new Request.Callback() { /* Callback */ @Override public void onCompleted(Response response) { FacebookRequestError error = response.getError(); if (error != null) { taskCompletionSource.setError(error.getException()); return; } GraphObject responseObject = response.getGraphObject(); JSONObject responseJson = responseObject != null ? responseObject.getInnerJSONObject() : null; if (responseJson == null) { taskCompletionSource.setResult(appLinkResults); return; } for (Uri uri : urisToRequest) { String uriString = uri.toString(); if (!responseJson.has(uriString)) { continue; } JSONObject urlData = null; try { urlData = responseJson.getJSONObject(uri.toString()); JSONObject appLinkData = urlData.getJSONObject(APP_LINK_KEY); JSONArray rawTargets = appLinkData.getJSONArray(APP_LINK_ANDROID_TARGET_KEY); int targetsCount = rawTargets.length(); List<AppLink.Target> targets = new ArrayList<AppLink.Target>(targetsCount); for (int i = 0; i < targetsCount; i++) { AppLink.Target target = getAndroidTargetFromJson(rawTargets.getJSONObject(i)); if (target != null) { targets.add(target); } } Uri webFallbackUrl = getWebFallbackUriFromJson(uri, appLinkData); AppLink appLink = new AppLink(uri, targets, webFallbackUrl); appLinkResults.put(uri, appLink); synchronized (cachedAppLinks) { cachedAppLinks.put(uri, appLink); } } catch (JSONException e) { // The data for this uri was missing or badly formed. continue; } } taskCompletionSource.setResult(appLinkResults); } }); appLinkRequest.executeAsync(); return taskCompletionSource.getTask(); }