【问题标题】:How to use intent in android react native module如何在android react native模块中使用intent
【发布时间】:2018-03-07 08:33:00
【问题描述】:

我编写了从 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();
    }
}

【问题讨论】:

  • 你能把android studio的错误放出来吗。
  • 您应该在问题中分享您的代码,原因有两个。 1)如果有人想帮助您,他们不能因为您共享图像而仅仅复制粘贴您的代码。 2) 链接可能会断开,因此其他人将无法使用您获得的帮助。
  • 我们需要准确的错误文本,而不是图片。
  • 对不起,我在上面添加了我的代码,我认为因为 QRmodule 类不是从 AppCompatActivity 扩展的,有人可以帮忙吗?
  • 你找到解决方法了吗?

标签: java android react-native


【解决方案1】:

您可以简单地使用这个很棒的包:react-native-intent-launcher

【讨论】:

    【解决方案2】:

    一个简单的方法。

    在您的 QRModule 中,您需要调用包含来自 react native 的 Activity 引用的 reactContext。

    getCurrentActivity().startActivity(intent,CODE);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-13
      • 2015-09-28
      • 1970-01-01
      • 2021-10-02
      • 1970-01-01
      • 2020-06-03
      • 2015-12-18
      相关资源
      最近更新 更多