Java Code Examples for android.app.Activity#RESULT_OK

The following examples show how to use android.app.Activity#RESULT_OK . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DoubanTop   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    mSearchHistoryList.setVisibility(View.VISIBLE);
    if (requestCode == VOICE_ACTIVITY_RESULT_CODE && resultCode == Activity.RESULT_OK) {
        Bundle results = data.getExtras();
        if (results == null) {
            return;
        }
        ArrayList<String> nbest = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
        if (nbest == null || nbest.size() == 0) {
            return;
        }
        // now we just get the first result
        String result = nbest.get(0);
        mSearchInputEditText.setText(result);
        mSearchInputEditText.setSelection(result.length());
    }
}
 
Example 2
Source Project: imsdk-android   File: QRCodeManager.java    License: MIT License 6 votes vote down vote up
/**
 * 结果回调
 *
 * @param requestCode 请求码
 * @param resultCode  结果码
 * @param data        数据
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (callback == null) {
        return;
    }
    if (requestCode == curRequestCode && resultCode == Activity.RESULT_OK) {//成功
        String result = data.getStringExtra("result");
        if (TextUtils.isEmpty(result)) {
            callback.onError(new Throwable("result is null"));
        } else {
            callback.onCompleted(result);
        }
    } else if (requestCode == curRequestCode && resultCode == Activity.RESULT_CANCELED) {//取消
        callback.onCancel();
    }
}
 
Example 3
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_LOAD_IMAGE && data != null) {
            selectedImageUri = data.getData();
            if (selectedImageUri == null) {
                genericError();
            }
        } else if (requestCode == REQUEST_IMAGE_CAPTURE) {
            // Do something with imagePath
            //selectedImageUri has the path
        }

        if (selectedImageUri != null) {
            listener.onImageArrived(selectedImageUri);
        }
    }
}
 
Example 4
@Override
boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    // Handle stuff
    Result outcome;

    if (data == null) {
        // This happens if the user presses 'Back'.
        outcome = Result.createCancelResult(pendingRequest, "Operation canceled");
    } else if (resultCode == Activity.RESULT_CANCELED) {
        outcome = Result.createCancelResult(pendingRequest, data.getStringExtra("error"));
    } else if (resultCode != Activity.RESULT_OK) {
        outcome = Result.createErrorResult(pendingRequest, "Unexpected resultCode from authorization.", null);
    } else {
        outcome = handleResultOk(data);
    }

    if (outcome != null) {
        completeAndValidate(outcome);
    } else {
        tryNextHandler();
    }
    return true;
}
 
Example 5
public void parseAndVerifyPurchaseItemResultAsync(int requestCode, int resultCode, Intent data) {
	if (requestCode == ACTIVITY_RESULT_CODE_PURCHASE_ITEM) {
		int responseCode = data.getIntExtra(RESPONSE_CODE, 0);

		if (resultCode == Activity.RESULT_OK && responseCode == RESPONSE_RESULT_OK) {
			String payload = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
			String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

			Purchasable item = LinphonePreferences.instance().getInAppPurchasedItem();
			item.setPayloadAndSignature(payload, signature);
			LinphonePreferences.instance().setInAppPurchasedItem(item);
			
			XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
			xmlRpcHelper.verifySignatureAsync(new XmlRpcListenerBase() {
				@Override
				public void onSignatureVerified(boolean success) {
					mListener.onPurchasedItemConfirmationQueryFinished(success);
				}
			}, payload, signature);
		}
	}
}
 
Example 6
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
	if (requestCode == REQUEST_CODE_OPEN_BLE && resultCode == Activity.RESULT_OK) {
	    // open gps
        if (isGpsOPen(getContext())) {
            permissionGranted();
        } else {
            // 开启GPS
            displayPromptForEnablingGPS();
        }

    } else if (requestCode == REQUEST_CODE_OPEN_GPS && resultCode == Activity.RESULT_OK) {
        // 开启GPS
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (bluetoothAdapter != null) {
            permissionGranted();
        }
    } else {
		super.onActivityResult(requestCode, resultCode, data);
	}
}
 
Example 7
Source Project: ThirdPartyLoginDemo   File: SignupPage.java    License: MIT License 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
	if(requestCode == INTENT_ACTION_PICTURE && resultCode == Activity.RESULT_OK && null != data){
		Cursor c = activity.getContentResolver().query(data.getData(), null, null, null, null);
		c.moveToNext();
		String path = c.getString(c.getColumnIndex(MediaStore.MediaColumns.DATA));
		c.close();
		System.out.println("onActivityResult == " + path);
		if(new File(path).exists()){
			System.out.println("onActivityResult == " + path +" == exist");
			userInfo.setUserIcon(path);
			ivUserIcon.setImageBitmap(compressImageFromFile(path));
			//ivUserIcon.setImageURI(Uri.parse(path));
			//ivUserIcon.setImageDrawable(Drawable.createFromPath(path));
		}
	}else if(requestCode == INTENT_ACTION_CAREMA && resultCode == Activity.RESULT_OK){
		userInfo.setUserIcon(picturePath);
		//ivUserIcon.setImageURI(Uri.parse(picturePath));
		ivUserIcon.setImageDrawable(Drawable.createFromPath(picturePath));
	}else if(requestCode == INTENT_ACTION_CROP && resultCode == Activity.RESULT_OK && null != data){
		//ivUserIcon.setImageURI(Uri.parse(picturePath));
		ivUserIcon.setImageDrawable(Drawable.createFromPath(picturePath));
	}
}
 
Example 8
@Override
boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    // Handle stuff
    Result outcome;

    if (data == null) {
        // This happens if the user presses 'Back'.
        outcome = Result.createCancelResult(pendingRequest, "Operation canceled");
    } else if (resultCode == Activity.RESULT_CANCELED) {
        outcome = Result.createCancelResult(pendingRequest, data.getStringExtra("error"));
    } else if (resultCode != Activity.RESULT_OK) {
        outcome = Result.createErrorResult(pendingRequest, "Unexpected resultCode from authorization.", null);
    } else {
        outcome = handleResultOk(data);
    }

    if (outcome != null) {
        completeAndValidate(outcome);
    } else {
        tryNextHandler();
    }
    return true;
}
 
Example 9
Source Project: UniFile   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;
    }
    startFileActivity(data.getData());
}
 
Example 10
Source Project: LauncherTV   File: ApplicationFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
	super.onActivityResult(requestCode, resultCode, intent);
	switch (requestCode) {
		case REQUEST_CODE_WALLPAPER:
			break;
		case REQUEST_CODE_PREFERENCES:
			restartActivity();
			break;
		case REQUEST_CODE_APPLICATION_START:
			if (intent != null)
				openApplication(intent.getExtras().getString(ApplicationList.PACKAGE_NAME));
			break;
		case REQUEST_CODE_APPLICATION_LIST:
			if (resultCode == Activity.RESULT_OK) {
				Bundle extra = intent.getExtras();
				int appNum = intent.getExtras().getInt(ApplicationList.APPLICATION_NUMBER);

				if (extra.containsKey(ApplicationList.DELETE) && extra.getBoolean(ApplicationList.DELETE)) {
					writePreferences(appNum, null);
				} else {
					writePreferences(appNum,
							intent.getExtras().getString(ApplicationList.PACKAGE_NAME)
					);
				}
				updateApplications();
			}
			break;
	}
}
 
Example 11
Source Project: appinventor-extensions   File: Texting.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Callback method to handle the result of attempting to send a message. 
 * Each message is assigned a Broadcast receiver that is notified by 
 * the phone's radio regarding the status of the sent message. The 
 * receivers call this method.  (See transmitMessage() method below.)
 * 
 * @param context
 *            The context in which the calling BroadcastReceiver is running.
 * @param receiver
 *            Currently unused. Intended as a special BroadcastReceiver to
 *            send results to. (For instance, if another plugin wanted to do
 *            its own handling.)
 * @param resultCode, the code sent back by the phone's Radio
 * @param seq, the message's sequence number
 * @param smsMsg, the message being processed
 */
