简体   繁体   English

通过 Nodejs 构建一个 Android 应用程序

[英]Build an Android application via Nodejs

I want to build twilio SMS sender for Android. I have recently searched for it and found how to create via Android Studio, but it seems to be complicated for me.我想为 Android 构建 twilio 短信发送器。我最近搜索它并找到了如何通过 Android Studio 创建,但它对我来说似乎很复杂。 Then tried to search if I could use python for building Android application, but may be I was searching on wrong places, I can not find right answers.然后尝试搜索我是否可以使用 python 来构建 Android 应用程序,但可能是我在错误的地方搜索,我找不到正确的答案。 Than discovered that it's possible to build via Nodejs.比发现可以通过 Nodejs 构建。 I want it for me, not to upload anywhere only for my device.我想要它给我,而不是只为我的设备上传到任何地方。

I found AndroidJS.我找到了 AndroidJS。

mkdir twilio1
cd twilio1
mkdir assets
mkidr views

also I have created index.html in views directory and main.js in main app directory and then -->我还在 views 目录中创建了 index.html,在主应用程序目录中创建了 main.js,然后 -->

npm install androidjs
npm install twilio

This is what I got这就是我得到的

twilio1
|__views
|     |__index.html
|
|__assets
|
|__node_modules
|
|__main.js
|__package.json

I have pasted simple form from Bootstrap into index.html我已将 Bootstrap 中的简单表格粘贴到 index.html

<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>SendME</title>

    <script type="text/javascript" src="../assets/androidjs.js"></script>
    <!-- <script type="text/javascript" src="../node_modules/androidjs/lib/androidjs.js"></script> -->

    <!-- Bootstrap core CSS -->
    <link href="../assets/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../assets/signin.css" rel="stylesheet">
</head>

<body class="text-center">

    <div id="app" class="app">

        <form class="form-signin">
            <img class="mb-4" src="https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72">

            <label for="inputTel" class="sr-only">Send To</label>
            <input type="tel" id="inputNumber" v-model="inputNumber" name="inputNumber" class="form-control" placeholder="Send To" maxlength="13" size="13" required autofocus>
            <label for="inputName" class="sr-only">Sending From</label>
            <input type="text" id="inputName" v-model="inputName" name="inputName" class="form-control" placeholder="Sending From" maxlength="11" size="11" required autofocus>
            <label for="inputText" class="sr-only">SMS Body</label>
            <input type="text" id="inputText" v-model="inputText" name="inputText" class="form-control" placeholder="SMS Body" maxlength="120" size="120" required autofocus>
            <div class="checkbox mb-3">
            </div>
            <button class="btn btn-lg btn-primary btn-block" onclick="sendMsg()" type="submit">Send</button>
        </form>
    </div>

    <script src="main.js"></script>


</body>

</html>

I have wrote this code in main.js我在 main.js 中写了这段代码

        const accountSid = 'XX';
        const authToken = 'XX';
        const client = require('twilio')(accountSid, authToken);

        text = this.inputText
        mobile = this.inputNumber
        names = this.inputName


        function sendMsg() {
            client.messages
                .create({
                    body: text,
                    from: names,
                    to: mobile,
                })
        }

after that I pasted this into package.json之后我将其粘贴到 package.json

{
  "name": "twilio1",
  "app-name": "twilio1",
  "package-name" : "twilio1",
  "icon": "./assets/icon/icon.png",
  "permission": ["android.permission.INTERNET"],
  "version": "1.0.0",
  "dist-path": "./dist",
  "description": "",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "androidjs": "^1.0.5"
  }
}

Then I have copied androidjs.js from GitHub repository and pasted in assets and then put its src location in index.html.然后我从 GitHub 存储库复制了 androidjs.js 并粘贴到资产中,然后将其 src 位置放在 index.html 中。 I thought it was ready and then I typed我以为它已经准备好了,然后我输入

androidjs b -f

and it is not working.它不工作。 There is just an error message -->只有一条错误消息 -->

Invalid project type: undefined

Finally I want to know if it is even possible to build an application like this.最后我想知道是否有可能构建这样的应用程序。 Or if someone have created it already and can share it to me, please, share.或者,如果有人已经创建了它并且可以分享给我,请分享。 And if it is possible help me to do it on right way.如果可能的话,请帮助我以正确的方式做到这一点。 I have already created an app in python for windows, so I wanted to created it for android too, so.我已经在 python 为 windows 创建了一个应用程序,所以我也想为 android 创建它,所以。 Thank you.谢谢你。

@Roman Smith you can give webview as type in your package.json . @Roman Smith 你可以在webview中输入package.json go and checkout the docs https://android-js.github.io/docs go 并查看文档https://android-js.github.io/docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM