Example usage for android.app Activity RESULT_OK

List of usage examples for android.app Activity RESULT_OK

Introduction

In this page you can find the example usage for android.app Activity RESULT_OK.

Prototype

int RESULT_OK

To view the source code for android.app Activity RESULT_OK.

Click Source Link

Document

Standard activity result: operation succeeded.

Usage

From source file:com.soomla.store.billing.tapclash.TapClashIabHelper.java

/**
 * Handles an activity result that's part of the purchase flow in in-app billing. If you
 * are calling {@link #launchPurchaseFlow}, then you must call this method from your
 * Activity's {@link android.app.Activity@onActivityResult} method. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param requestCode The requestCode as you received it.
 * @param resultCode The resultCode as you received it.
 * @param data The data (Intent) as you received it.
 * @return Returns true if the result was related to a purchase flow and was handled;
 *     false if the result was not related to a purchase, in which case you should
 *     handle it normally./*  w ww .  j  av  a  2 s . c o m*/
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != RC_REQUEST)
        return false;

    checkSetupDoneAndThrow("handleActivityResult");

    // cancellation moved here b/c there can be a cancellation with null data
    if (resultCode == Activity.RESULT_CANCELED) {
        SoomlaUtils.LogDebug(TAG, "IabPurchase canceled.");
        try {
            IabPurchase purchase = new IabPurchase(mPurchasingItemType,
                    "{\"productId\":" + mPurchasingItemSku + "}", null);
            result = new IabResult(IabResult.BILLING_RESPONSE_RESULT_USER_CANCELED, "User canceled.");
            purchaseFailed(result, purchase);
            return true;
        } catch (JSONException e) {
            SoomlaUtils.LogError(TAG, "Failed to generate canceled purchase.");
            e.printStackTrace();
            result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to generate canceled purchase.");
            purchaseFailed(result, null);
            return true;
        }
    }

    if (data == null) {
        SoomlaUtils.LogError(TAG, "Null data in IAB activity result.");
        result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Null data in IAB result");
        purchaseFailed(result, null);
        return true;
    }

    int responseCode = getResponseCodeFromIntent(data);
    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

    if (resultCode == Activity.RESULT_OK && responseCode == IabResult.BILLING_RESPONSE_RESULT_OK) {
        SoomlaUtils.LogDebug(TAG, "Successful resultcode from purchase activity.");
        SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData);
        SoomlaUtils.LogDebug(TAG, "Data signature: " + dataSignature);
        SoomlaUtils.LogDebug(TAG, "Extras: " + data.getExtras());
        SoomlaUtils.LogDebug(TAG, "Expected item type: " + mPurchasingItemType);

        if (purchaseData == null || dataSignature == null) {
            SoomlaUtils.LogError(TAG, "BUG: either purchaseData or dataSignature is null.");
            SoomlaUtils.LogDebug(TAG, "Extras: " + data.getExtras().toString());
            result = new IabResult(IabResult.IABHELPER_UNKNOWN_ERROR,
                    "IAB returned null purchaseData or dataSignature");
            purchaseFailed(result, null);
            return true;
        }

        IabPurchase purchase = null;
        try {
            purchase = new IabPurchase(mPurchasingItemType, purchaseData, dataSignature);
            String sku = purchase.getSku();

            SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME,
                    Context.MODE_PRIVATE);
            String publicKey = prefs.getString(TapClashIabService.PUBLICKEY_KEY, "");

            // Verify signature
            if (!Security.verifyPurchase(publicKey, purchaseData, dataSignature)) {
                SoomlaUtils.LogError(TAG, "IabPurchase signature verification FAILED for sku " + sku);
                result = new IabResult(IabResult.IABHELPER_VERIFICATION_FAILED,
                        "Signature verification failed for sku " + sku);
                purchaseFailed(result, purchase);
                return true;
            }
            SoomlaUtils.LogDebug(TAG, "IabPurchase signature successfully verified.");
        } catch (JSONException e) {
            SoomlaUtils.LogError(TAG, "Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            purchaseFailed(result, null);
            return true;
        }

        purchaseSucceeded(purchase);
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        SoomlaUtils.LogDebug(TAG, "Result code was OK but in-app billing response was not OK: "
                + IabResult.getResponseDesc(responseCode));
        result = new IabResult(responseCode, "Problem purchashing item.");
        purchaseFailed(result, null);
    } else {
        SoomlaUtils.LogError(TAG, "IabPurchase failed. Result code: " + Integer.toString(resultCode)
                + ". Response: " + IabResult.getResponseDesc(responseCode));
        result = new IabResult(IabResult.IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        purchaseFailed(result, null);
    }
    return true;
}