private synchronized void handleSentMessage(Context context,
                                            BroadcastReceiver receiver, int resultCode, String smsMsg) {
  switch (resultCode) {
    case Activity.RESULT_OK:
      Log.i(TAG, "Received OK, msg:" + smsMsg);
      Toast.makeText(activity, "Message sent", Toast.LENGTH_SHORT).show();
      break;
    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
      Log.e(TAG, "Received generic failure, msg:" + smsMsg);
      Toast.makeText(activity, "Generic failure: message not sent", Toast.LENGTH_SHORT).show();
      break;
    case SmsManager.RESULT_ERROR_NO_SERVICE:
      Log.e(TAG, "Received no service error, msg:"  + smsMsg);
      Toast.makeText(activity, "No Sms service available. Message not sent.", Toast.LENGTH_SHORT).show();
      break;
    case SmsManager.RESULT_ERROR_NULL_PDU:
      Log.e(TAG, "Received null PDU error, msg:"  + smsMsg);
      Toast.makeText(activity, "Received null PDU error. Message not sent.", Toast.LENGTH_SHORT).show();
      break;
    case SmsManager.RESULT_ERROR_RADIO_OFF:
      Log.e(TAG, "Received radio off error, msg:" + smsMsg);
      Toast.makeText(activity, "Could not send SMS message: radio off.", Toast.LENGTH_LONG).show();
      break;
  }
}
 
