本文整理匯總了Java中com.facebook.react.bridge.Promise.reject方法的典型用法代碼示例。如果您正苦於以下問題:Java Promise.reject方法的具體用法?Java Promise.reject怎麽用?Java Promise.reject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.facebook.react.bridge.Promise
的用法示例。
在下文中一共展示了Promise.reject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: share
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
/**
* Open a chooser dialog to send text content to other apps.
*
* Refer http://developer.android.com/intl/ko/training/sharing/send.html
*
* @param content the data to send
* @param dialogTitle the title of the chooser dialog
*/
@ReactMethod
public void share(ReadableMap content, String dialogTitle, Promise promise) {
if (content == null) {
promise.reject(ERROR_INVALID_CONTENT, "Content cannot be null");
return;
}
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setTypeAndNormalize("text/plain");
if (content.hasKey("title")) {
intent.putExtra(Intent.EXTRA_SUBJECT, content.getString("title"));
}
if (content.hasKey("message")) {
intent.putExtra(Intent.EXTRA_TEXT, content.getString("message"));
}
Intent chooser = Intent.createChooser(intent, dialogTitle);
chooser.addCategory(Intent.CATEGORY_DEFAULT);
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
currentActivity.startActivity(chooser);
} else {
getReactApplicationContext().startActivity(chooser);
}
WritableMap result = Arguments.createMap();
result.putString("action", ACTION_SHARED);
promise.resolve(result);
} catch (Exception e) {
promise.reject(ERROR_UNABLE_TO_OPEN_DIALOG, "Failed to open share dialog");
}
}
示例2: getAvailableLocales
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
@ReactMethod
public void getAvailableLocales(Promise promise) {
if(notReady(promise)) return;
try {
WritableArray localeList = Arguments.createArray();
Locale[] localesArray = Locale.getAvailableLocales();
for(Locale locale: localesArray) {
int isAvailable = tts.isLanguageAvailable(locale);
if(isAvailable == TextToSpeech.LANG_COUNTRY_AVAILABLE) {
WritableMap newLocale = returnMapForLocale(locale);
localeList.pushMap(newLocale);
}
}
promise.resolve(localeList);
} catch(Exception e) {
promise.reject("error", "Unable to retrieve locales for getAvailableLocales()", e);
}
}
開發者ID:echo8795,項目名稱:react-native-android-text-to-speech,代碼行數:21,代碼來源:RNAndroidTextToSpeechModule.java
示例3: disconnect
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
/**
* Disconnect printer
*
* @param promise
*/
@ReactMethod
public void disconnect(Promise promise){
try {
mmSocket.close();
if (mPrinter != null) {
mPrinter.release();
}
if (mProtocolAdapter != null) {
mProtocolAdapter.release();
}
if(promise != null) promise.resolve("DISCONNECTED");
} catch (Exception e) {
if(promise != null) promise.reject("Erro: " + e.getMessage());
}
}
示例4: createAndSendTransaction
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
/**
* Create and send transaction.
*
* @param passphrase Passphrase
* @param nonce Account nonce (use -1 to use last known nonce)
* @param toAddress Address destination
* @param amount Amount
* @param gasLimit Gas limit
* @param gasPrice Gas price
* @param data
* @param promise Promise
* @return Return String transaction
*/
@ReactMethod
public void createAndSendTransaction(String passphrase, double nonce, String toAddress,
double amount, double gasLimit, double gasPrice,
String data, Promise promise) {
try {
Account acc = GethHolder.getAccount();
Address fromAddress = acc.getAddress();
BigInt chain = new BigInt(GethHolder.getNodeConfig().getEthereumNetworkID());
Context ctx = new Context();
if (nonce == -1) {
nonce = GethHolder.getNode().getEthereumClient().getPendingNonceAt(ctx, fromAddress);
}
Transaction tx = new Transaction(
(long) nonce,
new Address(toAddress),
new BigInt((long) amount),
new BigInt((long) gasLimit),
new BigInt((long) gasPrice),
data.getBytes("UTF8"));
// Sign a transaction with a single authorization
Transaction signed = GethHolder.getKeyStore().signTxPassphrase(acc, passphrase, tx, chain);
// Send it out to the network.
GethHolder.getNode().getEthereumClient().sendTransaction(ctx, signed);
promise.resolve(tx.toString());
} catch (Exception e) {
promise.reject(NEW_TRANSACTION_ERROR, e);
}
}
示例5: toGraphDef
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
@ReactMethod
public void toGraphDef(String id, Promise promise) {
try {
Graph graph = graphs.get(id);
promise.resolve(Base64.encodeToString(graph.toGraphDef(), Base64.DEFAULT));
} catch (Exception e) {
promise.reject(e);
}
}
示例6: close
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
@ReactMethod
public void close(String id, Promise promise) {
try {
Graph graph = graphs.get(id);
graph.close();
promise.resolve(true);
} catch (Exception e) {
promise.reject(e);
}
}
示例7: speak
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
@ReactMethod
public void speak(String utterance, String queueMode, Promise promise) {
if(notReady(promise)) return;
if(IS_DUCKING) {
int amResult = audioManager.requestAudioFocus(afChangeListener,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
if(amResult != AudioManager.AUDIOFOCUS_REQUEST_GRANTED)
promise.reject("error", "Android AudioManager error, failed to request audio focus");
}
String utteranceId = Integer.toString(utterance.hashCode());
int mode = TextToSpeech.QUEUE_ADD;
if(queueMode.equals("ADD"))
mode = TextToSpeech.QUEUE_ADD;
else if(queueMode.equals("FLUSH"))
mode = TextToSpeech.QUEUE_FLUSH;
int speakResult = speak(utterance, mode, utteranceId);
if(speakResult == TextToSpeech.SUCCESS) {
promise.resolve(utteranceId);
} else {
promise.reject("error", "Unable to play. Error at speak(utterance, queueMode)");
}
}
開發者ID:echo8795,項目名稱:react-native-android-text-to-speech,代碼行數:29,代碼來源:RNAndroidTextToSpeechModule.java
示例8: writeToFile
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
@ReactMethod
public void writeToFile(String relativePath, String content, boolean isAppend, String storage, Promise promise) {
try {
writeToFile(relativePath, content, isAppend, Storage.valueOf(storage));
promise.resolve(true);
} catch (IOException e) {
promise.reject("ERROR", e.getMessage());
}
}
示例9: getPrinterSerialNo
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
/**
* 獲取打印機板序列號
*/
@ReactMethod
public void getPrinterSerialNo(final Promise p) {
try {
p.resolve(getPrinterSerialNo());
} catch (Exception e) {
Log.i(TAG, "ERROR: " + e.getMessage());
p.reject("" + 0, e.getMessage());
}
}
示例10: consume
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
@ReactMethod
public void consume(String sku,final Promise promise){
if(userInvo!=null){
if(userInvo.hasPurchase(sku)){
mHelper.consumeAsync(userInvo.getPurchase(sku),
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
WritableMap params = Arguments.createMap();
if (result.isSuccess()) {
// provision the in-app purchase to the user
promise.resolve(gson.toJson(purchase));
}
else {
// handle error
promise.reject(E_CONSUME_FAILURE,result.getMessage());
}
}
});
}
else{
promise.reject(E_CONSUME_ERROR,"user did not purchase item");
}
}
else{
promise.reject(E_CONSUME_INITIAL,"inventory not loaded!");
}
}
示例11: record
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
private void record(final ReadableMap options, final Promise promise) {
if (mRecordingPromise != null) {
return;
}
mCamera = RCTCamera.getInstance().acquireCameraInstance(options.getInt("type"));
if (mCamera == null) {
promise.reject(new RuntimeException("No camera found."));
return;
}
Throwable prepareError = prepareMediaRecorder(options);
if (prepareError != null) {
promise.reject(prepareError);
return;
}
try {
mMediaRecorder.start();
MRStartTime = System.currentTimeMillis();
mRecordingOptions = options;
mRecordingPromise = promise; // only got here if mediaRecorder started
} catch (Exception ex) {
Log.e(TAG, "Media recorder start error.", ex);
promise.reject(ex);
}
}
示例12: shouldShowRequestPermissionRationale
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
/**
* Check whether the app should display a message explaining why a certain permission is needed.
* successCallback is called with true if the app should display a message, false otherwise.
* This message is only displayed if the user has revoked this permission once before, and if the
* permission dialog will be shown to the user (the user can choose to not be shown that dialog
* again). For devices before Android M, this always returns false.
* See {@link Activity#shouldShowRequestPermissionRationale}.
*/
@ReactMethod
public void shouldShowRequestPermissionRationale(final String permission, final Promise promise) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
promise.resolve(false);
return;
}
try {
promise.resolve(getPermissionAwareActivity().shouldShowRequestPermissionRationale(permission));
} catch (IllegalStateException e) {
promise.reject(ERROR_INVALID_ACTIVITY, e);
}
}
示例13: getCurrentConnectivity
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
@ReactMethod
public void getCurrentConnectivity(Promise promise) {
if (mNoNetworkPermission) {
promise.reject(ERROR_MISSING_PERMISSION, MISSING_PERMISSION_MESSAGE, null);
return;
}
promise.resolve(createConnectivityEventMap());
}
示例14: get
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
@ReactMethod
public void get(String alias, Promise promise) {
try {
promise.resolve(getPlainText(alias));
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
promise.reject("404", "{\"code\":404,\"api-level\":" + Build.VERSION.SDK_INT + ",\"message\":" + fnfe.getMessage() + "}", fnfe);
} catch (Exception e) {
e.printStackTrace();
Log.e(Constants.TAG, "Exception: " + e.getMessage());
promise.reject("{\"code\":1,\"api-level\":" + Build.VERSION.SDK_INT + ",\"message\":" + e.getMessage() + "}");
}
}
示例15: getBadgeNumber
import com.facebook.react.bridge.Promise; //導入方法依賴的package包/類
@ReactMethod
public void getBadgeNumber(Promise promise) {
try {
promise.resolve(getBadge());
} catch (Exception e) {
e.printStackTrace();
promise.reject("can not get badge number due to an exception occurs", e);
}
}