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:net.olejon.mdapp.ClinicalTrialsCardsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Connected?
    if (!mTools.isDeviceConnected()) {
        mTools.showToast(getString(R.string.device_not_connected), 1);

        finish();/*from   w w w  .  ja  v a 2  s. co  m*/

        return;
    }

    // Intent
    final Intent intent = getIntent();

    searchString = intent.getStringExtra("search");

    // Layout
    setContentView(R.layout.activity_clinicaltrials_cards);

    // Toolbar
    mToolbar = (Toolbar) findViewById(R.id.clinicaltrials_cards_toolbar);
    mToolbar.setTitle(getString(R.string.clinicaltrials_cards_search) + ": \"" + searchString + "\"");

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.clinicaltrials_cards_toolbar_progressbar);
    mProgressBar.setVisibility(View.VISIBLE);

    // Refresh
    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.clinicaltrials_cards_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green,
            R.color.accent_purple, R.color.accent_orange);

    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            search(searchString, false);
        }
    });

    // Recycler view
    mRecyclerView = (RecyclerView) findViewById(R.id.clinicaltrials_cards_cards);

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setAdapter(new ClinicalTrialsCardsAdapter(mContext, new JSONArray()));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));

    // No clinical trials
    mNoClinicalTrialsLayout = (LinearLayout) findViewById(R.id.clinicaltrials_cards_no_clinicaltrials);

    Button noClinicalTrialsButton = (Button) findViewById(R.id.clinicaltrials_cards_no_results_button);

    noClinicalTrialsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title",
                        getString(R.string.clinicaltrials_cards_search) + ": \"" + searchString + "\"");
                intent.putExtra("uri", "https://clinicaltrials.gov/ct2/results?term="
                        + URLEncoder.encode(searchString.toLowerCase(), "utf-8") + "&no_unk=Y");
                mContext.startActivity(intent);
            } catch (Exception e) {
                Log.e("ClinicalTrialsCards", Log.getStackTraceString(e));
            }
        }
    });

    // Search
    search(searchString, true);

    // Correct
    RequestQueue requestQueue = Volley.newRequestQueue(mContext);

    try {
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
                getString(R.string.project_website_uri) + "api/1/correct/?search="
                        + URLEncoder.encode(searchString, "utf-8"),
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            final String correctSearchString = response.getString("correct");

                            if (!correctSearchString.equals("")) {
                                new MaterialDialog.Builder(mContext)
                                        .title(getString(R.string.correct_dialog_title))
                                        .content(Html.fromHtml(getString(R.string.correct_dialog_message)
                                                + ":<br><br><b>" + correctSearchString + "</b>"))
                                        .positiveText(getString(R.string.correct_dialog_positive_button))
                                        .negativeText(getString(R.string.correct_dialog_negative_button))
                                        .callback(new MaterialDialog.ButtonCallback() {
                                            @Override
                                            public void onPositive(MaterialDialog dialog) {
                                                ContentValues contentValues = new ContentValues();
                                                contentValues.put(ClinicalTrialsSQLiteHelper.COLUMN_STRING,
                                                        correctSearchString);

                                                SQLiteDatabase sqLiteDatabase = new ClinicalTrialsSQLiteHelper(
                                                        mContext).getWritableDatabase();

                                                sqLiteDatabase.delete(ClinicalTrialsSQLiteHelper.TABLE,
                                                        ClinicalTrialsSQLiteHelper.COLUMN_STRING + " = "
                                                                + mTools.sqe(searchString) + " COLLATE NOCASE",
                                                        null);
                                                sqLiteDatabase.insert(ClinicalTrialsSQLiteHelper.TABLE, null,
                                                        contentValues);

                                                sqLiteDatabase.close();

                                                mToolbar.setTitle(
                                                        getString(R.string.clinicaltrials_cards_search) + ": \""
                                                                + correctSearchString + "\"");

                                                mProgressBar.setVisibility(View.VISIBLE);

                                                mNoClinicalTrialsLayout.setVisibility(View.GONE);
                                                mSwipeRefreshLayout.setVisibility(View.VISIBLE);

                                                search(correctSearchString, true);
                                            }
                                        }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue)
                                        .negativeColorRes(R.color.black).show();
                            }
                        } catch (Exception e) {
                            Log.e("ClinicalTrialsCards", Log.getStackTraceString(e));
                        }
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e("ClinicalTrialsCards", error.toString());
                    }
                });

        jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        requestQueue.add(jsonObjectRequest);
    } catch (Exception e) {
        Log.e("ClinicalTrialsCards", Log.getStackTraceString(e));
    }
}

