私のプロジェクトでは、アラーム コードを使用しています。BroadcastReceiver
エラーはありませんが、クラス内の何も実行されていません。どこが悪いのか分かりません。Eclipseを使用してWindowsで実行しています。<receiver>
また、AndroidManifest.xml でクラスを指定しました。
クラス内のコードBroadcastReceiver
を実行したい。この場合、レシーバークラス内で指定されたテキストを指定された時間に表示したい。これは私のレシーバークラスです:
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.registerReceiver(null, null);
Toast.makeText(context, "Time is
up!!!!.",Toast.LENGTH_LONG).show();
}}
誰でもこの問題を解決する方法を提案できますか? ありがとう!!!
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project.rappel"
android:versionCode="1"
android:versionName="1.0">
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<provider
android:name="ScheduleProvider"
android:authorities="com.project.rappel" />
<activity
android:name=".Rappel"
android:label="@string/app_name">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SetSchedule"></activity>
<activity
android:name=".DaysAndTimes"></activity>
<activity
android:name=".Tts"></activity>
<receiver
android:name="MyBroadcastReceiver"
android:process=":remote" />
</application>
<uses-sdk
android:minSdkVersion="8" />
</manifest>
上記は私のandroidmanifest.xmlです。これは、レシーバーをトリガーするために使用したコードです。
public void startAlert(View view) {
EditText text = (EditText) findViewById(R.id.time);
int i = Integer.parseInt(text.getText().toString());
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ (i * 1000), pendingIntent);
Toast.makeText(this, "Alarm set in " + i + " seconds",
Toast.LENGTH_LONG).show();
}