Search in sources :

Example 11 with SendIntentException

use of android.content.IntentSender.SendIntentException in project CodenameOne by codenameone.

the class IabHelper method launchPurchaseFlow.

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
 * which will involve bringing up the Google Play screen. The calling activity will be paused while
 * the user interacts with Google Play, and the result will be delivered via the activity's
 * {@link android.app.Activity#onActivityResult} method, at which point you must call
 * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param act The calling activity.
 * @param sku The sku of the item to purchase.
 * @param itemType indicates if it's a product or a subscription (ITEM_TYPE_INAPP or ITEM_TYPE_SUBS)
 * @param requestCode A request code (to differentiate from other responses --
 *     as in {@link android.app.Activity#startActivityForResult}).
 * @param listener The listener to notify when the purchase process finishes
 * @param extraData Extra data (developer payload), which will be returned with the purchase data
 *     when the purchase completes. This extra data will be permanently bound to that purchase
 *     and will always be returned when the purchase is queried.
 */
public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode, OnIabPurchaseFinishedListener listener, String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;
    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE, "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null)
            listener.onIabPurchaseFinished(r, sku, null);
        return;
    }
    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(result, sku, null);
            return;
        }
        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        mPurchasingItemType = itemType;
        act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();
        result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null)
            listener.onIabPurchaseFinished(result, sku, null);
    } catch (RemoteException e) {
        logError("RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();
        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onIabPurchaseFinished(result, sku, null);
    }
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException) SendIntentException(android.content.IntentSender.SendIntentException)

Example 12 with SendIntentException

use of android.content.IntentSender.SendIntentException in project CodenameOne by codenameone.

the class GoogleImpl method onConnectionFailed.

public void onConnectionFailed(final ConnectionResult cr) {
    if (AndroidNativeUtil.getActivity() == null) {
        return;
    }
    final CodenameOneActivity main = (CodenameOneActivity) AndroidNativeUtil.getActivity();
    if (!mIntentInProgress && cr.hasResolution()) {
        try {
            mIntentInProgress = true;
            main.startIntentSenderForResult(cr.getResolution().getIntentSender(), 0, null, 0, 0, 0);
            main.setIntentResultListener(new com.codename1.impl.android.IntentResultListener() {

                public void onActivityResult(int requestCode, int resultCode, android.content.Intent data) {
                    mIntentInProgress = false;
                    if (!mGoogleApiClient.isConnecting()) {
                        mGoogleApiClient.connect();
                    }
                    main.restoreIntentResultListener();
                }
            });
        } catch (SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            mIntentInProgress = false;
            mGoogleApiClient.connect();
        }
        return;
    }
    if (callback != null) {
        Display.getInstance().callSerially(new Runnable() {

            @Override
            public void run() {
                callback.loginFailed(GooglePlayServicesUtil.getErrorString(cr.getErrorCode()));
            }
        });
    }
}
Also used : IntentResultListener(com.codename1.impl.android.IntentResultListener) CodenameOneActivity(com.codename1.impl.android.CodenameOneActivity) Intent(android.content.Intent) SendIntentException(android.content.IntentSender.SendIntentException)

Example 13 with SendIntentException

use of android.content.IntentSender.SendIntentException in project cardslib by gabrielemariotti.

the class IabHelper method launchPurchaseFlow.

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
 * which will involve bringing up the Google Play screen. The calling activity will be paused while
 * the user interacts with Google Play, and the result will be delivered via the activity's
 * {@link android.app.Activity#onActivityResult} method, at which point you must call
 * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param act The calling activity.
 * @param sku The sku of the item to purchase.
 * @param itemType indicates if it's a product or a subscription (ITEM_TYPE_INAPP or ITEM_TYPE_SUBS)
 * @param requestCode A request code (to differentiate from other responses --
 *     as in {@link android.app.Activity#startActivityForResult}).
 * @param listener The listener to notify when the purchase process finishes
 * @param extraData Extra data (developer payload), which will be returned with the purchase data
 *     when the purchase completes. This extra data will be permanently bound to that purchase
 *     and will always be returned when the purchase is queried.
 */
public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode, OnIabPurchaseFinishedListener listener, String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;
    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE, "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null)
            listener.onIabPurchaseFinished(r, null);
        return;
    }
    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(result, null);
            return;
        }
        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        mPurchasingItemType = itemType;
        act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();
        result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    } catch (RemoteException e) {
        logError("RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();
        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    } catch (NullPointerException ne) {
        result = new IabResult(IABHELPER_UNKNOWN_ERROR, "NullPointer while refreshing inventory.");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    }
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException) SendIntentException(android.content.IntentSender.SendIntentException)

Example 14 with SendIntentException

use of android.content.IntentSender.SendIntentException in project platform_frameworks_base by android.

the class ChooserActivity method onTargetSelected.

