LaborerYao丶
LaborerYao丶
  • 发布:2021-06-09 15:40
  • 更新:2023-05-17 11:15
  • 阅读:3881

Android开机自启应用-离线打包将应用变为Launcher程序

分类:HBuilderX
最近做一个项目,开始以为app只是一个开机自启动的程序.后来发现其实是需要app完全覆盖设备,即开机就显示自己的app且设备运行期间只能展示自己的app.  
在网上找了一圈想用uniapp暂时是不能实现了,于是就想到了用原生Android中  
<category android:name="android.intent.category.HOME" />  
<category android:name="android.intent.category.DEFAULT" />  

将应用变成launcher程序,结合uniapp通过离线打包实现  

**uniapp端**  
  1. 创建uniapp项目

2.HbuilderX制作自定义基座

Android签名证书生成指南:https://ask.dcloud.net.cn/article/35777

3.获取app-sha1和包名

安装Android包名sha1获取apk:链接: https://pan.baidu.com/s/1kFcJoQQTbJanp1TzoAfRrw 提取码: whyh 复制这段内容后打开百度网盘手机App,操作更方便哦

  1. dcloud开发者中心-配置离线打包key管理


Android端

  1. 创建Android项目


2.导入sdk里面的包
app离线打包sdk下载地址https://nativesupport.dcloud.net.cn/AppDocs/download/android

  1. 创建对应文件夹到对应位置

  1. 将sdk中的assets下的data下的文件放到对应目录下

  1. 修改AndroidManifest.xml

代码:
<activity
android:name="io.dcloud.PandoraEntry"
android:configChanges="orientation|keyboardHidden|keyboard|navigation"
android:label="@string/app_name"
android:launchMode="singleTask"
android:hardwareAccelerated="true"
android:theme="@style/TranslucentTheme"
android:screenOrientation="user"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="io.dcloud.PandoraEntryActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale|keyboard"
android:hardwareAccelerated="true"
android:permission="com.miui.securitycenter.permission.AppPermissionsEditor"
android:screenOrientation="user"
android:theme="@style/DCloudTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="h56131bcf" />
</intent-filter>
</activity>

    <provider  
        android:authorities="com.kuaikefu.androidlauncher.dc.fileprovider"  
        android:name="io.dcloud.common.util.DCloud_FileProvider"  
        android:exported="false"  
        android:grantUriPermissions="true">  
        <meta-data  
            android:name="android.support.FILE_PROVIDER_PATHS"  
            android:resource="@xml/dcloud_file_provider"/>  
    </provider>  

    <meta-data  
        android:name="dcloud_appkey"  
        android:value="你的开发者中心生成的app key" />  

6.添加对应代码

代码:
plugins {
id 'com.android.application'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

signingConfigs {  
    config {  
        keyAlias '别名'  
        keyPassword 'keypass'  
        storeFile file('路径')  
        storePassword 'pass'  
        v1SigningEnabled true //兼容v1  
        v2SigningEnabled true //兼容v2  
    }  
}  

defaultConfig {  
    applicationId "uni.UNI20C4F61"  
    minSdkVersion 21  
    targetSdkVersion 30  
    versionCode 1  
    versionName "1.0"  

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"  

    multiDexEnabled true  
    ndk {  
        abiFilters 'armeabi-v7a', 'x86'// , 'arm64-v8a'//, 'x86_64'  
    }  

}  

buildTypes {  
    debug  {  
        signingConfig signingConfigs.config  
        minifyEnabled false  
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'  
    }  
    release {  
        minifyEnabled false  
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'  
    }  
}  

aaptOptions {  
    additionalParameters '--auto-add-overlay'  
    ignoreAssetsPattern "!.svn:!.git:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"  
}  

compileOptions {  
    sourceCompatibility JavaVersion.VERSION_1_8  
    targetCompatibility JavaVersion.VERSION_1_8  
}  

}

dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'  
implementation 'com.google.android.material:material:1.1.0'  
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'  
testImplementation 'junit:junit:4.+'  
androidTestImplementation 'androidx.test.ext:junit:1.1.1'  
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'  

implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])  
implementation "com.android.support:support-v4:28.0.0"  
implementation "com.android.support:appcompat-v7:28.0.0"  
implementation 'com.android.support:recyclerview-v7:28.0.0'  
implementation 'com.facebook.fresco:fresco:1.13.0'  
implementation "com.facebook.fresco:animated-gif:1.13.0"  
implementation 'com.github.bumptech.glide:glide:4.9.0'  
implementation 'com.alibaba:fastjson:1.1.46.android'  

}
同步一下


7.添加对应代码并同步

代码:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
maven{
url 'https://dl.google.com/dl/android/maven2/'
name 'Google'
}
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"

    // NOTE: Do not place your application dependencies here; they belong  
    // in the individual module build.gradle files  
}  

}

allprojects {
repositories {
google()
maven{
url 'https://dl.google.com/dl/android/maven2/'
name 'Google'
}
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
8.HbuilderX生成本地打包app资源

复制此文件夹(UNI20C4F61)

9.打开Android-studio 在assets下创建apps文件夹 将复制的资源包放到apps文件夹下

10.修改appid

11.调试

最终效果 实现uniapp 通过原生离线打包将应用变为Launcher程序

3 关注 分享
迈远科技 huangzoro BoredApe

要回复文章请先登录注册

9***@qq.com

9***@qq.com

回复 huangzoro :
我也是这样的,最后怎么解决的
2023-05-17 11:15
huangzoro

huangzoro

我在第7.添加对应代码并同步 出现了报错,说什么Build被配置为更喜欢设置库而不是项目库,但是Build文件Build .gradle添加了'谷歌'库
2021-08-24 16:21
迈远科技

迈远科技

芜湖!起飞!!!
2021-06-09 17:43