You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过带Intent Filter的Activity启动Android应用时图标名称异常

解决通过自定义Activity启动应用后图标和名称变为Google Play services的问题

2024年6月12日更新:问题根源是手机原生二维码扫描器扫码导致,更换其他扫码器扫码可正常打开应用且无图标名称异常。

我用Avalonia UI框架开发Android应用,新增了一个StartAppActivity用于通过特定链接或扫描二维码启动应用。通过链接/扫码能正常打开应用,但出现以下异常:

  • 应用抽屉中的应用图标变为“Google Play services”图标
  • 应用抽屉中的应用显示名称变为“Google Play services”

该异常仅在通过这个Activity启动时出现,手动点击应用图标启动完全正常。目标是保持应用图标和显示名称始终不变。

核心解决方案

这个问题通常是Android系统处理Intent启动时,错误关联了其他应用组件信息,或Activity配置导致系统混淆应用标识。结合场景可通过以下步骤修复:

  1. 修正Activity启动模式与逻辑
    在StartAppActivity特性中添加LaunchMode = LaunchMode.SingleTask,避免重复创建任务栈引发识别混乱,同时启动主Activity后关闭当前Activity:
[Activity(Label = "MyApp", Name = "com.Test.MyApp.StartAppActivity", MainLauncher = false, LaunchMode = LaunchMode.SingleTask)]
public class StartAppActivity : Activity
{
    protected override void OnCreate(Bundle? savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // 启动主Activity,如需传递链接数据可在此处理
        var mainIntent = new Intent(this, typeof(MainActivity));
        if (Intent?.Data != null)
        {
            mainIntent.PutExtra("DeepLinkData", Intent.Data.ToString());
        }
        StartActivity(mainIntent);
        Finish(); // 关闭当前Activity,避免留存任务栈
    }
}
  1. 优化AndroidManifest.xml配置
    移除intent-filter标签上的icon属性(系统可能优先使用该图标引发冲突),确保application与activity的icon、label完全一致:
<application android:label="MyApp"  
             android:theme="@style/SplashScreen_Theme" 
             android:icon="@mipmap/launcher_foreground" 
             android:logo="@mipmap/launcher_foreground" >
    
    <activity android:name="com.Test.MyApp.StartAppActivity" 
              android:icon="@mipmap/launcher_foreground"  
              android:exported="true"  
              android:label="MyApp"
              android:launchMode="singleTask">
        
        <intent-filter android:label="MyApp">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="MyAppScheme" />
        </intent-filter>

    </activity>
    
</application>
  1. 清理缓存并重装应用
    异常出现后系统可能缓存了错误的应用信息,先卸载应用,清理手机应用缓存,再重新编译安装。

补充说明

根据更新信息,原生扫码器的问题大概率是部分厂商的原生扫码器在处理自定义Scheme时,错误传递了额外Intent信息,导致系统混淆应用组件标识。第三方扫码器的Intent传递更规范,因此不会触发该问题。若需兼容原生扫码器,可在StartAppActivity中添加Intent验证逻辑,确保只处理合法来源的启动请求。

内容的提问来源于stack exchange,提问作者Melon Dusk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 21:13:26