From source file:me.piebridge.prevent.framework.SystemReceiver.java

private boolean handleCheckLicense(Context context, Intent intent) {
    String user = intent.getStringExtra(Intent.EXTRA_USER);
    Map<String, Set<String>> users = new LinkedHashMap<String, Set<String>>();
    for (Account account : ActivityManagerServiceHook.getAccountWatcher().getEnabledAccounts()) {
        Set<String> accounts = users.get(account.type);
        if (accounts == null) {
            accounts = new LinkedHashSet<String>();
            users.put(account.type, accounts);
        }/*from ww w .  java2 s  .  c o  m*/
        accounts.add(account.name);
        if (PackageUtils.equals(account.name, user)) {
            setResultCode(0x1);
            return true;
        }
    }
    String number = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
    if (number != null) {
        number = number.replace("-", "");
        number = number.replace(" ", "");
        Set<String> numbers = users.get("");
        if (numbers == null) {
            numbers = new LinkedHashSet<String>();
            users.put("", numbers);
        }
        numbers.add(number);
        if (PackageUtils.equals(number, user)) {
            setResultCode(0x1);
            return true;
        }
    }
    setResultCode(0x0);
    setResultData(users.toString());
    return false;
}

From source file:com.application.treasurehunt.ScanQRCodeActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    if (resultCode == RESULT_OK) {
        if (intent.getStringExtra(ZBarConstants.SCAN_RESULT).contains(mCurrentHuntId + "")) {
            String questionReturned = intent.getStringExtra(ZBarConstants.SCAN_RESULT);
            //http://stackoverflow.com/questions/8694984/remove-part-of-string
            String questionReturnedWithoutHuntId = questionReturned.replace(mCurrentHuntId + "", "");
            mQuestionReturned.setText(questionReturnedWithoutHuntId);
            saveScanResult();//ww  w.  j  a  v  a  2 s  .  c  o  m
        } else {
            showFailedScanMessage();
        }

    } else if (resultCode == RESULT_CANCELED) {
        Toast.makeText(this, "Camera unavailable", Toast.LENGTH_SHORT).show();
    }
}

From source file:jp.alessandro.android.iab.PurchaseFlowLauncher.java

public Purchase handleResult(int requestCode, int resultCode, Intent data) throws BillingException {
    if (mRequestCode != requestCode) {
        throw new BillingException(Constants.ERROR_BAD_RESPONSE,
                Constants.ERROR_MSG_RESULT_REQUEST_CODE_INVALID);
    }//from  w ww.j a v a  2s  . c  o  m
    int responseCode = ResponseExtractor.fromIntent(data, mLogger);
    String purchaseData = data.getStringExtra(Constants.RESPONSE_INAPP_PURCHASE_DATA);
    String signature = data.getStringExtra(Constants.RESPONSE_INAPP_SIGNATURE);
    return getPurchase(resultCode, responseCode, purchaseData, signature);
}

From source file:com.csipsimple.plugins.betamax.CallHandlerWeb.java

