2

I wrote codes to access android native from react native, to show the toast-like example on react native docs http://facebook.github.io/react-native/docs/native-modules-android.html It works well, but when I try to use intent, there's an error. Can someone help?

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();
    }
}
5
  • can u put error of android studio. Commented Mar 7, 2018 at 8:39
  • You should share your code in the question for two reasons. 1) If someone wants to help you, they can't just copy-paste your code because you shared an image. 2) The link might break so other people won't be able to use the help that you get. Commented Mar 7, 2018 at 8:49
  • 1
    We need the exact error text, not the picture please. Commented Mar 7, 2018 at 9:03
  • i'm sorry i was added my code above, i think that because QRmodule class is not extend from AppCompatActivity, can someone help? Commented Mar 9, 2018 at 10:07
  • Did you find any fix regarding this? Commented May 12, 2018 at 16:26

2 Answers 2

1

You can simply use this great package: react-native-intent-launcher

Sign up to request clarification or add additional context in comments.

Comments

0

a simple way.

In your QRModule you need to call the reactContext that contain the Activity reference from react native.

getCurrentActivity().startActivity(intent,CODE);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.