gpt4 book ai didi

java - Nativescript + Angular - 无法实例化接收器....未找到类

转载 作者:行者123 更新时间:2023-12-02 09:25:40 31 4
gpt4 key购买 nike

我正在开发一个应用程序,我想在其中注册一个新的广播接收器。但是,当触发 Intent 时,应用程序无法找到接收器类并失败并出现以下错误:

System.err: Unable to instantiate receiver org.nativescript.ntngcallerid.PhoneCallReceiver: java.lang.ClassNotFoundException: Didn't find class "org.nativescript.ntngcallerid.PhoneCallReceiver" on path: DexPathList[[zip file "/data/app/org.nativescript.ntngcallerid-1v-8qMmEKBejsoEoL26_7Q==/base.apk"],nativeLibraryDirectories=[/data/app/org.nativescript.ntngcallerid-1v-8qMmEKBejsoEoL26_7Q==/lib/x86, /data/app/org.nativescript.ntngcallerid-1v-8qMmEKBejsoEoL26_7Q==/base.apk!/lib/x86, /system/lib, /system/product/lib]]

电话接收者类别:

import * as Toast from "nativescript-toast";

declare var android: any;

@JavaProxy("com.tns.PhoneCallReceiver")
export class PhoneCallReceiver extends android.content.BroadcastReceiver {

constructor() {
super();

return global.__native(this);
}

// @ts-ignore
onReceive(context: android.content.Context, intent: android.content.Intent): void {
// @ts-ignore

console.log("Receiver start");
Toast.makeText(" Receiver start ", "2000").show();
}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="10000"
android:versionName="1.0">

<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.WRITE_CALL_LOG"/>

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

<application android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
android:theme="@style/LaunchScreenTheme">

<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme"/>

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>


<receiver android:name="com.tns.PhoneCallReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>


</application>
</manifest>

最佳答案

您必须在 webpack.config.js 中添加广播接收器的条目

// Add your custom Activities, Services and other Android app components here.
const appComponents = [
"tns-core-modules/ui/frame",
"tns-core-modules/ui/frame/activity",
"path/to/phone-call-receiver.ts"
];

关于java - Nativescript + Angular - 无法实例化接收器....未找到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58359761/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com