@Override
public void onReceive(Context context, Intent intent) {
    if (Utils.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {

        PendingIntent pendingIntent = null;
        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, "");
        String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, "");

        // We must handle that clean way cause when call just to
        // get the row in account list expect this to reply correctly
        if (!TextUtils.isEmpty(number) && !TextUtils.isEmpty(user) && !TextUtils.isEmpty(nbr)
                && !TextUtils.isEmpty(pwd) && !TextUtils.isEmpty(provider)) {
            // Build pending intent
            Intent i = new Intent(ACTION_DO_WEB_CALL);
            i.setClass(context, getClass());
            i.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
            pendingIntent = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

        }/*from www  .  ja v  a2  s.c o m*/

        // Build icon
        Bitmap bmp = Utils.getBitmapFromResource(context, R.drawable.icon_web);

        // Build the result for the row (label, icon, pending intent, and
        // excluded phone number)
        Bundle results = getResultExtras(true);
        if (pendingIntent != null) {
            results.putParcelable(Utils.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        }

        // Text for the row
        String providerName = "";
        Resources r = context.getResources();
        if (!TextUtils.isEmpty(provider)) {
            String[] arr = r.getStringArray(R.array.provider_values);
            String[] arrEntries = r.getStringArray(R.array.provider_entries);
            int i = 0;
            for (String prov : arr) {
                if (prov.equalsIgnoreCase(provider)) {
                    providerName = arrEntries[i];
                    break;
                }
                i++;
            }
        }
        results.putString(Intent.EXTRA_TITLE, providerName + " " + r.getString(R.string.web_callback));
        Log.d(THIS_FILE, "icon is " + bmp);
        if (bmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, bmp);
        }

        // DO *NOT* exclude from next tel: intent cause we use a http method
        // results.putString(Intent.EXTRA_PHONE_NUMBER, number);

    } else if (ACTION_DO_WEB_CALL.equals(intent.getAction())) {

        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, "");
        String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, "");

        // params
        List<NameValuePair> params = new LinkedList<NameValuePair>();
        params.add(new BasicNameValuePair("username", user));
        params.add(new BasicNameValuePair("password", pwd));
        params.add(new BasicNameValuePair("from", nbr));
        params.add(new BasicNameValuePair("to", number));
        String paramString = URLEncodedUtils.format(params, "utf-8");

        String requestURL = "https://www." + provider + "/myaccount/makecall.php?" + paramString;

        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(requestURL);

        // Create a response handler
        HttpResponse httpResponse;
        try {
            httpResponse = httpClient.execute(httpGet);
            Log.d(THIS_FILE, "response code is " + httpResponse.getStatusLine().getStatusCode());
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                InputStreamReader isr = new InputStreamReader(httpResponse.getEntity().getContent());
                BufferedReader br = new BufferedReader(isr);

                String line;
                String fullReply = "";
                boolean foundSuccess = false;
                while ((line = br.readLine()) != null) {
                    if (!TextUtils.isEmpty(line) && line.toLowerCase().contains("success")) {
                        showToaster(context, "Success... wait a while you'll called back");
                        foundSuccess = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(line)) {
                        fullReply = fullReply.concat(line);
                    }
                }
                if (!foundSuccess) {
                    showToaster(context, "Error : server error : " + fullReply);
                }
            } else {
                showToaster(context, "Error : invalid request " + httpResponse.getStatusLine().getStatusCode());
            }
        } catch (ClientProtocolException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        } catch (IOException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        }

    }
}

From source file:com.flavik.barcode.recognizer.client.android.book.SearchBookContentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Make sure that expired cookies are removed on launch.
    CookieSyncManager.createInstance(this);
    CookieManager.getInstance().removeExpiredCookie();

    Intent intent = getIntent();
    if (intent == null || !intent.getAction().equals(Intents.SearchBookContents.ACTION)) {
        finish();//from  w  ww  .  j  a va 2  s.co  m
        return;
    }

    isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN);
    if (LocaleManager.isBookSearchUrl(isbn)) {
        setTitle(getString(R.string.sbc_name));
    } else {
        setTitle(getString(R.string.sbc_name) + ": ISBN " + isbn);
    }

    setContentView(R.layout.search_book_contents);
    queryTextView = (EditText) findViewById(R.id.query_text_view);

    String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY);
    if (initialQuery != null && !initialQuery.isEmpty()) {
        // Populate the search box but don't trigger the search
        queryTextView.setText(initialQuery);
    }
    queryTextView.setOnKeyListener(keyListener);

    queryButton = (Button) findViewById(R.id.query_button);
    queryButton.setOnClickListener(buttonListener);

    resultListView = (ListView) findViewById(R.id.result_list_view);
    LayoutInflater factory = LayoutInflater.from(this);
    headerView = (TextView) factory.inflate(R.layout.search_book_contents_header, resultListView, false);
    resultListView.addHeaderView(headerView);
}

From source file:com.ripperdesignandmultimedia.phoneblockplugin.PhoneBlockerPlugin.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 * /*from   w  ww .  ja v  a2 s  .  com*/
 * @param ctx The context of the main Activity.
 */
