DEV Community

loading...

Simple Execute Shell Android In React Native

M Julius
Mobile Developer
・1 min read

Hello Bruh, execute the shell is in my opinion very important, to find out detailed information on android.

Getting Started

$ npx react-native init nameYourProject
Enter fullscreen mode Exit fullscreen mode
$ cd nameYourProject
Enter fullscreen mode Exit fullscreen mode
$ npm install react-native-android-shell --save
Enter fullscreen mode Exit fullscreen mode

Edit App.js file
replace code, using within code

Example

import React, { Component } from 'react';
import { View, Text } from 'react-native';
import AndroidShell from 'react-native-android-shell'

class demo extends Component {
    constructor(props) {
        super(props);
        this.state = {
            result: ''
        };
    }

    componentDidMount() {
        AndroidShell.executeCommand("ls", (result) => {
            this.setState({ result: 'yeu : ' + result });
            console.log('Result :', result);
        });
    }

    render() {
        return (
            <View style={{ alignItems: 'center', flex: 1 }}>
                <Text>{this.state.result}</Text>
            </View>
        );
    }
}

export default demo;
Enter fullscreen mode Exit fullscreen mode

Discussion (2)

Collapse
amanagr843 profile image
amanagr843

how to use commands like "pkg install "

Collapse
juldev profile image
M Julius Author

you need root, and install proot package for super user