Example 12
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  Log.i(getString(R.string.app_name), LOCAL_TAG + ": onActivityResult");
  if (requestCode == SCAN_REQUEST && resultCode == Activity.RESULT_OK) {
    // Grab the scan results and convert it into a URI
    String scanResult =
        (intent != null)
            ? intent.getStringExtra(BarcodeCaptureActivity.INTENT_EXTRA_BARCODE_VALUE)
            : null;
    Uri uri = (scanResult != null) ? Uri.parse(scanResult) : null;
    interpretScanResult(uri, false);
  }
}
 
Example 13
private void onGroupManagerResult(int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;
    }

    HashSet<String> groups = new HashSet<>(data.getStringArrayListExtra("groups"));

    for (VaultEntry entry : _vault.getEntries()) {
        if (!groups.contains(entry.getGroup())) {
            entry.setGroup(null);
        }
    }
}
 
Example 14
Source Project: BitmapMerger   File: BitmapAngleFragment.java    License: MIT License 5 votes vote down vote up
@Override
public void onActivityResult(final int requestCode, int resultCode, Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    switch (requestCode) {
        case SELECT_PHOTO_1:
        case SELECT_PHOTO_2:
            if (resultCode == Activity.RESULT_OK) {
                final Uri imageUri = imageReturnedIntent.getData();

                int dimens[] = getDimens(R.id.image_holder);

                new BitmapDecoderTask()
                        .setDecodingImageReference(imageUri, getActivity().getContentResolver())
                        .setRequiredWidth(dimens[0])
                        .setRequiredHeight(dimens[1])
                        .setListener(new BitmapDecoderTask.OnDecodeListener() {
                            @Override
                            public void onDecode(BitmapDecoderTask task, Bitmap bitmap) {

                                if (requestCode == SELECT_PHOTO_1) {

                                    mBaseBitmap = bitmap;

                                } else {

                                    mMergeBitmap = bitmap;

                                }
                                refresh();
                            }
                        })
                        .decode();

            }
    }
}
 
