How to run Python code in Android App?
HTML-код
- Опубликовано: 11 сен 2024
- In this video it shows the steps to run a python code in Android App's code. It calls the python script from the Java code. It uses chaquo plugin, which is Python SDK for Android. Details are available at: chaquo.com/cha...
The steps for setting the Gradle is taken from this page: chaquo.com/cha...
I hope you like this video. For any questions, suggestions or appreciation please contact us at: programmerworl... or email at: programmerworld1990@gmail.com
Complete source code and other details/ steps of this video are posted in the below link:
programmerworl...
However, the main Java code is copied below also for reference:
package com.programmerworld.pythininandroidapp;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.chaquo.python.PyObject;
import com.chaquo.python.Python;
import com.chaquo.python.android.AndroidPlatform;
public class MainActivity extends AppCompatActivity {
private TextView textViewOutput;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) - {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
textViewOutput = findViewById(R.id.textViewOutput);
Python.start(new AndroidPlatform(getApplicationContext()));
return insets;
});
}
public void buttonPythonRun(View view){
Python python = Python.getInstance();
PyObject pyObjectResult = python.getModule("add_numbers")
.callAttr("add_numbers", 10, 25);
textViewOutput.setText(pyObjectResult.toString());
}
}
--
Thank you so muchhhh
can u also make a video on how to integrate RFID reader info into the app, also text to speech and voice to text
what if i want to install some libraries python
Can u share all Gradle Files. I have lots of errors in the program. May be it can help us sir. Ty
Details are shared at:
programmerworld.co/android/how-to-run-python-code-in-android-app/