@Override
protected boolean onTargetSelected(TargetInfo target, boolean alwaysCheck) {
    if (mRefinementIntentSender != null) {
        final Intent fillIn = new Intent();
        final List<Intent> sourceIntents = target.getAllSourceIntents();
        if (!sourceIntents.isEmpty()) {
            fillIn.putExtra(Intent.EXTRA_INTENT, sourceIntents.get(0));
            if (sourceIntents.size() > 1) {
                final Intent[] alts = new Intent[sourceIntents.size() - 1];
                for (int i = 1, N = sourceIntents.size(); i < N; i++) {
                    alts[i - 1] = sourceIntents.get(i);
                }
                fillIn.putExtra(Intent.EXTRA_ALTERNATE_INTENTS, alts);
            }
            if (mRefinementResultReceiver != null) {
                mRefinementResultReceiver.destroy();
            }
            mRefinementResultReceiver = new RefinementResultReceiver(this, target, null);
            fillIn.putExtra(Intent.EXTRA_RESULT_RECEIVER, mRefinementResultReceiver);
            try {
                mRefinementIntentSender.sendIntent(this, 0, fillIn, null, null);
                return false;
            } catch (SendIntentException e) {
                Log.e(TAG, "Refinement IntentSender failed to send", e);
            }
        }
    }
    return super.onTargetSelected(target, alwaysCheck);
}
Also used : LabeledIntent(android.content.pm.LabeledIntent) Intent(android.content.Intent) SendIntentException(android.content.IntentSender.SendIntentException)

Example 15 with SendIntentException

use of android.content.IntentSender.SendIntentException in project SeriesGuide by UweTrottmann.

the class IabHelper method launchPurchaseFlow.

/**
     * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
     * which will involve bringing up the Google Play screen. The calling activity will be paused
     * while the user interacts with Google Play, and the result will be delivered via the
     * activity's {@link android.app.Activity#onActivityResult} method, at which point you must call
     * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
     * MUST be called from the UI thread of the Activity.
     *
     * @param activity The calling activity.
     * @param sku The sku of the item to purchase.
     * @param itemType indicates if it's a product or a subscription (ITEM_TYPE_INAPP or
     * ITEM_TYPE_SUBS)
     * @param requestCode A request code (to differentiate from other responses -- as in {@link
     * android.app.Activity#startActivityForResult}).
     * @param listener The listener to notify when the purchase process finishes
     * @param extraData Extra data (developer payload), which will be returned with the purchase
     * data when the purchase completes. This extra data will be permanently bound to that purchase
     * and will always be returned when the purchase is queried.
     */
public void launchPurchaseFlow(@NonNull Activity activity, @NonNull String sku, @NonNull String itemType, int requestCode, OnIabPurchaseFinishedListener listener, @NonNull String extraData) {
    if (context == null || billingService == null) {
        warnNotSetup();
        if (listener != null) {
            listener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_SERVICE_UNAVAILABLE, "Billing service not set up."), null);
        }
        return;
    }
    flagStartAsync("launchPurchaseFlow");
    IabResult result;
    if (itemType.equals(ITEM_TYPE_SUBS) && !subscriptionsSupported) {
        IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE, "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null) {
            listener.onIabPurchaseFinished(r, null);
        }
        return;
    }
    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle = billingService.getBuyIntent(3, context.getPackageName(), sku, itemType, extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null) {
                listener.onIabPurchaseFinished(result, null);
            }
            return;
        }
        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        if (pendingIntent == null) {
            logError("Unable to buy item, buy intent is null.");
            flagEndAsync();
            if (listener != null) {
                listener.onIabPurchaseFinished(new IabResult(IABHELPER_SEND_INTENT_FAILED, "Buy intent is null."), null);
            }
            return;
        }
        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        this.requestCode = requestCode;
        purchaseListener = listener;
        purchasingItemType = itemType;
        activity.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(), 0, 0, 0);
    } catch (SendIntentException e) {
        logError(e, "launchPurchaseFlow: failed for sku " + sku);
        flagEndAsync();
        result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null) {
            listener.onIabPurchaseFinished(result, null);
        }
    } catch (RemoteException e) {
        logError(e, "launchPurchaseFlow: failed for sku " + sku);
        flagEndAsync();
        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null) {
            listener.onIabPurchaseFinished(result, null);
        }
    }
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException) SendIntentException(android.content.IntentSender.SendIntentException)

Aggregations

SendIntentException (android.content.IntentSender.SendIntentException)38 Intent (android.content.Intent)26 Bundle (android.os.Bundle)26 RemoteException (android.os.RemoteException)25 PendingIntent (android.app.PendingIntent)21 ColorDrawable (android.graphics.drawable.ColorDrawable)6 PrinterInfo (android.print.PrinterInfo)6 View (android.view.View)6 AdapterView (android.widget.AdapterView)6 ImageView (android.widget.ImageView)6 ListView (android.widget.ListView)6 SearchView (android.widget.SearchView)6 TextView (android.widget.TextView)6 SettingsActivity (com.android.settings.SettingsActivity)6 ToggleSwitch (com.android.settings.widget.ToggleSwitch)6 NonNull (android.annotation.NonNull)5 Activity (android.app.Activity)5 IntentSender (android.content.IntentSender)5 LabeledIntent (android.content.pm.LabeledIntent)5 CodenameOneActivity (com.codename1.impl.android.CodenameOneActivity)1