タイトルの通り、配信でトラブルが発生しました。一部のインテントをメイン アクティビティに送信するサービスを取得しました (ブロードキャストでこれらのメッセージを受信します)。
このログを取得しました:
08-03 18:23:11.581: E/AndroidRuntime(776): FATAL EXCEPTION: main
08-03 18:23:11.581: E/AndroidRuntime(776): java.lang.RuntimeException: Unable to instantiate receiver com.example.proyectjane_smartphone.Main.$IncomingBroadcaster: java.lang.ClassNotFoundException: com.example.proyectjane_smartphone.Main.$IncomingBroadcaster in loader dalvik.system.PathClassLoader[/data/app/com.example.proyectjane_smartphone-1.apk]
08-03 18:23:11.581: E/AndroidRuntime(776): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1777)
08-03 18:23:11.581: E/AndroidRuntime(776): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
08-03 18:23:11.581: E/AndroidRuntime(776): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
08-03 18:23:11.581: E/AndroidRuntime(776): at android.os.Handler.dispatchMessage(Handler.java:99)
08-03 18:23:11.581: E/AndroidRuntime(776): at android.os.Looper.loop(Looper.java:130)
08-03 18:23:11.581: E/AndroidRuntime(776): at android.app.ActivityThread.main(ActivityThread.java:3687)
08-03 18:23:11.581: E/AndroidRuntime(776): at java.lang.reflect.Method.invokeNative(Native Method)
08-03 18:23:11.581: E/AndroidRuntime(776): at java.lang.reflect.Method.invoke(Method.java:507)
08-03 18:23:11.581: E/AndroidRuntime(776): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-03 18:23:11.581: E/AndroidRuntime(776): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-03 18:23:11.581: E/AndroidRuntime(776): at dalvik.system.NativeStart.main(Native Method)
08-03 18:23:11.581: E/AndroidRuntime(776): Caused by: java.lang.ClassNotFoundException: com.example.proyectjane_smartphone.Main.$IncomingBroadcaster in loader dalvik.system.PathClassLoader[/data/app/com.example.proyectjane_smartphone-1.apk]
08-03 18:23:11.581: E/AndroidRuntime(776): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-03 18:23:11.581: E/AndroidRuntime(776): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-03 18:23:11.581: E/AndroidRuntime(776): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-03 18:23:11.581: E/AndroidRuntime(776): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1768)
08-03 18:23:11.581: E/AndroidRuntime(776): ... 10 more
これは、broadcastReceiver のコードです (内部クラスとして定義されているため、マニフェスト内の名前は、「$」を使用して「com.example.proyectjane_smartphone.Main.$IncomingBroadcaster」になります)。
class IncomingBroadcaster extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ACTION_CHANGE_TEXT_IO)) {
textIO.setText("OUTUT: " + intent.getStringExtra("text"));
} else if (action.equals(ACTION_SPEAK)) {
JANEvoi.speak(intent.getStringExtra("speak"));
} else if (action.equals(ACTION_CHANGE_LIGHT)) {
if (intent.getBooleanExtra("light", false)) {
connLight.setImageResource(R.drawable.lighton);
} else {
connLight.setImageResource(R.drawable.lightoff);
}
} else if (action.equals(ACTION_ENABLE_BT)) {
Intent enableBtIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent,
BluetoothManager.REQUEST_ENABLE_BT);
}
}
}
ブロードキャストを内部クラスとして定義する必要があります。これは、一部のテキストを変更して「activityforResult」を呼び出すためです。これはメイン アクティビティでのみ可能です。
呼び出しはサービスに対して行われます。例外を発生させる例を次に示します。
public void enableBluetoothAdapter() {
if (blueManager.getAdapter() == null) {
Log.d("BLUETOOTHMANAGER", "There's no bluetooth adapter");
} else if (!blueManager.getAdapter().isEnabled()) {
Intent enableBTIntent = new Intent(Main.ACTION_ENABLE_BT);
sendBroadcast(enableBTIntent);
Log.d("BLUETOOTH", "BLUETOOTH ENCENDIDO");
}
}
私が理解できないのは、(たとえば「ACTION_ENABLE_BT」を使用すると)インテントが送受信されることです。これは、アクティビティがクラッシュしている間にBluetoothをアクティブにする「ポップアップメニュー」が表示されるためです...したがって、以前のブロードキャストクラッシュが使用されました(ブロードキャストをインスタンス化できないというエラーを受け取ったにもかかわらず...)。
最後に、マニフェストは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.proyectjane_smartphone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.proyectjane_smartphone.Main"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.example.proyectjane_smartphone.Main.$IncomingBroadcaster"
android:exported="false" >
<intent-filter>
<action android:name="es.jane.SpeakAction" />
<action android:name="es.jane.ChangeTextIOAction" />
<action android:name="es.jane.ChangeLight" />
<action android:name="es.jane.EnableBT" />
</intent-filter>
</receiver>
<service android:name="com.example.proyectjane_smartphone.Bluetooth.BluetoothService" >
</service>
</application>
</manifest>
私は検索していましたが、解決策が見つかりませんでした。前もって感謝します