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:es.uma.lcc.lockpic.MainActivity.java

private void encryptImage(Intent data) {
    String src = data.getStringExtra("path");
    int width = data.getIntExtra("width", 0);
    int height = data.getIntExtra("height", 0);
    (new EncryptionUploaderTask(src, width, height, data.getStringArrayListExtra("rectangles"),
            MainActivity.this)).execute();
}

From source file:com.thunder.iap.IAPActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RC_INAPP_BUY) {
        //in app item bought
        int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
        String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
        String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
        if (resultCode == RESULT_OK) {
            try {
                JSONObject jo = new JSONObject(purchaseData);
                //String sku = jo.getString("productId");
                if (buyItemListener != null) {
                    buyItemListener.onSuccess(jo);
                }/* ww w .  ja  va 2s.c  o  m*/
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            if (buyItemListener != null) {
                buyItemListener.onError(new RuntimeException("Error during onActivityResult"));
            }
        }
    }
    if (requestCode == RC_SUBS_BUY) {
        //subscription bought
        int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
        String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
        String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
        if (resultCode == RESULT_OK) {
            try {
                JSONObject jo = new JSONObject(purchaseData);
                //String sku = jo.getString("productId");
                if (buySubscriptionListener != null) {
                    buySubscriptionListener.onSuccess(jo);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            if (buySubscriptionListener != null) {
                buySubscriptionListener.onError(new RuntimeException("Error during onActivityResult"));
            }
        }
    }
}

From source file:org.klnusbaum.udj.network.PlayerCommService.java

private void joinPlayer(Intent intent, AccountManager am, Account account, boolean attemptReauth) {
    if (!Utils.isNetworkAvailable(this)) {
        doLoginFail(am, account, PlayerJoinError.NO_NETWORK_ERROR);
        return;/*from  ww w.  ja  v  a2  s  .c  o  m*/
    }

    String userId = am.getUserData(account, Constants.USER_ID_DATA);
    String playerId = intent.getStringExtra(Constants.PLAYER_ID_EXTRA);
    String ownerId = intent.getStringExtra(Constants.PLAYER_OWNER_ID_EXTRA);
    if (userId.equals(ownerId)) {
        setLoggedInToPlayer(intent, am, account, playerId);
        return;
    }

    String authToken;
    String password = "";
    boolean hasPassword = false;
    //TODO hanle error if account isn't provided
    try {
        //TODO handle if player id isn't provided
        authToken = am.blockingGetAuthToken(account, "", true);
        if (intent.hasExtra(Constants.PLAYER_PASSWORD_EXTRA)) {
            Log.d(TAG, "password given for player");
            hasPassword = true;
            password = intent.getStringExtra(Constants.PLAYER_PASSWORD_EXTRA);
        } else {
            Log.d(TAG, "No password given for player");
        }
    } catch (OperationCanceledException e) {
        Log.e(TAG, "Operation canceled exception");
        doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR);
        return;
    } catch (AuthenticatorException e) {
        Log.e(TAG, "Authenticator exception");
        doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR);
        return;
    } catch (IOException e) {
        Log.e(TAG, "IO exception");
        doLoginFail(am, account, PlayerJoinError.AUTHENTICATION_ERROR);
        return;
    }

    try {
        if (!hasPassword) {
            ServerConnection.joinPlayer(playerId, authToken);
        } else {
            ServerConnection.joinPlayer(playerId, password, authToken);
        }
        setLoggedInToPlayer(intent, am, account, playerId);
    } catch (IOException e) {
        Log.e(TAG, "IO exception when joining player");
        Log.e(TAG, e.getMessage());
        doLoginFail(am, account, PlayerJoinError.SERVER_ERROR);
    } catch (JSONException e) {
        Log.e(TAG, "JSON exception when joining player");
        Log.e(TAG, e.getMessage());
        doLoginFail(am, account, PlayerJoinError.SERVER_ERROR);
    } catch (AuthenticationException e) {
        handleLoginAuthException(intent, am, account, authToken, attemptReauth);
    } catch (PlayerInactiveException e) {
        Log.e(TAG, "Player inactive Exception when joining player");
        doLoginFail(am, account, PlayerJoinError.PLAYER_INACTIVE_ERROR);
    } catch (ParseException e) {
        e.printStackTrace();
        doLoginFail(am, account, PlayerJoinError.SERVER_ERROR);
    } catch (PlayerPasswordException e) {
        Log.e(TAG, "Player Password Exception");
        e.printStackTrace();
        doLoginFail(am, account, PlayerJoinError.PLAYER_PASSWORD_ERROR);
    } catch (PlayerFullException e) {
        Log.e(TAG, "Player Password Exception");
        e.printStackTrace();
        doLoginFail(am, account, PlayerJoinError.PLAYER_FULL_ERROR);
    } catch (BannedException e) {
        Log.e(TAG, "Player Password Exception");
        e.printStackTrace();
        doLoginFail(am, account, PlayerJoinError.BANNED_ERROR);
    }
}

