私はSMSリスナー、以下のコードで作業しています:
public class SMSReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
EventEntry entry = ((MyApplication)context.getApplicationContext()).getCurrent();
System.out.println("Received message: " + smsMessage[0].getMessageBody() + " - SILENCE IS " + ((entry != null) ? "ON" : "OFF"));
}
}
そして AndroidManifest への次の変更
<application
android:name="MyApplication" ...
コードの別の部分 (AlarmManager の BroadcastReceiver 内) では、
public void onReceive(Context context, Intent intent) {
((MyApplication).context.getApplicationContext()).setCurrent("TESTING");
}
ただし、アプリケーションを実行してサンプル テキストを送信すると、次のデバッグ メッセージが表示されます。
09-15 15:07:30.974: I/System.out(21625): DEBUG!!!!!! Setting current event to TESTING
09-15 15:07:54.399: I/System.out(21605): DEBUG!!!!!! Getting current event: null
アプリケーション コンテキストが同期していない理由はありますか?
ありがとう!