我正在开发一个想要注册新的广播接收器的应用程序。 但是,在触发意图后,应用程序将无法找到接收器类,并且失败并显示以下错误:
System.err:无法实例化接收者 org.nativescript.ntngcallerid.PhoneCallReceiver: java.lang.ClassNotFoundException:找不到类 路径上的“ org.nativescript.ntngcallerid.PhoneCallReceiver”: DexPathList [[zip文件 “ /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>
答案 0 :(得分:1)
您将必须在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"
];