Example 15
Source Project: rpicheck   File: NewRaspiAuthActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_LOAD_FILE && resultCode == Activity.RESULT_OK) {
        final String filePath = data.getData().getPath();
        LOGGER.debug("Path of selected keyfile: {}", filePath);
        this.keyfilePath = filePath;
        // set text to filename, not full path
        String fileName = getFilenameFromPath(filePath);
        buttonKeyfile.setText(fileName);
        buttonKeyfile.setError(null);
    }
}
 
Example 16
Source Project: DevUtils   File: QRCodeCreateActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // 判断是否属于图片选择
    if (resultCode == Activity.RESULT_OK && data != null) {
        LocalMedia localMedia = PictureSelectorUtils.getSingleMedia(data);
        // 获取图片地址
        String imgPath = PictureSelectorUtils.getLocalMediaPath(localMedia, true);
        // 获取图片 Bitmap
        selectBitmap = ImageUtils.decodeFile(imgPath);
    }
}
 
Example 17
Source Project: styT   File: loveviayou.java    License: Apache License 2.0 5 votes vote down vote up
public static void Modi_WangYi_Mp3_UI_doing(Activity con, int requestCode, int resultCode, Intent in) {
    if (requestCode == requestcode && resultCode == Activity.RESULT_OK) {
        Uri uri = in.getData();
        ContentResolver cr = con.getContentResolver();
        try {
            Bitmap bmp = BitmapFactory.decodeStream(cr.openInputStream(uri));
            File[] files = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/netease/cloudmusic/Ad/").listFiles();
            if (files == null) {
                Toast.makeText(con, "没安装网易音乐或者是没有加载广告", Toast.LENGTH_LONG).show();
                return;
            }
            Vector<String> c = new Vector<String>();
            for (File f : files) {
                if (f.isDirectory()) {
                    File[] temp_files = f.listFiles();
                    if (temp_files == null) continue;
                    for (File inner_f : temp_files) {

                        if (inner_f.isFile())
                            c.add(inner_f.getAbsolutePath());
                    }
                }
                if (f.isFile())
                    c.add(f.getAbsolutePath());
            }
            for (String s : c) {
                OutputStream ops = new FileOutputStream(s);
                bmp.compress(Bitmap.CompressFormat.JPEG, 100, ops);
            }


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        Toast.makeText(con, "替换完成", Toast.LENGTH_SHORT).show();
        //finish();
    }
}
 
Example 18
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (requestCode == mRequestCodeFilePicker) {
        if (resultCode == Activity.RESULT_OK) {
            if (intent != null) {
                if (mFileUploadCallbackFirst != null) {
                    mFileUploadCallbackFirst.onReceiveValue(intent.getData());
                    mFileUploadCallbackFirst = null;
                } else if (mFileUploadCallbackSecond != null) {
                    Uri[] dataUris = null;

                    try {
                        if (intent.getDataString() != null) {
                            dataUris = new Uri[]{Uri.parse(intent.getDataString())};
                        } else {
                            if (Build.VERSION.SDK_INT >= 16) {
                                if (intent.getClipData() != null) {
                                    final int numSelectedFiles = intent.getClipData().getItemCount();

                                    dataUris = new Uri[numSelectedFiles];

                                    for (int i = 0; i < numSelectedFiles; i++) {
                                        dataUris[i] = intent.getClipData().getItemAt(i).getUri();
                                    }
                                }
                            }
                        }
                    } catch (Exception ignored) {
                    }

                    mFileUploadCallbackSecond.onReceiveValue(dataUris);
                    mFileUploadCallbackSecond = null;
                }
            }
        } else {
            if (mFileUploadCallbackFirst != null) {
                mFileUploadCallbackFirst.onReceiveValue(null);
                mFileUploadCallbackFirst = null;
            } else if (mFileUploadCallbackSecond != null) {
                mFileUploadCallbackSecond.onReceiveValue(null);
                mFileUploadCallbackSecond = null;
            }
        }
    }
}
 
