How to generate APK for python base Android app

Viewed 238

I am a beginner working on android app and i managed to interface the emulator with this python code but when i generate the apk file the python side doesn't work.

here is my code:

import os.path
import numpy as np
import cv2
import json
from flask import Flask,request,Response
import uuid


def faceDetect(img):
    face_cascade = cv2.CascadeClassifier('face.xml')
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray,1.3,5)
    #print(faces)
    for (x,y,w,h) in faces:
        img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0))
    # save the file
    path_file =('static/%s.jpg' %uuid.uuid4().hex)
    cv2.imwrite(path_file,img)
    return json.dumps(path_file)


# API

app = Flask(__name__)

@app.route('/api/upload',methods=['POST'])


def upload():
    img = cv2.imdecode(np.fromstring(request.files['image'].read(),np.uint8),cv2.IMREAD_UNCHANGED)
    # process image
    img_processed =faceDetect(img)
    # response
    return Response(response=img_processed,status=200,mimetype="application/json")


app.run(host="0.0.0.0",port=5000)


1 Answers

I would suggest you use Flutter, or write a native android app, if you want to develop a mobile app. Currently, It's really hard to develop a mobile application using the Python programming language.
Also, your code is just a REST API written in python on the Flask framework.

Finally, you can write a native app using Java/Kotlin, or develop on the Flutter framework. I think, you should read more information about that.

Related