List of usage examples for android.os Bundle putString
public void putString(@Nullable String key, @Nullable String value)
From source file:com.devsh.androidlogin.library.FacebookLoginUtil.java
private FacebookLoginUtil() { callbackManager = CallbackManager.Factory.create(); accessTokenTracker = new AccessTokenTracker() { @Override// www . ja va 2s . c o m protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) { if (oldAccessToken == null && currentAccessToken != null) { loginCallback.onCallback(currentAccessToken); } if (oldAccessToken != null && currentAccessToken == null) { SharedData.clearSharedPreference(sContext); logoutCallback.onCallback(currentAccessToken); } if (oldAccessToken != null && currentAccessToken != null) { updateTokenCallback.onCallback(currentAccessToken); } } }; // profileTracker = new ProfileTracker() { // @Override // protected void onCurrentProfileChanged( // Profile oldProfile, // Profile currentProfile) { // Log.i(TAG, "oldProfile" + oldProfile + "currentProfile" + currentProfile); // } // }; loginCallback = nullCallback; logoutCallback = nullCallback; updateTokenCallback = nullCallback; // LoginResultCallback LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Profile profile = Profile.getCurrentProfile(); final AccessToken accessToken = loginResult.getAccessToken(); if (profile != null) { SharedData.putAccountProvider(sContext, SharedData.PROVIDER_FACEBOOK); SharedData.putAccountIdToken(sContext, accessToken.getToken()); SharedData.putAccountId(sContext, profile.getId()); SharedData.putAccountUserName(sContext, profile.getName()); SharedData.putAccountUserPhoto(sContext, profile.getProfilePictureUri(200, 200).toString()); // No email loginResultCallback.onSuccess(loginResult); } else { final LoginResult loginResult2 = loginResult; GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { SharedData.putAccountProvider(sContext, SharedData.PROVIDER_FACEBOOK); SharedData.putAccountIdToken(sContext, accessToken.getToken()); SharedData.putAccountId(sContext, accessToken.getUserId()); try { String userName = response.getJSONObject().getString("name"); String userPhoto = object.getJSONObject("picture").getJSONObject("data") .getString("url"); String userEmail = object.getString("email"); SharedData.putAccountUserName(sContext, userName); SharedData.putAccountUserPhoto(sContext, userPhoto); SharedData.putAccountUserEmail(sContext, userEmail); } catch (JSONException e) { e.printStackTrace(); } loginResultCallback.onSuccess(loginResult2); } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,email,picture"); request.setParameters(parameters); request.executeAsync(); } } @Override public void onCancel() { SharedData.clearSharedPreference(sContext); loginResultCallback.onCancel(); } @Override public void onError(FacebookException error) { SharedData.clearSharedPreference(sContext); loginResultCallback.onError(error); } }); }
From source file:com.facebook.AccessToken.java
/** * Creates a new AccessToken using the information contained in an Intent populated by the * Facebook application in order to launch a native link. For more information on native * linking, please see https://developers.facebook.com/docs/mobile/android/deep_linking/. * * @param intent the Intent that was used to start an Activity; must not be null * @param applicationId the ID of the Facebook Application associated with this access token *//*from w w w .j a v a 2s.c om*/ public static void createFromNativeLinkingIntent(Intent intent, final String applicationId, final AccessTokenCreationCallback accessTokenCallback) { Validate.notNull(intent, "intent"); if (intent.getExtras() == null) { accessTokenCallback.onError(new FacebookException("No extras found on intent")); return; } final Bundle extras = new Bundle(intent.getExtras()); String accessToken = extras.getString(ACCESS_TOKEN_KEY); if (accessToken == null || accessToken.isEmpty()) { accessTokenCallback.onError(new FacebookException("No access token found on intent")); return; } String userId = extras.getString(USER_ID_KEY); // Old versions of facebook for android don't provide the UserId. Obtain the id if missing if (userId == null || userId.isEmpty()) { Utility.getGraphMeRequestWithCacheAsync(accessToken, new Utility.GraphMeRequestWithCacheCallback() { @Override public void onSuccess(JSONObject userInfo) { try { String userId = userInfo.getString("id"); extras.putString(USER_ID_KEY, userId); accessTokenCallback.onSuccess(createFromBundle(null, extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date(), applicationId)); } catch (JSONException ex) { accessTokenCallback.onError( new FacebookException("Unable to generate access token due to missing user id")); } } @Override public void onFailure(FacebookException error) { accessTokenCallback.onError(error); } }); } else { accessTokenCallback.onSuccess(createFromBundle(null, extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB, new Date(), applicationId)); } }
From source file:com.facebook.InsightsLogger.java
/** * Log, or "Fire" a Conversion Pixel. Conversion Pixels are used for Ads Conversion Tracking. See * https://www.facebook.com/help/435189689870514 to learn more. * * @param pixelId Numeric ID for the conversion pixel to be logged. See * https://www.facebook.com/help/435189689870514 to learn how to create a conversion pixel. * @param valueOfPixel Value of what the logging of this pixel is worth to the calling app. The currency that this * is expressed in doesn't matter, so long as it is consistent across all logging for this * pixel. This value will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). *///from w w w .j a va 2s. c o m public void logConversionPixel(String pixelId, double valueOfPixel) { if (pixelId == null) { notifyDeveloperError("pixelID cannot be null"); return; } Bundle parameters = new Bundle(); parameters.putString(EVENT_PARAMETER_PIXEL_ID, pixelId); parameters.putDouble(EVENT_PARAMETER_PIXEL_VALUE, valueOfPixel); logEventNow(EVENT_NAME_LOG_CONVERSION_PIXEL, valueOfPixel, parameters); }
From source file:edu.mit.media.funf.funftowotk.MainPipeline.java
@Override public void onDataReceived(Bundle data) { String android_id = Secure.getString(getBaseContext().getContentResolver(), Secure.ANDROID_ID); data.putString("Device_ID", android_id); super.onDataReceived(data); if (MainActivity.real_time) { data.putString("WoTK_ID", "coffeejack"); //add WotKit info here String dataJson = getBundleSerializer().serialize(data); if (checkValidData(data)) { Log.i("DataLog", dataJson); RequestTask rq = new RequestTask(); rq.execute(MainActivity.REAL_TIME_UPLOAD_URL, "POST", "application/json", dataJson); } else {/*from ww w. j a v a2s . com*/ Log.i("DataLog", "Invalid Data, not sending"); } } incrementCount(); }
From source file:cn.newgxu.android.bbs.ui.TopicFragment.java
@Override public void onSaveInstanceState(Bundle outState) { if (this.sendReply != null) { Editable text = this.sendReply.getText(); if (text != null) { outState.putString(REPLY_CONTENT, text.toString()); }/* w w w.j a v a 2s. c o m*/ } super.onSaveInstanceState(outState); }
From source file:com.enefsy.facebook.Util.java
/** * Connect to an HTTP URL and return the response as a string. * * 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/* w w w. j av a 2 s .co m*/ * @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); } HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK"); if (!method.equals("GET")) { Bundle dataparams = new Bundle(); for (String key : params.keySet()) { Object parameter = params.get(key); if (parameter instanceof byte[]) { dataparams.putByteArray(key, (byte[]) parameter); } } // 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.easy.facebook.android.facebook.FBLoginManager.java
public void dialog(Context context, String action, Bundle parameters, final LoginListener listener) { String endpoint = "https://m.facebook.com/dialog/" + action; parameters.putString("display", "touch"); parameters.putString("redirect_uri", "fbconnect://success"); if (action.equals("oauth")) { parameters.putString("type", "user_agent"); parameters.putString("client_id", appID); } else {/*from w w w . j a va 2s .co m*/ parameters.putString("app_id", appID); } String url = endpoint + "?" + Util.encodeUrl(parameters); new FBLoginWithOutApi(context, url, listener, this).show(); }
From source file:com.redhorse.quickstart.AppAll.java
public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, final long arg3) { // TODO Auto-generated method stub // ResolveInfo info = mApps.get(position); ////from w w w .j a va 2s .c o m // Intent i = getIntent(); // Bundle b = new Bundle(); // b.putString("msg", "open"); // b.putString("packageName", info.activityInfo.packageName); // b.putString("name", info.activityInfo.name); // i.putExtras(b); // this.setResult(RESULT_OK, i); // dbStart.close(); // this.finish(); // TODO Auto-generated method stub AlertDialog opDialog = new AlertDialog.Builder(AppAll.this).setTitle("") .setItems(R.array.select_dialog_items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { /* User clicked so do some stuff */ String[] items = getResources().getStringArray(R.array.select_dialog_items); ResolveInfo info = null; ResolveInfo selectedinfo = null; switch (which) { case ITEM_ID_DELETE: selectedinfo = mApps.get(arg2); String packageName = selectedinfo.activityInfo.packageName; String name = selectedinfo.activityInfo.name; Iterator it1 = mAllApps.iterator(); while (it1.hasNext()) { info = (ResolveInfo) it1.next(); if (packageName.equals(info.activityInfo.packageName) && name.equalsIgnoreCase(info.activityInfo.name)) { Intent intent = new Intent(); Uri packageURI = Uri.parse("package:" + packageName); Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI); startActivityForResult(uninstallIntent, STARTUNINSTALL_REQUEST); break; } } break; case ITEM_ID_OPEN: info = mApps.get(arg2); Intent i = getIntent(); Bundle b = new Bundle(); b.putString("msg", "open"); b.putString("packageName", info.activityInfo.packageName); b.putString("name", info.activityInfo.name); i.putExtras(b); AppAll.this.setResult(RESULT_OK, i); dbStart.close(); AppAll.this.finish(); break; } } }).create(); opDialog.show(); }
From source file:com.captix.scan.social.facebook.Util.java
/** * Connect to an HTTP URL and return the response as a string. * //from w w w.j av a 2 s.c om * 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("Facebook-Util", method + " URL: " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK"); 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")) { @SuppressWarnings("deprecation") 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.donnyfishball.fourzero.FourZeroActivity.java
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name()); }