From source file:net.networksaremadeofstring.cyllell.Search.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_main);

    //Fancy title
    ((TextView) findViewById(R.id.TitleBarText))
            .setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/codeops_serif.ttf"));

    //List view to hold search results
    list = (ListView) findViewById(R.id.SearchResultsListView);

    //Prep the handler to do all the UI updating etc
    MakeHandler();//ww  w.java 2  s . c om

    //This is for the crafted search (not visible if the user came in via a search intent
    ((Button) findViewById(R.id.SearchButton)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            index = ((Spinner) findViewById(R.id.IndexChoice)).getSelectedItem().toString().toLowerCase();
            query = ((TextView) findViewById(R.id.SearchStringEditText)).getText().toString();
            PerformSearch(true);
        }
    });

    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        findViewById(R.id.SearchParamContainer).setVisibility(8);
        //findViewById(R.id.ShowSearchParams).setVisibility(0);
        findViewById(R.id.SearchMainRelativeLayout).invalidate();

        query = intent.getStringExtra(SearchManager.QUERY);
        index = "node";

        PerformSearch(false);
    } else if (Intent.ACTION_SEARCH_LONG_PRESS.equals(intent.getAction())) {
        //findViewById(R.id.SearchParamContainer).setVisibility(0);
        //findViewById(R.id.ShowSearchParams).setVisibility(4);
    } else {
        //findViewById(R.id.SearchParamContainer).setVisibility(0);
        //findViewById(R.id.ShowSearchParams).setVisibility(4);
    }

    /*((ImageView)findViewById(R.id.ShowSearchParams)).setOnClickListener(new View.OnClickListener() {
    public void onClick(View v)
    {
       findViewById(R.id.SearchParamContainer).setVisibility(0);
      findViewById(R.id.ShowSearchParams).setVisibility(4);
      findViewById(R.id.SearchMainRelativeLayout).invalidate();
    }
     });
            
    ((ImageView)findViewById(R.id.HideSearchParams)).setOnClickListener(new View.OnClickListener() {
    public void onClick(View v)
    {
       findViewById(R.id.SearchParamContainer).setVisibility(8);
      findViewById(R.id.ShowSearchParams).setVisibility(0);
      findViewById(R.id.SearchMainRelativeLayout).invalidate();
              
    }
     });*/
}

From source file:com.attentec.Login.java

/**
 * Handle the result of scanning a phone key QR code with the barcode scanner app.
 * @param requestCode A code that tells which activity the request is bound to.
 * @param resultCode The resultet code after QR code scan.
 * @param intent dummy, never used/*from  www .j a  va 2s .  co m*/
 */
@Override
public final void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (requestCode == REQUEST_PHONE_KEY_SCANNER_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            //Handle successful scan
            saveKey(contents);
            if (!readUserName().equals("")) {
                login(readKey(), readUserName());
            } else {
                EditText passwordEditText = (EditText) findViewById(R.id.txt_password);
                passwordEditText.setText(readKey());
            }
        } /*else if (resultCode == RESULT_CANCELED) {
           //If user cancels, we don't need to do anything
          }*/
    }
}

From source file:com.duguang.baseanimation.ui.listivew.listviews.ListViewsMainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) {
        Toast.makeText(this, "Thank you!", Toast.LENGTH_LONG).show();

        new Thread() {

            @Override//from ww  w . j a  va2s .c  o m
            public void run() {
                try {
                    JSONObject json = new JSONObject(data.getStringExtra("INAPP_PURCHASE_DATA"));
                    mService.consumePurchase(3, getPackageName(), json.getString("purchaseToken"));
                } catch (JSONException e) {
                    e.printStackTrace();
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }

        }.start();
    }
}

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

