[英]How to use intent in android react native module
我編寫了代碼來從 react native 訪問 android native,以在 react native docs http://facebook.github.io/react-native/docs/native-modules-android.html上顯示類似 toast 的示例 它運行良好,但是當我嘗試使用意圖時,出現錯誤。 有人可以幫忙嗎?
package com.myApp;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
public class QRModule extends ReactContextBaseJavaModule{
public QRModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "QRCode";
}
@ReactMethod
public void show(String message) {
Intent intent = new Intent(this,DimoActivity.class);
startActivity(intent);
//Toast.makeText(getReactApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
}
你可以簡單地使用這個很棒的包: react-native-intent-launcher
一個簡單的方法。
在您的 QRModule 中,您需要調用包含來自 react native 的 Activity 引用的 reactContext。
getCurrentActivity().startActivity(intent,CODE);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.