From source file:it.evilsocket.dsploit.core.System.java

public static boolean checkNetworking(final Activity current) {
    if (Network.isWifiConnected(mContext) == false) {
        AlertDialog.Builder builder = new AlertDialog.Builder(current);

        builder.setCancelable(false);/*from  ww w .  ja  va  2  s.c o  m*/
        builder.setTitle("Error");
        builder.setMessage("WiFi connectivity went down.");
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                Bundle bundle = new Bundle();
                bundle.putBoolean(WifiScannerActivity.CONNECTED, false);

                Intent intent = new Intent();
                intent.putExtras(bundle);

                current.setResult(Activity.RESULT_OK, intent);

                current.finish();
            }
        });

        AlertDialog alert = builder.create();
        alert.show();

        return false;
    }

    return true;
}

From source file:com.sourceallies.android.zonebeacon.activity.TransferActivityTest.java

@Test
public void test_onActivityResult_otherRequestCode() {
    activity.setResolvingError(true);
    activity.onActivityResult(2, Activity.RESULT_OK, null);
    assertTrue(activity.isResolvingError());
}

From source file:de.stadtrallye.rallyesoft.ConnectionAssistantActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == IntentIntegrator.REQUEST_CODE) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (scanResult == null)
            return;
        if (resultCode == Activity.RESULT_OK && scanResult.getContents() != null)
            readServerLoginJSON(scanResult.getContents());
    }/*ww w  . j a  v a  2 s.c o m*/
}

From source file:org.planetmono.dcuploader.ActivityGalleryChooser.java

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

    db = new DatabaseHelper(this);

    setContentView(R.layout.gallery_chooser);
    ((Button) findViewById(R.id.gallery_chooser_search)).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            String query = ((EditText) findViewById(R.id.gallery_chooser_edit)).getText().toString();

            if (query.length() > 0) {
                Message m = fetcherHandler.obtainMessage();
                m.getData().putString("searchTerm", query);
                fetcherHandler.handleMessage(m);
            } else {
                fetcherHandler.sendEmptyMessage(0);
            }//w  w w  .  ja va2  s.c  o  m
        }
    });
    ((Button) findViewById(R.id.gallery_chooser_ok)).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ListView lv = (ListView) findViewById(R.id.gallery_chooser_list);

            long nids[] = lv.getCheckItemIds();
            String nstrs[] = new String[nids.length];

            for (int i = 0; i < nids.length; ++i)
                nstrs[i] = ids.get((int) nids[i]);

            Intent i = new Intent();
            i.putExtra("result", nstrs);

            setResult(Activity.RESULT_OK, i);
            finishActivity(Application.ACTION_ADD_GALLERY);
            finish();
        }
    });
    ((Button) findViewById(R.id.gallery_chooser_cancel)).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });

    if (db.rowCount() == 0)
        refresh();
    else
        fetcherHandler.sendEmptyMessage(0);
}

