以编程方式更改应用程序图标和应用程序名称后,然后最小化该应用程序后,在后台找不到该应用程序 [英] After the app icon and app name changed programatically, then after minimizing the app the application not found in background

查看:76
本文介绍了以编程方式更改应用程序图标和应用程序名称后,然后最小化该应用程序后,在后台找不到该应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在android kotlin中,我使用活动别名概念更改了应用程序图标和应用程序名称.但是切换图标和应用名称后.最小化该应用程序后,在我的后台找不到该应用程序. 随附视频链接以供参考: https://drive.google.com /file/d/1V59pBDjhC6kvK5uvnRH3Miqd291pbN2g/view?usp = sharing

In android kotlin, I had changed the app icon and app name using activity alias concept. But after switch the icons and app name. When the app is minimized the app is not found in my background. Attached video link for issue reference:https://drive.google.com/file/d/1V59pBDjhC6kvK5uvnRH3Miqd291pbN2g/view?usp=sharing

下面的我的Mainactivity.kt和android.xml代码:

  packageManager.setComponentEnabledSetting(ComponentName("com.example.batpoc","com.example.batpoc.MainActivityOneLaunch"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP)
    packageManager.setComponentEnabledSetting(ComponentName("com.example.batpoc","com.example.batpoc.MainActivity"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP)




<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.batpoc">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="batpoc"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"        
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
          <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
      <activity-alias
            android:name=".MainActivityOneLaunch"
            android:enabled="false"
            android:roundIcon="@mipmap/th"
            android:icon="@mipmap/th"
            android:label="One Launch"
            android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
             <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity-alias>

</application>

请指导.谢谢.

推荐答案

Manifest.xml

<activity android:name="package.name.MainActivity"
 android:screenOrientation="portrait"
 android:label="@string/app_name"
 android:theme="@style/CustomTheme"
 android:launchMode="singleTask">
  <intent-filter>
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

<activity-alias android:label="@string/app_name_default" 
 android:icon="@drawable/icon_default" 
 android:name=".MainActivity-Default"
 android:enabled="true"
 android:targetActivity=".MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>   
</activity-alias>

<activity-alias android:label="@string/app_name_flavor_one" 
 android:icon="@drawable/icon_flavor_one" 
 android:name=".MainActivity-Flavor-One"
 android:enabled="false"
 android:targetActivity=".MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>   
</activity-alias>

现在您可以在这两个别名之间切换,因此我们将更改应用程序图标或/和名称.要从默认"切换到风味一",请使用此代码.

Now you can switch between those two aliases, therefore we will change app icon or/and name. To switch from Default to Flavor-One use this code.

getPackageManager().setComponentEnabledSetting(
    new ComponentName("package.name", "package.name.MainActivity-Flavor-One"), 
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
 getPackageManager().setComponentEnabledSetting(
    new ComponentName("package.name", "package.name.MainActivity-Default"), 
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

请记住,您必须跟踪一次只能启用一个别名

Keep in mind that you have to track that only one alias will be enabled at a time

这篇关于以编程方式更改应用程序图标和应用程序名称后,然后最小化该应用程序后,在后台找不到该应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