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);
}
}
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);
}
}
});
}
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"));
}
}
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;
}
}
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();
}
Aggregations