Android QPython3 扩展:基础窗口
#需要android.py https://www.bilibili.com/read/cv8679914
#请先学习Android QPython3调用其他Android App http://www.bilibili.com/read/cv8781928
【QPythonSupport/app/src/main/AndroidManifest.xml】
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="czc.qpython.support" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:resizeableActivity="true">
<activity
android:name=".Main"
android:label="@string/app_name_cn" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
【QPythonSupport/app/src/main/java/czc/qpython/support/Main.java】
package czc.qpython.support;
import android.app.*;
import android.os.*;
import android.*;
import android.content.pm.*;
public class Main extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
// TODO: Implement this method
requestPermissions(this);
super.onCreate(savedInstanceState);
}
public static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE }; //Android6.0以后操作系统的动态权限申请
//用于Android6.0以后的操作系统,动态申请存储的读写权限
public static void requestPermissions(Activity context){
//用于Android6.0以后的操作系统,动态申请存储的读写权限
int permission = context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED){
context.requestPermissions(PERMISSIONS_STORAGE,1);
}
}
}
【QPythonSupport/app/build.gradle】
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "czc.qpython.support"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
【QPythonSupport/__init__.py】
#请先阅读说明文件
from android import *
【QPythonSupport/说明.txt】
需要android.py;
需要通过AIDE编译生成QPythonSupport.apk,然后安装Apk;
安装Apk后,进入应用,是一个空白界面,如果有存储授权申请,点“始终允许”即可,其他什么都不用做;
复制QPythonSupport到site-packages中,该Apk仅在QPython调用时生效。
调用方法:
from QPythonSupport import *
可用QPython函数:
#请听下回分解

说明:

是一个空白界面。
如果有存储授权申请,
点“始终允许”即可。
视频:https://www.bilibili.com/video/BV1wi4y1w7e7
作者:乘着船@Bilibili
更多文章+下载链接:https://www.bilibili.com/read/readlist/rl321663