Search in sources :

Example 56 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-iap by dooboolab.

the class RNIapModule method prepare.

@ReactMethod
public void prepare(Promise promise) {
    Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    // This is the key line that fixed everything for me
    intent.setPackage("com.android.vending");
    try {
        addPromiseForKey(PROMISE_PREPARE, promise);
        reactContext.bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);
        mBillingClient = BillingClient.newBuilder(reactContext).setListener(purchasesUpdatedListener).build();
        mBillingClient.startConnection(billingClientStateListener);
    } catch (Exception e) {
        rejectPromisesForKey(PROMISE_PREPARE, E_NOT_PREPARED, e.getMessage(), e);
    }
}
Also used : Intent(android.content.Intent) RemoteException(android.os.RemoteException) JSONException(org.json.JSONException) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 57 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-iap by dooboolab.

the class RNIapModule method getItemsByType.

@ReactMethod
public void getItemsByType(String type, ReadableArray skus, final Promise promise) {
    if (mService == null) {
        promise.reject(E_NOT_PREPARED, "IAP not prepared. Check if Google Play service is available.");
        return;
    }
    ArrayList<String> skusList = new ArrayList<>();
    for (int i = 0; i < skus.size(); i++) {
        skusList.add(skus.getString(i));
    }
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skusList).setType(type);
    mBillingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {

        @Override
        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
            Log.d(TAG, "responseCode: " + responseCode);
            if (responseCode == BillingClient.BillingResponse.OK) {
                WritableArray items = Arguments.createArray();
                for (SkuDetails skuDetails : skuDetailsList) {
                    WritableMap item = Arguments.createMap();
                    item.putString("productId", skuDetails.getSku());
                    item.putString("price", String.valueOf(skuDetails.getPriceAmountMicros() / 1000000));
                    item.putString("currency", skuDetails.getPriceCurrencyCode());
                    item.putString("type", skuDetails.getType());
                    item.putString("localizedPrice", skuDetails.getPrice());
                    item.putString("title", skuDetails.getTitle());
                    item.putString("description", skuDetails.getDescription());
                    items.pushMap(item);
                }
                promise.resolve(items);
            } else {
                rejectPromiseWithBillingError(promise, responseCode);
            }
        }
    });
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) ArrayList(java.util.ArrayList) SkuDetailsParams(com.android.billingclient.api.SkuDetailsParams) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 58 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method openPlacePickerModal.

@ReactMethod
public void openPlacePickerModal(ReadableMap options, final Promise promise) {
    this.pendingPromise = promise;
    Activity currentActivity = getCurrentActivity();
    double latitude = options.getDouble("latitude");
    double longitude = options.getDouble("longitude");
    double radius = options.getDouble("radius");
    LatLng center = new LatLng(latitude, longitude);
    try {
        PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
        if (latitude != 0 && longitude != 0 && radius != 0) {
            intentBuilder.setLatLngBounds(this.getLatLngBounds(center, radius));
        }
        Intent intent = intentBuilder.build(currentActivity);
        // Start the Intent by requesting a result, identified by a request code.
        currentActivity.startActivityForResult(intent, PLACE_PICKER_REQUEST_CODE);
    } catch (GooglePlayServicesRepairableException e) {
        GoogleApiAvailability.getInstance().getErrorDialog(currentActivity, e.getConnectionStatusCode(), PLACE_PICKER_REQUEST_CODE).show();
    } catch (GooglePlayServicesNotAvailableException e) {
        rejectPromise("E_INTENT_ERROR", new Error("Google Play Services is not available"));
    }
}
Also used : PlacePicker(com.google.android.gms.location.places.ui.PlacePicker) Activity(android.app.Activity) Intent(android.content.Intent) LatLng(com.google.android.gms.maps.model.LatLng) GooglePlayServicesRepairableException(com.google.android.gms.common.GooglePlayServicesRepairableException) GooglePlayServicesNotAvailableException(com.google.android.gms.common.GooglePlayServicesNotAvailableException) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 59 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method getAutocompletePredictions.

