Android-设置APP开机自启和隐藏导航栏/状态栏方法

描述

本文适用于触觉智能所有支持Android11系统的开发板设置APP开机自启和隐藏导航栏/状态栏。触觉智能的Purple Pi OH鸿蒙开源主板,是华为Laval官方社区主荐的一款鸿蒙开发主板。

RK3566

 

RK3566

该主板主要针对学生党,极客,工程师,极大降低了开源鸿蒙开发者的入门门槛,具有以下几点优势:

支持开源鸿蒙/Linux /Andriod 11/麒麟,兼容树莓派 ;

四核A55,最高1.8G主频,Mali G52-2EE GPU ;

支持OpenGL/CL/Vulkan/1T NPU/8M ISP ;

支持TensorFlow/MXNet/PyTorch/ Caffe ;

支持1*千兆以太网、3*USB2.0、1*USB3.0、3*UART、2*SPI、2*I2C、28*GPIO、1*MIPI DSI、1*HDMI ;

支持OpenHarmony3.2/4.0/4.1版本,开放SDK源代码 ;

活跃的开发者社区, 更多牛人在线技术支持 ;

超小尺寸,极致性价比,只需249元 ;

 


一、APP自启


1.1 添加自启服务

修改文件:

frameworks\base\core\java\com\android\internal\app\ResolverActivity.java

--- a/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java +++ b/frameworks/base/core/java/com/android/internal/app/ResolverActivity.java @@ -101,6 +101,10 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.concurrent.Executor; +import java.util.function.Consumer; +import android.os.SystemProperties; +import android.app.role.RoleManager; /** * This activity is displayed when the system attempts to start an Intent for @@ -341,6 +345,18 @@ public class ResolverActivity extends Activity implements protected void onCreate(Bundle savedInstanceState, Intent intent, CharSequence title, int defaultTitleRes, Intent[] initialIntents, List rList, boolean supportsAlwaysUseOption) { + + //by Lyle,220923 + String LauncherPkg = SystemProperties.get("persist.sys.def_launherpag"); + if(LauncherPkg!=null/* && !isDefaultLauncher(this,LauncherPkg)*/){ + Log.v("defaultLauncher","-----found default launcher pkg:"+LauncherPkg); + setDefaltLauncher(this,LauncherPkg); + startDefaultLauncher(this,LauncherPkg); + finish(); + return; + } + //end + setTheme(appliedThemeResId()); super.onCreate(savedInstanceState); @@ -433,6 +449,47 @@ public class ResolverActivity extends Activity implements intent.getAction() + ":" + intent.getType() + ":" + (categories != null ? Arrays.toString(categories.toArray()) : "")); } + + + public void setDefaltLauncher(Context context, String packageName) {//by Lyle,220923 + String roleName = "android.app.role.HOME"; + boolean add = true; + int flags = 0; + UserHandle user = android.os.Process.myUserHandle(); + + RoleManager roleManager = context.getSystemService(RoleManager.class); + Executor executor = context.getMainExecutor(); + Consumer< Boolean > callback = successful -> { + if (successful) { + Log.v("defaultLauncher","set Defalt Launcher successful" ); + } else { + Log.v("defaultLauncher","set Defalt Launcher failed "); + } + }; + roleManager.addRoleHolderAsUser(roleName, packageName, flags, user, executor, callback); + } + + public void startDefaultLauncher(Context context, String packageName) { + Intent intent = new Intent(); + PackageManager pm = context.getPackageManager(); + intent = pm.getLaunchIntentForPackage(packageName); + if (intent != null) + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + try { + context.startActivity(intent); + } catch (Exception e) { + Log.v("defaultLauncher","start Default Launcher failed,not find package:"+packageName ); + } + } + + public boolean isDefaultLauncher(Context context,String launcherPkg){ + Intent intent = new Intent(Intent.ACTION_MAIN); + intent.addCategory(Intent.CATEGORY_HOME); + ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); + String currentHomePackage = resolveInfo.activityInfo.packageName; + Log.v("defaultLauncher","-currentHomePackage:"+currentHomePackage); + return launcherPkg.equals(currentHomePackage); + } private boolean isIntentPicker() { return getClass().equals(ResolverActivity.class);


1.2 添加APP

将需要自启的APP放置
device/rockchip/rk356x/rk3566_r/preinstall_del/目录下

(没有preinstall_del目录就手动创建一个即可),并添加以下文件:

Android.mk

xxx.apk(APP)

preinstall.mk

Android.mk文件内容:

include $(call all-subdir-makefiles)
preinstall.mk文件内容:

PRODUCT_PACKAGES += neu

注意:

neu为APP名字,例如neu.apk。

该目录也是APK的预安装目录,如果有新的APK要预安装,可把APK拷贝到preinstall_del/目录下,并且把APK名字添加到preinstall.mk文件即可。

 

1.3 添加APP包名

修改文件:
device/rockchip/rk356x/rk3566_r/rk3566_r.mk
例如包名为:
com.mdptech.neuronappandroidhu
 

--- a/device/rockchip/rk356x/rk3566_r/rk3566_r.mk +++ b/device/rockchip/rk356x/rk3566_r/rk3566_r.mk @@ -46,4 +46,5 @@ PRODUCT_PROPERTY_OVERRIDES += persist.bt.power.down=true PRODUCT_PROPERTY_OVERRIDES += persist.sys.timezone=Asia/Shanghai PRODUCT_PROPERTY_OVERRIDES += ro.vendor.hdmirotationlock=true #PRODUCT_PROPERTY_OVERRIDES += vendor.hwc.device.primary=HDMI-A-1 PRODUCT_PROPERTY_OVERRIDES += vendor.hwc.device.primary=DSI +PRODUCT_PROPERTY_OVERRIDES += persist.sys.def_launherpag=com.mdptech.neuronappandroidhu


包名命令行方式查看:pm list package -3,修改后 make 编译源码即可。

 

 

二、修改导航栏/状态栏


2.1 导航栏

修改文件:

frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml

 

--- a/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml +++ b/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml @@ -22,6 +22,7 @@ xmlns:systemui="http://schemas.android.com/apk/res-auto" android:layout_height="match_parent" android:layout_width="match_parent" + android:visibility="gone" android:background="@drawable/system_bar_background"> + android:layout_height="match_parent" + android:visibility="gone"/>


2.2 状态栏

修改文件:

frameworks/base/packages/SystemUI/res/layout/status_bar.xml

 

--- a/frameworks/base/packages/SystemUI/res/layout/status_bar.xml +++ b/frameworks/base/packages/SystemUI/res/layout/status_bar.xml @@ -26,6 +26,7 @@ android:id="@+id/status_bar" android:orientation="vertical" android:focusable="false" + android:visibility="gone" android:descendantFocusability="afterDescendants" android:accessibilityPaneTitle="@string/status_bar" >


修改后重新make编译即可。

 

Purle Pi OH已过XTS兼容性认证

RK3566
打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分