From source file:com.dwdesign.tweetings.activity.ComposeActivity.java

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

    switch (requestCode) {
    case REQUEST_SCHEDULE_DATE: {
        if (resultCode == Activity.RESULT_OK) {
            Bundle bundle = intent.getExtras();
            mScheduleDate = bundle.getString(INTENT_KEY_SCHEDULE_DATE_TIME);
        } else {/*from w w w  . j a v a2 s .  c  o  m*/
            if (mScheduleDate != null) {
                mScheduleDate = null;
            }
        }
        setMenu();
        break;
    }
    case REQUEST_TAKE_PHOTO: {
        if (resultCode == Activity.RESULT_OK) {
            final File file = new File(mImageUri.getPath());
            if (file.exists()) {
                mIsImageAttached = false;
                mIsPhotoAttached = true;
                mImageThumbnailPreview.setVisibility(View.VISIBLE);
                reloadAttachedImageThumbnail(file);
            } else {
                mIsPhotoAttached = false;
            }
            setMenu();
            boolean isAutoUpload = mPreferences.getBoolean(PREFERENCE_KEY_AUTO_UPLOAD, false);
            if (!isNullOrEmpty(mUploadProvider) && mIsPhotoAttached && isAutoUpload) {
                postMedia();
            }
        }
        break;
    }
    case REQUEST_PICK_IMAGE: {
        if (resultCode == Activity.RESULT_OK) {
            final Uri uri = intent.getData();
            final File file = uri == null ? null : new File(getImagePathFromUri(this, uri));
            if (file != null && file.exists()) {
                mImageUri = Uri.fromFile(file);
                mIsPhotoAttached = false;
                mIsImageAttached = true;
                mImageThumbnailPreview.setVisibility(View.VISIBLE);
                reloadAttachedImageThumbnail(file);
            } else {
                mIsImageAttached = false;
            }
            setMenu();
            boolean isAutoUpload = mPreferences.getBoolean(PREFERENCE_KEY_AUTO_UPLOAD, false);
            if (!isNullOrEmpty(mUploadProvider) && mIsImageAttached && isAutoUpload) {
                postMedia();
            }
        }
        break;
    }
    case REQUEST_SELECT_ACCOUNT: {
        if (resultCode == Activity.RESULT_OK) {
            final Bundle bundle = intent.getExtras();
            if (bundle == null) {
                break;
            }
            final long[] account_ids = bundle.getLongArray(INTENT_KEY_IDS);
            if (account_ids != null) {
                mAccountIds = account_ids;
                if (mInReplyToStatusId <= 0 && !Intent.ACTION_SEND.equals(getIntent().getAction())) {
                    final SharedPreferences.Editor editor = mPreferences.edit();
                    editor.putString(PREFERENCE_KEY_COMPOSE_ACCOUNTS,
                            ArrayUtils.toString(mAccountIds, ',', false));
                    editor.commit();
                }
                mColorIndicator.setColor(getAccountColors(this, account_ids));
            }
        }
        break;
    }
    case REQUEST_EDIT_IMAGE: {
        if (resultCode == Activity.RESULT_OK) {
            final Uri uri = intent.getData();
            final File file = uri == null ? null : new File(getImagePathFromUri(this, uri));
            if (file != null && file.exists()) {
                mImageUri = Uri.fromFile(file);
                reloadAttachedImageThumbnail(file);
            } else {
                break;
            }
            setMenu();
        }
        break;
    }
    case REQUEST_EXTENSION_COMPOSE: {
        if (resultCode == Activity.RESULT_OK) {
            final Bundle extras = intent.getExtras();
            if (extras == null) {
                break;
            }
            final String text = extras.getString(INTENT_KEY_TEXT);
            final String append = extras.getString(INTENT_KEY_APPEND_TEXT);
            if (text != null) {
                mEditText.setText(text);
                mText = parseString(mEditText.getText());
            } else if (append != null) {
                mEditText.append(append);
                mText = parseString(mEditText.getText());
            }
        }
        break;
    }
    case ACTION_REQUEST_FEATHER:
        if (resultCode == RESULT_OK) {
            final Uri uri = intent.getData();
            final File file = uri == null ? null : new File(getImagePathFromUri(this, uri));
            if (file != null && file.exists()) {
                mImageUri = Uri.fromFile(file);
                reloadAttachedImageThumbnail(file);
            } else {
                break;
            }
            setMenu();
        }
        break;
    }

}

