package com.myandroid.main;
/* import相關class */
import java.util.Calendar;
import java.util.StringTokenizer;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;
import android.os.Bundle;
import android.util.Log;
/* 呼叫鬧鐘Alert的Receiver */
public class CallAlarm extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
/* create Intent,呼叫AlarmAlert.class */
String tepName = intent.getStringExtra("name");
String date = intent.getStringExtra("date");
String place = intent.getStringExtra("place");
String time = intent.getStringExtra("time");
String sclass = intent.getStringExtra("class");
final int notifyID = 1; // 通知的識別號碼
final int requestCode = notifyID; // PendingIntent的Request Code
final Intent intent = getIntent(); // 目前Activity的Intent
final int flags = PendingIntent.FLAG_CANCEL_CURRENT; // ONE_SHOT:
PendingIntent只使用一次;CANCEL_CURRENT:PendingIntent執行前會先結束掉之前的;
NO_CREATE:沿用先前的PendingIntent,不建立新的PendingIntent;UPDATE_CURRENT:
更新先前PendingIntent所帶的額外資料,並繼續沿用
final PendingIntent pendingIntent =
PendingIntent.getActivity(context.getApplicationContext(), requestCode,
intent, flags); // 取得PendingIntent
final NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE); // 取得系統的通知服務
final Notification notification = new
Notification.Builder(context.getApplicationContext()).setSmallIcon(R.drawable.keepcon).setContentTitle("
內容標題").setContentText(tepName + ", Time: " + date + " " + time + ",
class:" + sclass + ", in place: " +
place).setContentIntent(pendingIntent).build(); // 建立通知
notificationManager.notify(notifyID, notification); // 發送通知
}
}
想要請問一下,這個callalarm.class類別他是要傳送通知的類別,是根據使用者設定的提
醒時間而傳送通知回去的,但是在callalarm.class的類別中
final Intent intent = getIntent(); // 目前Activity的Intent 這段程式碼寫是錯誤
是因為什麼原因呢?還是不能這麼用??