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: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 {//  www  . 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:ca.utoronto.ece1778.baton.gcm.client.main.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
    Log.i(TAG, context.getPackageName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
}

From source file:com.ibm.mil.readyapps.telco.utils.TelcoChallengeHandler.java

@Override
public void handleChallenge(WLResponse response) {
    cachedResponse = response;/* ww w  . j  av a 2  s . co m*/
    /* This is where a developer would traditionally have code to spawn a login activity */
    Log.i("TEST", "HANDLE CHALLENGE EXECUTED");
    submitLogin(Activity.RESULT_OK, DEMO_USERNAME, DEMO_PASSWORD, false);
}

From source file:com.appsimobile.appsii.iab.IabPurchaseHelper.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 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./*from   w  w w.ja v a  2  s  .c  o  m*/
 */
public static int handleActivityResult(int resultCode, Intent data,
        OnIabPurchaseFinishedListener purchaseListener, String itemType, String devPayload) {

    if (data == null) {
        logError("Null data in IAB activity result.");
        return IABHELPER_BAD_RESPONSE;
    }

    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 == BILLING_RESPONSE_RESULT_OK) {
        logDebug("Successful resultcode from purchase activity.");
        logDebug("Purchase data: " + purchaseData);
        logDebug("Data signature: " + dataSignature);
        logDebug("Extras: " + data.getExtras());
        logDebug("Expected item type: " + itemType);

        if (purchaseData == null || dataSignature == null) {
            logError("BUG: either purchaseData or dataSignature is null.");
            logDebug("Extras: " + data.getExtras().toString());
            return IABHELPER_UNKNOWN_ERROR;
        }

        Purchase purchase;
        try {
            purchase = new Purchase(itemType, purchaseData, dataSignature);
            String sku = purchase.getSku();

            // Verify signature
            if (!Security.verifyPurchase(RSA_CODE, purchaseData, dataSignature)) {
                logError("Purchase signature verification FAILED for sku " + sku);
                return IABHELPER_VERIFICATION_FAILED;
            }
            logDebug("Purchase signature successfully verified.");
            if (!Security.verifyDeveloperPayload(purchase, devPayload)) {
                logError("Purchase payload verification FAILED for sku " + sku);
                return IABHELPER_DEVELOPER_PAYLOAD_FAILED;
            }
            logDebug("Developer payload successfully verified.");
        } catch (JSONException e) {
            logError("Failed to parse purchase data.");
            e.printStackTrace();
            return IABHELPER_BAD_RESPONSE;
        }

        if (purchaseListener != null) {
            purchaseListener.onIabPurchaseSuccess(purchase);
        }
        return BILLING_RESPONSE_RESULT_OK;

    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode));
        return responseCode;
    } else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        return IABHELPER_USER_CANCELLED;
    } else {
        logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: "
                + getResponseDesc(responseCode));
        return IABHELPER_UNKNOWN_PURCHASE_RESPONSE;
    }
}

From source file:can.yrt.onebusaway.MyStopListFragmentBase.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    StopData stopData = getStopData(l, position);

    ArrivalsListActivity.Builder b = stopData.getArrivalsList();

    if (isShortcutMode()) {
        final Intent shortcut = UIHelp.makeShortcut(getActivity(), stopData.getUiName(), b.getIntent());

        Activity activity = getActivity();
        activity.setResult(Activity.RESULT_OK, shortcut);
        activity.finish();/*from   w w  w  .  j a v a2 s.  c  om*/
    } else {
        b.setUpMode(NavHelp.UP_MODE_BACK);
        b.start();
    }
}