From source file:com.dwdesign.tweetings.fragment.AccountsFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_SET_COLOR: {
        if (resultCode == Activity.RESULT_OK)
            if (data != null && data.getExtras() != null) {
                final int color = data.getIntExtra(Accounts.USER_COLOR, Color.WHITE);
                final ContentValues values = new ContentValues();
                values.put(Accounts.USER_COLOR, color);
                final String where = Accounts.USER_ID + " = " + mSelectedUserId;
                mResolver.update(Accounts.CONTENT_URI, values, where, null);
                getLoaderManager().restartLoader(0, null, this);
            }//from  ww  w .  java 2  s . c om
        break;
    }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:ca.rmen.android.poetassistant.main.reader.ReaderFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(TAG, "onActivityResult() called with: " + "requestCode = [" + requestCode + "], resultCode = ["
            + resultCode + "], data = [" + data + "]");
    if (requestCode == ACTION_FILE_OPEN && resultCode == Activity.RESULT_OK) {
        if (data != null) {
            Uri uri = data.getData();/*  ww  w. j  a  v  a 2  s  .c  o  m*/
            PoemFile.open(getActivity(), uri, this);
        }
    } else if (requestCode == ACTION_FILE_SAVE_AS && resultCode == Activity.RESULT_OK) {
        if (data != null) {
            Uri uri = data.getData();
            PoemFile.save(getActivity(), uri, mBinding.tvText.getText().toString(), this);
        }
    }
}