@ReactMethod
public void getAutocompletePredictions(String query, ReadableMap options, final Promise promise) {
    String type = options.getString("type");
    String country = options.getString("country");
    country = country.isEmpty() ? null : country;
    double latitude = options.getDouble("latitude");
    double longitude = options.getDouble("longitude");
    double radius = options.getDouble("radius");
    LatLng center = new LatLng(latitude, longitude);
    LatLngBounds bounds = null;
    if (latitude != 0 && longitude != 0 && radius != 0) {
        bounds = this.getLatLngBounds(center, radius);
    }
    PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query, bounds, getFilterType(type, country));
    AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS);
    final Status status = autocompletePredictions.getStatus();
    if (status.isSuccess()) {
        if (autocompletePredictions.getCount() == 0) {
            WritableArray emptyResult = Arguments.createArray();
            autocompletePredictions.release();
            promise.resolve(emptyResult);
            return;
        }
        WritableArray predictionsList = Arguments.createArray();
        for (AutocompletePrediction prediction : autocompletePredictions) {
            WritableMap map = Arguments.createMap();
            map.putString("fullText", prediction.getFullText(null).toString());
            map.putString("primaryText", prediction.getPrimaryText(null).toString());
            map.putString("secondaryText", prediction.getSecondaryText(null).toString());
            map.putString("placeID", prediction.getPlaceId().toString());
            if (prediction.getPlaceTypes() != null) {
                List<String> types = new ArrayList<>();
                for (Integer placeType : prediction.getPlaceTypes()) {
                    types.add(findPlaceTypeLabelByPlaceTypeId(placeType));
                }
                map.putArray("types", Arguments.fromArray(types.toArray(new String[0])));
            }
            predictionsList.pushMap(map);
        }
        // Release the buffer now that all data has been copied.
        autocompletePredictions.release();
        promise.resolve(predictionsList);
    } else {
        Log.i(TAG, "Error making autocomplete prediction API call: " + status.toString());
        autocompletePredictions.release();
        promise.reject("E_AUTOCOMPLETE_ERROR", new Error("Error making autocomplete prediction API call: " + status.toString()));
        return;
    }
}
Also used : Status(com.google.android.gms.common.api.Status) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) AutocompletePredictionBuffer(com.google.android.gms.location.places.AutocompletePredictionBuffer) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) ArrayList(java.util.ArrayList) AutocompletePrediction(com.google.android.gms.location.places.AutocompletePrediction) LatLng(com.google.android.gms.maps.model.LatLng) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 60 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-fbads by callstack.

the class InterstitialAdManager method showAd.

@ReactMethod
public void showAd(String placementId, Promise p) {
    if (mPromise != null) {
        p.reject("E_FAILED_TO_SHOW", "Only one `showAd` can be called at once");
        return;
    }
    ReactApplicationContext reactContext = this.getReactApplicationContext();
    mPromise = p;
    mInterstitial = new InterstitialAd(reactContext, placementId);
    mInterstitial.setAdListener(this);
    mInterstitial.loadAd();
}
Also used : InterstitialAd(com.facebook.ads.InterstitialAd) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

ReactMethod (com.facebook.react.bridge.ReactMethod)87 Activity (android.app.Activity)21 WritableMap (com.facebook.react.bridge.WritableMap)17 Intent (android.content.Intent)10 Bundle (android.os.Bundle)10 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)6 WritableArray (com.facebook.react.bridge.WritableArray)5 ArrayList (java.util.ArrayList)5 Camera (android.hardware.Camera)4 InterstitialAd (com.facebook.ads.InterstitialAd)4 ShareContent (com.facebook.share.model.ShareContent)4 LayoutNode (com.reactnativenavigation.options.LayoutNode)4 LoginManager (com.facebook.login.LoginManager)3 ReactActivity (com.facebook.react.ReactActivity)3 LatLng (com.google.android.gms.maps.model.LatLng)3 NotificationManager (android.app.NotificationManager)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 RemoteException (android.os.RemoteException)2 NativeAdsManager (com.facebook.ads.NativeAdsManager)2 JSApplicationIllegalArgumentException (com.facebook.react.bridge.JSApplicationIllegalArgumentException)2