From source file:com.example.AllSOSservice.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(), Activity.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);

    String message = intent.getStringExtra("message");
    String email = intent.getStringExtra("email");
    String latitude = intent.getStringExtra("latitude");
    String longitude = intent.getStringExtra("longitude");

    Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
    toast.show();/*from ww  w.  j  a v a 2 s.co  m*/

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Novo Pedido de Ajuda!")
            .setContentText("Alguem precisa de um " + message);

    Intent resultIntent = null;
    try {
        if (isLoggedIn()) {
            resultIntent = new Intent(context, LoggedInActivity.class);
        } else {
            resultIntent = new Intent(context, LoginActivity.class);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (TimeoutException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    // Because clicking the notification opens a new ("special") activity, there's
    // no need to create an artificial back stack.
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);

    int mNotificationId = 001;
    // Gets an instance of the NotificationManager service
    NotificationManager mNotifyMgr = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
    mNotifyMgr.notify(mNotificationId, mBuilder.build());
}

From source file:com.swisscom.safeconnect.utils.gcm.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    setResultCode(Activity.RESULT_OK);
    Bundle extras = intent.getExtras();//  w  ww. j a v a2  s. co m
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            if (BuildConfig.DEBUG)
                Log.d(Config.TAG, "Error receiving push notification: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            if (BuildConfig.DEBUG)
                Log.d(Config.TAG, "Deleted messages on server: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            if (BuildConfig.DEBUG)
                Log.d(Config.TAG, "Received: " + extras.toString());

            String key = extras.getString("key");
            String args_json = extras.getString("args");

            if (key != null) {
                int resId = context.getResources().getIdentifier(key, "string", context.getPackageName());

                if (resId != 0) {
                    Object[] args = convertJsonToStringArray(args_json);
                    String title = context.getString(R.string.push_title);
                    String msg = context.getString(resId, args);
                    //String title = extras.getString("title");
                    //String msg = extras.getString("message");
                    sendNotification(title, msg, context);
                }
            }
        }
    }
}

From source file:ca.uwaterloo.magic.goodhikes.AddMilestoneDialogFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RESULT_LOAD_IMG) {
        if (resultCode == Activity.RESULT_OK) {
            Uri selectedImage = data.getData();
            Bitmap bitmap = null;// ww  w  .  j  av a2  s  . c  om
            try {
                bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), selectedImage);
                bitmap = Bitmap.createScaledBitmap(bitmap, 300, 225, false);
            } catch (IOException e) {
                Log.d(LOG_TAG,
                        "Thread: " + Thread.currentThread().getId() + "; Couldn't load the image selected");
                //                    e.printStackTrace();
            }
            //                previewImage.setImageURI(selectedImage);
            previewImage.setImageBitmap(bitmap);
        }
    }
    if (requestCode == RESULT_CAPTURE_IMG) {
        if (resultCode == Activity.RESULT_OK) {
            Bitmap imageBitmap = (Bitmap) data.getExtras().get("data");
            imageBitmap = Bitmap.createScaledBitmap(imageBitmap, 300, 225, false);
            previewImage.setImageBitmap(imageBitmap);
        }
    }
}

From source file:com.nanostuffs.yurdriver.GCMIntentService.java

@Override
protected void onRegistered(Context context, String registrationId) {
    AppLog.Log(TAG, "Device registered: regId = " + registrationId);
    CommonUtilities.displayMessage(context, "Device Registerd");
    new PreferenceHelper(context).putDeviceToken(registrationId);
    publishResults(registrationId, Activity.RESULT_OK);
    // GCMRegisterHendler.onRegComplete(registrationId);
}

From source file:com.ibm.mil.readyapps.telco.utils.TelcoChallengeHandler.java

private void submitLogin(int resultCode, String userName, String password, boolean back) {
    if (resultCode != Activity.RESULT_OK || back) {
        submitFailure(cachedResponse);// w ww .  j a  v a2s.c o m
    } else {
        Object[] parameters = new Object[] { userName, password };
        WLProcedureInvocationData invocationData = new WLProcedureInvocationData(TELCO_AUTH_ADAPTER,
                TELCO_AUTH_METHOD);
        invocationData.setParameters(parameters);
        WLRequestOptions options = new WLRequestOptions();

        options.setTimeout(30000);
        submitAdapterAuthentication(invocationData, options);

        Log.i("TEST", "SUBMIT LOGIN");
    }
}