Java Code Examples for android.app.Activity#startIntentSenderForResult()

The following examples show how to use android.app.Activity#startIntentSenderForResult() . 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 File: ShortcutConfigActivityInfo.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean startConfigActivity(Activity activity, int requestCode) {
    if (getUser().equals(Process.myUserHandle())) {
        return super.startConfigActivity(activity, requestCode);
    }
    try {
        Method m = LauncherApps.class.getDeclaredMethod(
                "getShortcutConfigActivityIntent", LauncherActivityInfo.class);
        IntentSender is = (IntentSender) m.invoke(
                activity.getSystemService(LauncherApps.class), mInfo);
        activity.startIntentSenderForResult(is, requestCode, null, 0, 0, 0);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 2
Source File: DonateActivity.java    From always-on-amoled with GNU General Public License v3.0 6 votes vote down vote up
public static void quicklyPromptToSupport(final Activity context, final View rootView) {
    if (mService != null) {
        String googleIAPCode = SecretConstants.getPropertyValue(context, "googleIAPCode");
        String IAP = SecretConstants.getPropertyValue(context, "IAPID1");
        try {
            Bundle buyIntentBundle = mService.getBuyIntent(3, context.getPackageName(),
                    IAP, "inapp", googleIAPCode);
            PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
            if (pendingIntent == null)
                Snackbar.make(rootView, context.getString(R.string.error_IAP), Snackbar.LENGTH_LONG).show();
            else
                context.startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), 0, 0, 0);
        } catch (RemoteException | IntentSender.SendIntentException e) {
            Snackbar.make(rootView, context.getString(R.string.error_0_unknown_error) + e.getMessage(), Snackbar.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }
}
 
Example 3
Source File: Accountant.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/** Launches the purchase flow (Google Play UI to complete in-app purchase. */
public boolean buy(Activity activity, String sku) {
    if (null == mService || activity == null) return false;
    LogUtils.LOGI("Accountant", "buy(" + sku + ')');
    try {
        Bundle bundle = mService.getBuyIntent(3, activity.getPackageName(),
                sku, ITEM_TYPE_INAPP, null);
        LogUtils.LOGD("Accountant", Utils.bundle2string(bundle));

        PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
        if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
            // Start purchase flow (this brings up the Google Play UI).
            // Result will be delivered through onActivityResult().
            activity.startIntentSenderForResult(pendingIntent.getIntentSender(),
                    RESULT_CODE_BUY, new Intent(), 0, 0, 0);
            return true;
        }
    } catch (Throwable t) {
        LogUtils.LOGE("Accountant", "Error launching in-app purchase Intent.", t);
    }
    return false;
}
 
Example 4
Source File: ActivityWindowAndroid.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public int showCancelableIntent(
        PendingIntent intent, IntentCallback callback, Integer errorId) {
    Activity activity = getActivity().get();
    if (activity == null) return START_INTENT_FAILURE;

    int requestCode = generateNextRequestCode();

    try {
        activity.startIntentSenderForResult(
                intent.getIntentSender(), requestCode, new Intent(), 0, 0, 0);
    } catch (SendIntentException e) {
        return START_INTENT_FAILURE;
    }

    storeCallbackData(requestCode, callback, errorId);
    return requestCode;
}
 
Example 5
Source File: Accountant.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/** Launches the purchase flow (Google Play UI to complete in-app purchase. */
public boolean buy(Activity activity, String sku) {
    if (null == mService || activity == null) return false;
    LogUtils.LOGI("Accountant", "buy(" + sku + ')');
    try {
        Bundle bundle = mService.getBuyIntent(3, activity.getPackageName(),
                sku, ITEM_TYPE_INAPP, null);
        LogUtils.LOGD("Accountant", Utils.bundle2string(bundle));

        PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
        if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
            // Start purchase flow (this brings up the Google Play UI).
            // Result will be delivered through onActivityResult().
            activity.startIntentSenderForResult(pendingIntent.getIntentSender(),
                    RESULT_CODE_BUY, new Intent(), 0, 0, 0);
            return true;
        }
    } catch (Throwable t) {
        LogUtils.LOGE("Accountant", "Error launching in-app purchase Intent.", t);
    }
    return false;
}
 
Example 6
Source File: PurchaseFlowLauncher.java    From android-easy-checkout with Apache License 2.0 5 votes vote down vote up
private void startBuyIntent(final Activity activity,
                            final PendingIntent pendingIntent,
                            int requestCode) throws BillingException {

    IntentSender sender = pendingIntent.getIntentSender();
    try {
        activity.startIntentSenderForResult(sender, requestCode, new Intent(), 0, 0, 0);

    } catch (IntentSender.SendIntentException e) {
        throw new BillingException(Constants.ERROR_SEND_INTENT_FAILED, e.getMessage());
    }
}
 
