在我的項目中,我使用了報警代碼。沒有錯誤,但BroadcastReceiver
類中的任何內容都未執行。我不明白故障在哪裏。 我使用Eclipse在Windows中執行此操作。我也在AndroidManifest.xml中指定了<receiver>
類。在Android中接收報警
我希望執行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.This是我用trigerring接收器的編碼。
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();
}
請顯示AndroidManifest.xml – ccheneson 2012-03-28 16:20:07
您可能想要發佈您認爲應該觸發接收器的代碼。 – 2012-03-28 16:20:54
我已經在我的文章中包含了我的androidmanifest和用於觸發報警的代碼... – Kiruthika 2012-03-28 17:25:05