j***@lvluokeji.cn
j***@lvluokeji.cn
  • 发布:2025-04-01 10:06
  • 更新:2025-04-01 10:35
  • 阅读:47

uts中通过广播打开应用没有生效

分类:uts

uts中AndroidManifest.xml文件定义了

复制代码<?xml version="1.0" encoding="utf-8"?>  
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"  
    package="io.dcloud.uni_modules.uts_bootBroadcastReceiver">  

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />  

    <application>  
        <!--开机自启动-->  
        <receiver android:name=".BootBroadcastReceiver" android:enabled="true"  
            android:exported="true">  
            <intent-filter>  
                <action android:name="android.intent.action.BOOT_COMPLETED" />  
                <action android:name="com.example.CUSTOM_INTENT" />  
                <category android:name="android.intent.category.LAUNCHER"></category>  
            </intent-filter>  
        </receiver>  
    </application>  
</manifest>
复制代码import BroadcastReceiver from "android.content.BroadcastReceiver";  
import Context from "android.content.Context";  
import Intent from "android.content.Intent";  
import PandoraEntry from "io.dcloud.PandoraEntry";  

export class BootBroadcastReceiver extends BroadcastReceiver {  
    constructor() {  
        super()  
        console.log('BootBroadcastReceiver init')  
    }  

    override onReceive(context : Context, intent : Intent) {  

        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED") || intent.getAction().equals("com.example.CUSTOM_INTENT")) {  

            const pandoraEntry = new PandoraEntry()  

            const bootMainIntent = new Intent(context, pandoraEntry.javaClass);  

            bootMainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  

            context.startActivity(bootMainIntent);  
        }  

    }  
}

也打了自定义基座,然后使用adb shell am broadcast -a com.example.CUSTOM_INTENT命令发送广播,会出现报错

复制代码04-01 09:48:49.512  3185  3185 W System.err: java.lang.RuntimeException: Unable to instantiate receiver io.dcloud.uni_modules.uts_bootBroadcastReceiver.BootBroadcastReceiver: java.lang.ClassNotFoundException: Didn't find class "io.dcloud.uni_modules.uts_bootBroadcastReceiver.BootBroadcastReceiver" on path: DexPathList[[zip file "/data/app/cn.xxx.xxx.app-1/base.apk"],nativeLibraryDirectories=[/data/app/cn.xxx.xxx.app-1/lib/arm, /data/app/cn.xxx.xxx.app-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
2025-04-01 10:06 负责人:无 分享
已邀请:
DCloud_Android_DQQ

DCloud_Android_DQQ

看上去大概率是包名的问题,如果你没有指定插件的包名。

io.dcloud.uni_modules.uts_bootBroadcastReceiver.BootBroadcastReceiver 会把中划线修改为驼峰。参考一下这个文档 :
https://doc.dcloud.net.cn/uni-app-x/plugin/uts-for-android.html#_3-android%E5%8E%9F%E7%94%9F%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE

你可以尝试指定包名或者修改包名,如果排除了包名之外还有问题,提交一下可以复现问题的示例,我看看。

要回复问题请先登录注册

  • 标题 / 粗斜体
  • 代码片段
  • 超链接 / 图片 / 视频
  • 列表 / 引用

文章内容较多时,可以用标题分段 :

## 大标题 
### 小标题

斜体 / 粗体 :

**粗体** 
*斜体*
***粗斜体***

代码片段 :

``` javascript
代码片段
```

超链接 :

[链接文字](链接地址) 例: [百度](http://www.baidu.com)

图片 :

![图片说明](图片地址) 例: ![百度logo](http://www.baidu.com/img/bdlogo.gif)

视频 :

!![视频说明](视频地址) 例: !![优酷视频](http://youku.com)

有序列表 :

1. 123
2. 123
3. 123

无序列表 :

- 123
- 123
- 123

引用 : ( 双回车后结束引用 )

> 引用内容
引用内容
引用内容