samnursa
samnursa

Reputation: 51

How to use intent in android react native module

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

Upvotes: 2

Views: 14916

Answers (2)

Nahuel Albornoz
Nahuel Albornoz

Reputation: 31

a simple way.

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

getCurrentActivity().startActivity(intent,CODE);

Upvotes: 0

HessiPard
HessiPard

Reputation: 41

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

Upvotes: 1

Related Questions