Example 19
Source Project: Cashier   File: InAppBillingV3Vendor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
  log("onActivityResult " + resultCode);
  if (this.requestCode != requestCode) {
    return false;
  }

  if (data == null) {
    purchaseListener.failure(pendingProduct, purchaseError(BILLING_RESPONSE_RESULT_ERROR));
    return true;
  }

  final int responseCode = getResponseCode(data);
  if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) {
    try {
      final InAppBillingPurchase purchase = InAppBillingPurchase.create(pendingProduct, data);
      if (!purchase.developerPayload().equals(developerPayload)) {
        log("Developer payload mismatch!");
        purchaseListener.failure(pendingProduct,
            new Vendor.Error(PURCHASE_SUCCESS_RESULT_MALFORMED,
                BILLING_RESPONSE_RESULT_ERROR));
        return true;
      }

      if (!TextUtils.isEmpty(publicKey64)
          && !InAppBillingSecurity.verifySignature(publicKey64, purchase.receipt(), purchase.dataSignature())) {
        log("Local signature check failed!");
        purchaseListener.failure(pendingProduct,
            new Vendor.Error(PURCHASE_SUCCESS_RESULT_MALFORMED,
                BILLING_RESPONSE_RESULT_ERROR));
        return true;
      }

      log("Successful purchase of " + pendingProduct.sku() + "!");
      purchaseListener.success(purchase);
      developerPayload = null;
    } catch (JSONException e) {
      purchaseListener.failure(pendingProduct,
          new Vendor.Error(PURCHASE_SUCCESS_RESULT_MALFORMED,
              BILLING_RESPONSE_RESULT_ERROR));
    }
  } else if (resultCode == Activity.RESULT_OK) {
    log("CashierPurchase failed! " + responseCode);
    purchaseListener.failure(pendingProduct, purchaseError(responseCode));
  } else {
    log("CashierPurchase canceled! " + responseCode);
    purchaseListener.failure(pendingProduct, purchaseError(responseCode));
  }

  return true;
}
 
Example 20
Source Project: SystemUITuner2   File: IabHelper.java    License: MIT License 4 votes vote down vote up
/**
 * 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 [email protected]} 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.
 */
@SuppressWarnings("unused")
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != mRequestCode) return false;

    checkNotDisposed();
    checkSetupDone("handleActivityResult");

    // end of async purchase operation that started on launchPurchaseFlow
    flagEndAsync();

    if (data == null) {
        logError("Null data in IAB activity result.");
        result = new IabResult(IABHELPER_BAD_RESPONSE, "Null data in IAB result");
        if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(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 == 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: " + mPurchasingItemType);

        if (purchaseData == null || dataSignature == null) {
            logError("BUG: either purchaseData or dataSignature is null.");
            logDebug("Extras: " + data.getExtras().toString());
            result = new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature");
            if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        @SuppressWarnings("UnusedAssignment") Purchase purchase = null;
        try {
            purchase = new Purchase(mPurchasingItemType, purchaseData, dataSignature);
            String sku = purchase.getSku();

            // Verify signature
            if (!Security.verifyPurchase(mSignatureBase64, purchaseData, dataSignature)) {
                logError("Purchase signature verification FAILED for sku " + sku);
                result = new IabResult(IABHELPER_VERIFICATION_FAILED, "Signature verification failed for sku " + sku);
                if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, purchase);
                return true;
            }
            logDebug("Purchase signature successfully verified.");
        }
        catch (JSONException e) {
            logError("Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        if (mPurchaseListener != null) {
            mPurchaseListener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Success"), purchase);
        }
    }
    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));
        if (mPurchaseListener != null) {
            result = new IabResult(responseCode, "Problem purchashing item.");
            mPurchaseListener.onIabPurchaseFinished(result, null);
        }
    }
    else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
        if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    else {
        logError("Purchase failed. Result code: " + Integer.toString(resultCode)
                + ". Response: " + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    return true;
}