Example 7
Source File: ActivityUtils.java    From CumulusTV with MIT License 5 votes vote down vote up
public static void syncFile(Activity activity, GoogleApiClient gapi) {
    if (DEBUG) {
    Log.d(TAG, "About to sync a file");
    }
    if (gapi == null && mCloudStorageProvider.connect(activity) != null) {
        gapi = mCloudStorageProvider.connect(activity);
    } else if(mCloudStorageProvider.connect(activity) == null) {
        // Is not existent
        Toast.makeText(activity, "There is no Google Play Service", Toast.LENGTH_SHORT).show();
        return;
    }
    if (gapi.isConnected()) {
        IntentSender intentSender = Drive.DriveApi
                .newOpenFileActivityBuilder()
                .setMimeType(new String[]{"application/json", "text/*"})
                .build(gapi);
        try {
            if (DEBUG) {
                Log.d(TAG, "About to start activity");
            }
            activity.startIntentSenderForResult(intentSender, REQUEST_CODE_OPENER, null, 0, 0,
                    0);
            if (DEBUG) {
                Log.d(TAG, "Activity activated");
            }
        } catch (IntentSender.SendIntentException e) {
            if (DEBUG) {
                Log.w(TAG, "Unable to send intent", e);
            }
            e.printStackTrace();
        }
    } else {
        Toast.makeText(activity, R.string.toast_msg_wait_google_api_client,
                Toast.LENGTH_SHORT).show();
    }
}
 
