Example usage for android.content Intent getStringExtra

List of usage examples for android.content Intent getStringExtra

Introduction

In this page you can find the example usage for android.content Intent getStringExtra.

Prototype

public String getStringExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:org.geometerplus.android.fbreader.network.BearerAuthenticator.java

static boolean onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
    final BearerAuthenticator ba = ourAuthenticators.get(activity);
    boolean processed = true;
    try {/*  w w w  . j av a 2  s .  c  o  m*/
        switch (requestCode) {
        default:
            processed = false;
            break;
        case NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER:
            if (resultCode == Activity.RESULT_OK && data != null) {
                ba.myAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            }
            break;
        case NetworkLibraryActivity.REQUEST_AUTHORISATION:
            if (resultCode == Activity.RESULT_OK) {
                ba.myAuthorizationConfirmed = true;
            }
            break;
        case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN:
            if (resultCode == Activity.RESULT_OK && data != null) {
                final CookieStore store = ZLNetworkManager.Instance().cookieStore();
                final Map<String, String> cookies = (Map<String, String>) data
                        .getSerializableExtra(NetworkLibraryActivity.COOKIES_KEY);
                if (cookies != null) {
                    for (Map.Entry<String, String> entry : cookies.entrySet()) {
                        final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue());
                        c.setDomain(data.getData().getHost());
                        c.setPath("/");
                        final Calendar expire = Calendar.getInstance();
                        expire.add(Calendar.YEAR, 1);
                        c.setExpiryDate(expire.getTime());
                        c.setSecure(true);
                        c.setDiscard(false);
                        store.addCookie(c);
                    }
                }
            }
            break;
        }
    } finally {
        if (processed) {
            synchronized (ba) {
                ba.notifyAll();
            }
        }
        return processed;
    }
}

From source file:Main.java

public static float getCurrentBattery(Context context) {
    Intent batteryInfoIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    int status = batteryInfoIntent.getIntExtra("status", 0);
    int health = batteryInfoIntent.getIntExtra("health", 1);
    boolean present = batteryInfoIntent.getBooleanExtra("present", false);
    int level = batteryInfoIntent.getIntExtra("level", 0);
    int scale = batteryInfoIntent.getIntExtra("scale", 0);
    int plugged = batteryInfoIntent.getIntExtra("plugged", 0);
    int voltage = batteryInfoIntent.getIntExtra("voltage", 0);
    int temperature = batteryInfoIntent.getIntExtra("temperature", 0);
    String technology = batteryInfoIntent.getStringExtra("technology");
    return level / (float) scale;
}

From source file:net.openid.appauth.AuthorizationResponse.java

/**
 * Extracts an authorization response from an intent produced by {@link #toIntent()}. This is
 * used to extract the response from the intent data passed to an activity registered as the
 * handler for {@link AuthorizationService#performAuthorizationRequest}.
 *///from   w w w  .  j av  a  2 s  .  co m
@Nullable
public static AuthorizationResponse fromIntent(@NonNull Intent dataIntent) {
    checkNotNull(dataIntent, "dataIntent must not be null");
    if (!dataIntent.hasExtra(EXTRA_RESPONSE)) {
        return null;
    }

    try {
        return AuthorizationResponse.jsonDeserialize(dataIntent.getStringExtra(EXTRA_RESPONSE));
    } catch (JSONException ex) {
        throw new IllegalArgumentException("Intent contains malformed auth response", ex);
    }
}

From source file:net.openid.appauth.AuthorizationException.java

/**
 * Extracts an {@link AuthorizationException} from an intent produced by {@link #toIntent()}.
 * This is used to retrieve an error response in the handler registered for a call to
 * {@link AuthorizationService#performAuthorizationRequest}.
 *//*from ww  w .j  a va2s. c  o m*/
@Nullable
public static AuthorizationException fromIntent(Intent data) {
    checkNotNull(data);

    if (!data.hasExtra(EXTRA_EXCEPTION)) {
        return null;
    }

    try {
        return fromJson(data.getStringExtra(EXTRA_EXCEPTION));
    } catch (JSONException ex) {
        throw new IllegalArgumentException("Intent contains malformed exception data", ex);
    }
}

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * Given an Intent, returns the stack trace extra from it.
 *
 * @param intent The Intent. Must not be null.
 * @return The stacktrace, or null if not provided.
 *///from w w w .j  av a  2s  . com
public static String getStackTraceFromIntent(Intent intent) {
    return intent.getStringExtra(CustomActivityOnCrash.EXTRA_STACK_TRACE);
}

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * Given an Intent, returns the user actions trace extra from it.
 *
 * @param intent The Intent. Must not be null.
 * @return The stacktrace, or null if not provided.
 *//*from  w  ww  .  j a v  a2s .c o  m*/
public static String getUserTraceFromIntent(Intent intent) {
    return intent.getStringExtra(CustomActivityOnCrash.EXTRA_USER_ACTION_TRACE);
}

From source file:com.upnext.blekit.BLEKit.java

/**
 * Should be called from Activity that handles notifications.
 * For the notification to be handled successfully add the following line to the <code>onNewIntent</code> method of this activity:
 * <pre>// w  w  w  .j a v  a2  s.c  o m
 * {@code
 * protected void onNewIntent(Intent intent) {
 *     super.onNewIntent(intent);
 *     BLEKit.processIntent(intent, this); //add this line
 * }
 * }
 * </pre>
 *
 * @param intent Android Intent
 * @param activity Android Activity
 */
public static void processIntent(Intent intent, Activity activity) {
    if (intent == null)
        return;
    String type = intent.getStringExtra("type");
    if (type == null)
        return;

    BLEAction action = mActionsFactory.get(type);
    if (action != null) {
        action.processIntent(intent, activity);
    }
}

From source file:net.primeranks.fs_viewer.fs_replay.ConnectionChangedBroadcastReceiver.java

public void onReceive(Context context, Intent intent) {
    String info = intent.getStringExtra(ConnectivityManager.EXTRA_EXTRA_INFO);
    NetworkInfo nwInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
    Log.d(Config.LOG_AS, info + ": " + nwInfo.getReason());

    HttpParams httpParams = EntryPointActivity.getHttpClient().getParams();
    if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        String proxyHost = Proxy.getHost(context);
        if (proxyHost == null) {
            proxyHost = Proxy.getDefaultHost();
        }/*from ww  w  .j a v a 2 s .  c o m*/
        int proxyPort = Proxy.getPort(context);
        if (proxyPort == -1) {
            proxyPort = Proxy.getDefaultPort();
        }
        if (proxyHost != null && proxyPort > -1) {
            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        } else {
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
        }
    } else {
        httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
    }
}

From source file:hongik.android.project.best.MenuActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menudetail);

    Intent intent = getIntent();
    license = intent.getStringExtra("LICENSE");
    item = intent.getStringExtra("MENU");

    try {/* www .j  a va 2s  . c  o  m*/
        drawintent();
    } catch (Exception ex) {
    }
}

From source file:hongik.android.project.best.ReviewDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reviewdetail);

    Intent intent = getIntent();
    access = intent.getStringExtra("ACCESS");
    cid = intent.getStringExtra("CID");
    license = intent.getStringExtra("LICENSE");

    if (access.equals("STORE"))
        ((ButtonPlus) findViewById(R.id.reviewdetail_button)).setText("Go Back");
    else if (access.equals("HISTORY"))
        ((ButtonPlus) findViewById(R.id.reviewdetail_button)).setText("StoreInfo");

    drawReview();/*from w ww .  j  a va2 s .  c  o m*/
}