public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    boolean processed = true;
    try {/*from w w  w.  j  av  a  2  s  .  co m*/
        switch (requestCode) {
        default:
            processed = false;
            break;
        case NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER:
            if (resultCode == Activity.RESULT_OK && data != null) {
                myAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            }
            break;
        case NetworkLibraryActivity.REQUEST_AUTHORISATION:
            if (resultCode == Activity.RESULT_OK) {
                myAuthorizationConfirmed = true;
            }
            break;
        case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN:
            if (resultCode == Activity.RESULT_OK && data != null) {
                final CookieStore store = 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 (this) {
                notifyAll();
            }
        }
        return processed;
    }
}

From source file:edu.mit.mobile.android.locast.accounts.AuthenticatorActivity.java

/**
 * {@inheritDoc}//from w w  w  .  j  a  v  a2 s .  c o  m
 */
@Override
public void onCreate(Bundle icicle) {
    Log.i(TAG, "onCreate(" + icicle + ")");
    super.onCreate(icicle);

    mAccountManager = AccountManager.get(this);
    Log.i(TAG, "loading data from Intent");

    final Intent intent = getIntent();
    mUsername = intent.getStringExtra(EXTRA_USERNAME);
    mAuthtokenType = intent.getStringExtra(EXTRA_AUTHTOKEN_TYPE);
    mRequestNewAccount = mUsername == null;
    mConfirmCredentials = intent.getBooleanExtra(EXTRA_CONFIRMCREDENTIALS, false);

    Log.i(TAG, "    request new: " + mRequestNewAccount);
    requestWindowFeature(Window.FEATURE_LEFT_ICON);
    // make the title based on the app name.
    setTitle(getString(R.string.login_title, getString(R.string.app_name)));

    setContentView(R.layout.login);
    // this is done this way, so the associated icon is managed in XML.
    try {
        getWindow().setFeatureDrawable(Window.FEATURE_LEFT_ICON,
                getPackageManager().getActivityIcon(getComponentName()));
    } catch (final NameNotFoundException e) {
        e.printStackTrace();
    }

    mMessage = (TextView) findViewById(R.id.message);
    mUsernameEdit = (EditText) findViewById(R.id.username);
    mPasswordEdit = (EditText) findViewById(R.id.password);
    mPasswordEdit.setOnEditorActionListener(this);
    findViewById(R.id.login).setOnClickListener(this);
    findViewById(R.id.cancel).setOnClickListener(this);
    ((Button) findViewById(R.id.register)).setOnClickListener(this);

    mUsernameEdit.setText(mUsername);

    mAuthenticationTask = (AuthenticationTask) getLastNonConfigurationInstance();
    if (mAuthenticationTask != null) {
        mAuthenticationTask.attach(this);
    }
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog informing the user that Whatsapp is not installed on the
 * device, and gives an option to hide the dialog in the future.
 * /*ww  w .  j a v a 2s .c  o  m*/
 * @param activity
 *            the caller activity
 * @param intent
 *            the intent containing the content to be shared
 */
public static void whatsappMissing(final SendToWhatsappActivity activity, final Intent intent) {
    // @formatter:off
    DialogFragment dialog = new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getNoUiBuilder(activity)
                    .setTitle(activity.getString(R.string.whatsapp_not_installed_title))
                    .setMessage(activity.getString(R.string.whatsapp_not_installed)).setPositiveButton(
                            activity.getString(android.R.string.ok), new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    activity.startActivity(SendToAppActivity
                                            .createPlainIntent(intent.getStringExtra("message")));
                                }
                            })
                    .setNegativeButton(activity.getString(R.string.whatsapp_not_installed_dont_mind),
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    SharedPreferences pref = activity.getSharedPreferences("it.mb.whatshare",
                                            Context.MODE_PRIVATE);
                                    pref.edit()
                                            .putBoolean(SendToWhatsappActivity.HIDE_MISSING_WHATSAPP_KEY, true)
                                            .commit();
                                    activity.startActivity(SendToAppActivity
                                            .createPlainIntent(intent.getStringExtra("message")));
                                }
                            });
            Dialog dialog = builder.create();
            dialog.setCanceledOnTouchOutside(false);
            return dialog;
        }
    };
    dialog.show(activity.getSupportFragmentManager(), "whatsapp_missing");
    // @formatter:on
}