public void setContext(CordovaInterface ctx) {
    super.setContext(ctx);
    this.phoneBlockerCallbackId = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;
                    String state;
                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                    updatePhoneState(state, true);
                }
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        cordova.getActivity().registerReceiver(this.receiver, intentFilter);
    }
}

From source file:devbox.com.br.minercompanion.ProfileActivity.java

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


    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (networkInfo.isConnected()) {
        final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
        final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
        if (connectionInfo != null && !(connectionInfo.getSSID().equals(""))) {
            //if (connectionInfo != null && !StringUtil.isBlank(connectionInfo.getSSID())) {
            routerName = connectionInfo.getSSID();
        }/* www  . j  av  a  2  s  .c o  m*/
    }

    sensorCounter = new SensorCounter(3000, 3000);
    sensorCounter.start();

    Intent intent = getIntent();

    if(intent != null) {
        matricula = intent.getStringExtra("MATRICULA");

        TextView textView = (TextView) findViewById(R.id.textView);

        textView.setText("Matrcula: " + matricula);

        sensors = new Sensors(matricula, routerName.replace("\"",""));
    }

    /* Get a SensorManager instance */
    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    ListView listView = (ListView) findViewById(R.id.listView);
    profileListAdapter = new ProfileListAdapter(this, strings);
    listView.setAdapter(profileListAdapter);

    profileListAdapter.addItem("Conectado ao servidor!");
}

From source file:com.scigames.registration.Registration4PhotoActivity.java

/** Called with the activity is first created. */
@Override/*  w w w  .j ava2  s  . c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "super.OnCreate");
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    Intent i = getIntent();
    Log.d(TAG, "getIntent");
    firstNameIn = i.getStringExtra("fName");
    lastNameIn = i.getStringExtra("lName");
    studentIdIn = i.getStringExtra("studentId");
    visitIdIn = i.getStringExtra("visitId");
    Log.d(TAG, "...getStringExtra");

    // Inflate our UI from its XML layout description.
    setContentView(R.layout.registration4_photo);
    Log.d(TAG, "...setContentView");

    avatarPhoto = (ImageView) this.findViewById(R.id.avatar_photo);
    Log.d(TAG, "...findViewById. avatar_photo");

    or = (TextView) findViewById(R.id.or);
    or.setVisibility(View.INVISIBLE);
    retakeButton = (Button) findViewById(R.id.retake_pic);
    retakeButton.setVisibility(View.INVISIBLE);
    retakeButton.setOnClickListener(mTakePhotoListener);

    saveButton = (Button) findViewById(R.id.save_button);
    saveButton.setOnClickListener(mContinueButtonListener);
    saveButton.setVisibility(View.INVISIBLE);

    takePhotoButton = (Button) findViewById(R.id.take_pic);
    takePhotoButton.setOnClickListener(mTakePhotoListener);
    takePhotoButton.setVisibility(View.VISIBLE);
    //((Button) findViewById(R.id.take_pic)).setOnClickListener(mTakePhotoListener);
    Log.d(TAG, "...instantiateButtons");

    //set listener
    task.setOnResultsListener(this);

    Typeface ExistenceLightOtf = Typeface.createFromAsset(getAssets(), "fonts/Existence-Light.ttf");
    Typeface Museo300Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo300-Regular.otf");
    Typeface Museo500Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo500-Regular.otf");
    Typeface Museo700Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo700-Regular.otf");

    //       TextView welcome = (TextView)findViewById(R.id.welcome);
    //instruction = (TextView)findViewById(R.id.instructions);
    //       setTextViewFont(ExistenceLightOtf, welcome);
    setButtonFont(Museo500Regular, retakeButton);
    setTextViewFont(Museo300Regular, or);
}

From source file:org.runnerup.export.FacebookSynchronizer.java

@Override
public Status getAuthResult(int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        try {//from  w ww .ja  v  a 2s.  c o m
            String authConfig = data.getStringExtra(DB.ACCOUNT.AUTH_CONFIG);
            Uri uri = Uri.parse("http://keso?" + authConfig);
            access_token = uri.getQueryParameter("access_token");
            expire_time = Long.valueOf(uri.getQueryParameter("expires"));
            token_now = System.currentTimeMillis();
            return Status.OK;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return Status.ERROR;
}