From source file:uf.edu.encDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.encdetail_activity);
    context = this.getApplicationContext();
    TextView tv = null;/*ww w.j  a  v a2  s .  com*/
    SeekBar sb = null;
    Button b = null;
    Bundle bundle = this.getIntent().getExtras();
    Log.i("TAG", "encDetailActivity:onCreate,  Max Trust =" + getString(R.string.TrustSliderMax));
    MaxTrust = Integer.parseInt(getString(R.string.TrustSliderMax)) / 2;

    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                //Okay clicked.
                break;

            case DialogInterface.BUTTON_NEGATIVE:
                //No button clicked
                break;
            }
        }
    };

    //builder.setMessage("Are you sure?").setPositiveButton("Okay", dialogClickListener);

    final EncUser encUser = (EncUser) bundle.getSerializable("userdata");
    final ArrayList<String> Address = (ArrayList<String>) bundle.getSerializable("useraddress");
    if (encUser == null) {
        Log.i(TAG, "encDetailsActivity: parameter received was null");
    }
    //Name
    tv = (TextView) findViewById(R.id.encdetail_name);
    tv.setText(encUser.Name);
    //Mac
    tv = (TextView) findViewById(R.id.encdetail_mac);
    tv.setText(encUser.Mac);
    tv.setOnClickListener(new View.OnClickListener() { //event listener to fetch more info abt a user.
        @Override
        public void onClick(View v) {
            iTrust.cd.write("Registration Lookup requested for " + encUser.Mac);
            Toast.makeText(encDetailActivity.this, "Please wait while we lookup the information",
                    Toast.LENGTH_LONG).show();
            String data = getData(encUser.Mac).replace('\n', ' ').trim();
            String message = null;
            if (data.substring(0, 5).compareToIgnoreCase("Error") == 0) {
                message = "No more info available for this device";
            } else {
                data = data.replace('\'', ' '); //remove single quotes
                data = data.replace(')', ' ').trim(); //remove closing brackets.
                StringTokenizer tok = new StringTokenizer(data.substring(1), ",");
                message = "Name: " + tok.nextToken() + " " + tok.nextToken() + "\n" + "Email: "
                        + tok.nextToken() + "\n" + "Profile: " + tok.nextToken();
            }
            //Toast.makeText(encDetailActivity.this, getData(encUser.Mac), Toast.LENGTH_LONG).show();
            builder.setMessage(message);
            builder.show();
        }
    });
    //lasttime
    tv = (TextView) findViewById(R.id.encdetail_lasttime);
    tv.setText((new java.util.Date((long) encUser.lastEncounterTime * 1000)).toString());
    tv.setOnClickListener(new View.OnClickListener() { //To generate graph
        @Override
        public void onClick(View v) {
            Intent intent = barchartIntent(encUser.timeSeries, encUser.Mac, encUser.Name);
            startActivity(intent);
        }
    });

    //tv.setText(Integer.toString(encUser.lastEncounterTime)); 
    //FE
    tv = (TextView) findViewById(R.id.encdetail_FE);
    tv.setText(Float.toString(encUser.score[0]));
    tv = (TextView) findViewById(R.id.encdetail_decayFE);
    tv.setText(Float.toString(encUser.decayScore[0] * ((float) Math.pow(.5,
            (float) (((float) System.currentTimeMillis() / 1000) - (float) encUser.lastEncounterTime)
                    / (float) 15552000.0F))));
    //DE
    tv = (TextView) findViewById(R.id.encdetail_DE);
    tv.setText(Float.toString(encUser.score[1]));
    tv = (TextView) findViewById(R.id.encdetail_decayDE);
    tv.setText(Float.toString(encUser.decayScore[1] * ((float) Math.pow(.5,
            (float) (((float) System.currentTimeMillis() / 1000) - (float) encUser.lastEncounterTime)
                    / (float) 15552000.0F))));
    //LV-C
    tv = (TextView) findViewById(R.id.encdetail_LVC);
    tv.setText(Float.toString(encUser.score[2]));
    //LV-D
    tv = (TextView) findViewById(R.id.encdetail_LVD);
    tv.setText(Float.toString(encUser.score[3]));
    //combined 
    //FE
    tv = (TextView) findViewById(R.id.encdetail_comb);
    tv.setText(Float.toString(encUser.score[4]));

    //check the toggle button state

    sb = (SeekBar) findViewById(R.id.encdetail_trust);
    //since Seekbar cannot go into -ve values we scale -Max Value to Max Value
    sb.setProgress(encUser.trusted + MaxTrust);
    tv = (TextView) findViewById(R.id.CurrentTrustValue);
    tv.setText(TrustArray[encUser.trusted + MaxTrust]);

    sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        TextView tvcurrent = (TextView) findViewById(R.id.CurrentTrustValue);

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser == true) {
                Log.i(TAG, "encDetailsActivity: User changed value for Trust to " + progress);
                encUser.trusted = progress - MaxTrust;
                tvcurrent.setText(TrustArray[progress]);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }
    });

    b = (Button) findViewById(R.id.encdetail_done);
    b.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            iTrust.cd.write("Trust Value changed for this user :" + encUser.Mac + " to:" + encUser.trusted);
            Bundle bundle = new Bundle();
            Intent returnIntent = new Intent();
            bundle.putSerializable("Object", encUser);
            returnIntent.putExtras(bundle);
            //returnIntent.putExtra("TrustSet",trustResult);
            encDetailActivity.this.setResult(Activity.RESULT_OK, returnIntent);
            finish();
        }
    });

    //show map
    tv = (TextView) findViewById(R.id.encdetail_map);
    tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            iTrust.cd.write("Map lookup for encounter user " + encUser.Mac);
            Bundle bundle = new Bundle();
            Intent newIntent = new Intent(context, map.class);
            bundle.putSerializable("useraddress", Address);
            newIntent.putExtras(bundle);
            startActivity(newIntent);
        }
    });

}

From source file:com.gmail.srivi.sundaram.locgenie.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // Choose what to do based on the request code
    switch (requestCode) {

    // If the request code matches the code sent in onConnectionFailed
    case LocationUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST:

        switch (resultCode) {
        // If Google Play services resolved the problem
        case Activity.RESULT_OK:

            // Log the result
            Log.d(LocationUtils.APPTAG, getString(R.string.resolved));

            // Display the result
            // mConnectionState.setText(R.string.connected);
            // mConnectionStatus.setText(R.string.resolved);
            break;

        // If any other result was returned by Google Play services
        default://from   w w w  .j  av  a 2 s .  co  m
            // Log the result
            Log.d(LocationUtils.APPTAG, getString(R.string.no_resolution));

            // Display the result
            // mConnectionState.setText(R.string.disconnected);
            // mConnectionStatus.setText(R.string.no_resolution);

            break;
        }

        // If any other request code was received
    default:
        // Report that this Activity received an unknown requestCode
        Log.d(LocationUtils.APPTAG, getString(R.string.unknown_activity_request_code, requestCode));

        break;
    }
}