Example 8
Source File: PhoneNumberHelper.java    From react-native-sms-retriever with MIT License 4 votes vote down vote up
void requestPhoneNumber(@NonNull final Context context, final Activity activity, final Promise promise) {
    if (promise == null) {
        callAndResetListener();
        return;
    }

    mPromise = promise;

    if (!GooglePlayServicesHelper.isAvailable(context)) {
        promiseReject(GooglePlayServicesHelper.UNAVAILABLE_ERROR_TYPE, GooglePlayServicesHelper.UNAVAILABLE_ERROR_MESSAGE);
        callAndResetListener();
        return;
    }

    if (!GooglePlayServicesHelper.hasSupportedVersion(context)) {
        promiseReject(GooglePlayServicesHelper.UNSUPORTED_VERSION_ERROR_TYPE, GooglePlayServicesHelper.UNSUPORTED_VERSION_ERROR_MESSAGE);
        callAndResetListener();
        return;
    }

    if (activity == null) {
        promiseReject(ACTIVITY_NULL_ERROR_TYPE, ACTIVITY_NULL_ERROR_MESSAGE);
        callAndResetListener();
        return;
    }

    final HintRequest request = new HintRequest.Builder()
            .setPhoneNumberIdentifierSupported(true)
            .build();

    final GoogleApiClient googleApiClient = getGoogleApiClient(context, activity);

    final PendingIntent intent = Auth.CredentialsApi
            .getHintPickerIntent(googleApiClient, request);

    try {
        activity.startIntentSenderForResult(intent.getIntentSender(),
                REQUEST_PHONE_NUMBER_REQUEST_CODE, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        promiseReject(SEND_INTENT_ERROR_TYPE, SEND_INTENT_ERROR_MESSAGE);
        callAndResetListener();
    }
}
 
Example 9
Source File: InAppBillingV3Vendor.java    From Cashier with Apache License 2.0 4 votes vote down vote up
@Override
public void purchase(Activity activity, Product product, String developerPayload,
                     PurchaseListener listener) {
  if (activity == null || product == null || listener == null) {
    throw new IllegalArgumentException("Activity, product, or listener is null");
  }

  throwIfUninitialized();

  if (!canPurchase(product)) {
    throw new IllegalArgumentException("Cannot purchase given product!" + product.toString());
  }

  log("Constructing buy intent...");
  final String type = product.isSubscription() ? PRODUCT_TYPE_SUBSCRIPTION : PRODUCT_TYPE_ITEM;
  try {
    if (developerPayload == null) {
      this.developerPayload = UUID.randomUUID().toString();
    } else {
      this.developerPayload = developerPayload;
    }

    final Bundle buyBundle = api.getBuyIntent(product.sku(), type, developerPayload);
    final int response = getResponseCode(buyBundle);
    if (response != BILLING_RESPONSE_RESULT_OK) {
      log("Couldn't purchase product! code:" + response);
      listener.failure(product, purchaseError(response));
      return;
    }

    final PendingIntent pendingIntent = buyBundle.getParcelable(RESPONSE_BUY_INTENT);
    if (pendingIntent == null) {
      log("Received no pending intent!");
      listener.failure(product, purchaseError(response));
      return;
    }

    log("Launching buy intent for " + product.sku());
    this.purchaseListener = listener;
    pendingProduct = product;
    requestCode = new Random().nextInt(1024);
    activity.startIntentSenderForResult(pendingIntent.getIntentSender(),
        requestCode,
        new Intent(), 0, 0, 0);
  } catch (RemoteException | IntentSender.SendIntentException e) {
    log("Failed to launch purchase!\n" + Log.getStackTraceString(e));
    listener.failure(product, purchaseError(BILLING_RESPONSE_RESULT_ERROR));
  }
}
 
Example 10
Source File: BillingProcessor.java    From RxIAPv3 with Apache License 2.0 4 votes vote down vote up
private boolean purchase(Activity activity, String productId, String purchaseType) {
    if (!isInitialized() || TextUtils.isEmpty(productId) || TextUtils.isEmpty(purchaseType))
        return false;
    try {
        String purchasePayload = purchaseType + ":" + UUID.randomUUID().toString();
        savePurchasePayload(purchasePayload);
        Bundle bundle = billingService.getBuyIntent(Constants.GOOGLE_API_VERSION, contextPackageName, productId, purchaseType, purchasePayload);
        if (bundle != null) {
            int response = bundle.getInt(Constants.RESPONSE_CODE);
            if (response == Constants.BILLING_RESPONSE_RESULT_OK) {
                PendingIntent pendingIntent = bundle.getParcelable(Constants.BUY_INTENT);
                if (activity != null && pendingIntent != null)
                    activity.startIntentSenderForResult(pendingIntent.getIntentSender(), PURCHASE_FLOW_REQUEST_CODE, new Intent(), 0, 0, 0);
                else if (billingProcessorListener != null)
                    billingProcessorListener.onBillingError(Constants.BILLING_ERROR_LOST_CONTEXT, null);
            } else if (response == Constants.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                if (!isPurchased(productId) && !isSubscribed(productId))
                    loadOwnedPurchasesFromGoogle();
                PurchaseDataModel details = cachedProducts.getDetails(productId);
                if (!checkMerchant(details)) {
                    Log.i(LOG_TAG, "Invalid or tampered merchant id!");
                    if (billingProcessorListener != null)
                        billingProcessorListener.onBillingError(Constants.BILLING_ERROR_INVALID_MERCHANT_ID, null);
                    return false;
                }
                if (billingProcessorListener != null) {
                    if (details == null)
                        details = cachedSubscriptions.getDetails(productId);
                    billingProcessorListener.onProductPurchased(productId, details);
                }
            } else if (billingProcessorListener != null)
                billingProcessorListener.onBillingError(Constants.BILLING_ERROR_FAILED_TO_INITIALIZE_PURCHASE, null);
        }
        return true;
    } catch (Exception e) {
        Log.e(LOG_TAG, e.toString());
        if (billingProcessorListener != null)
            billingProcessorListener.onBillingError(Constants.BILLING_ERROR_OTHER_ERROR, e);
    }
    return false;
}
 
Example 11
Source File: IAP.java    From ExtensionsPack with MIT License 4 votes vote down vote up
public static void purchaseItem(String sku, int rc,
    HaxeObject callback)
{
  try
  {
    if(!setupDone || iapService == null)
    {
      callback.call("onWarning", new Object[] {"Service is not ready", "purchaseItem"});
      return;
    }

    if(buyCallback != null)
    {
      callback.call("onWarning", new Object[] {"Purchase item is not end", "purchaseItem"});
      return;
    }

    Log.d(tag, "getBuyIntent for " + sku);
    Bundle bundle = iapService.getBuyIntent(3, packageName, sku,
        ITEM_TYPE_INAPP, "");
    int response = getResponseCode(bundle);
    if(response != BILLING_RESPONSE_RESULT_OK)
    {
      callback.call("onError", new Object[] {response, "purchaseItem"});

      return;
    }

    buyCallback = callback;
    requestCode = rc;

    PendingIntent intent = bundle.getParcelable(RESPONSE_BUY_INTENT);
    Log.d(tag, "Start intent for " + sku + " with request code " + requestCode);

    Activity activity = GameActivity.getInstance();
    activity.startIntentSenderForResult(intent.getIntentSender(),
        requestCode, new Intent(),
        Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    Log.d(tag, "Intent for " + sku + " with request code " +
        requestCode + "started");
  }
  catch(Exception e)
  {
    callback.call("onException", new Object[] {e.toString(), "purchaseItem"});
    if(buyCallback != null)
    {
      buyCallback.call("finish", new Object[]{});
    }
    buyCallback = null;
  }
}