私はシナリオを持っています。xは期限付きのyにタスクを割り当てます。今は、タスクが割り当てられたときに、つまり、&という時間のボタンクリックで通知を送信しています。今度は、指定された時間に完了しなければリマインダ通知を送信したいと思う。以下 は、私がいることを呼び出したい ...リマインダー通知を送信する方法で私を提案してください私のコード特定の日付と時刻にgcm通知を送信する方法
Button dialogButtonOk = (Button) dialog.findViewById(R.id.dialogButtonOk);
Button dialogButtonNo = (Button) dialog.findViewById(R.id.dialogButtonNo);
dialogButtonOk.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View v){
changeCallStatus();
sendGcmNotification();
dialog.dismiss();
}
});
dialogButtonNo.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View v){
dialog.dismiss();
}
});
dialog.show();
}
public void sendGcmNotification{
String status = "OnHold";
String url = URLMap.getSendNotificationUrl("sendnotification_url");
url = url.replace("{ename}", name).replace("{tid}", aTokenId).replace("{status}", status);
StringRequest request=new StringRequest(Request.Method.GET,url,new Response.Listener<String>(){
@Override
public void onResponse(String response){
Log.i("GCM-MESSAGE","has been sent successfully");
}
},new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
Log.i("GCM-MESSAGE","Failed to send the message : ComplaintDetailsSupervisor.java");
}
});
request.setRetryPolicy(new VolleyRetryPolicy().getRetryPolicy());
RequestQueue queue=((VolleyRequestQueue)getApplication()).getRequestQueue();
queue.add(request);
}
}
サーバーサイドコード
namespace CMS.Notification
{
public class GCMNotification
{
private CMSEntities db = new CMSEntities();
static string gcmid = "AIzaSyCDJbRbAl-mjG2am5R3gAaXmXXXXXXXXX";
static string msg="";
public string AssignEmpNotification(string employeeName, string TokenId,string status)
{
if (status.Trim() == "Open")
msg = "value1" + employeeName;
else if (status.Trim() == "OnHold")
msg = "value5" + employeeName;
else
msg = "value9" + employeeName;
WebRequest tRequest;
tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", GoogleAppID));
String collaspeKey = Guid.NewGuid().ToString("n");
String postData = string.Format("registration_id={0}&data.msg={1}&collapse_key={2}", TokenId, msg, collaspeKey);
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
return sResponseFromServer;
}
}
マイレシーバクラス
public class NotificationService extends GcmListenerService {
String msg;
int time;
public static final String appname = "FM Ninja";
Intent myintent;
public NotificationService() {
// super("GcmIntentService");
}
public static int MESSAGE_NOTIFICATION_ID = 435345;
private static final String TAG = "MyGcmListenerService";
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "From: " + appname);
Log.d(TAG, "Message: " + message);
String msg1 = data.getString("msg");
String name = "six30labs.io";
sendNotification(name, msg1);
}
private void sendNotification(String title, String body) {
Context context = getBaseContext();
if(body.contains("value1")){
msg=body.replace("value1","New complaint has been Raised by \n");
msg = msg + ". Tap to view!!";
myintent=new Intent(this, HomeActivity.class);
myintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
myintent.setAction("item1");
}
else if(body.contains("value5")) {
msg = body.replace("value5", "Your task has been put On Hold by\n");
msg = msg + ". Tap to view!!";
myintent=new Intent(this, HomeActivity.class);
myintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
myintent.setAction("item5");
}
else{
msg=body.replace("value9","Your task is due..Please contact your supervisor to change status..Thanks \n");
msg = msg + ".\n Tap to view!!";
myintent=new Intent(this, HomeActivity.class);
myintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
myintent.setAction("item9");
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setContentTitle(title).setSmallIcon(R.drawable.fmn24).setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg). setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)).setVibrate(new long[]{1000,1000,1000,1000}). setAutoCancel(true).setColor(getResources().getColor(R.color.colorPrimary));
time=(int)System.currentTimeMillis();
PendingIntent intent = PendingIntent.getActivity(context, time,
myintent, 0);
mBuilder.setContentIntent(intent);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID,mBuilder.build());
MESSAGE_NOTIFICATION_ID++;
}
}
です期限が過ぎたときにもう一度sendGcmNotificationメソッドを送信してください。私がsendGcmNotificationメソッドを起動するサービスを書く方法を教えてください。彼は期日と時間を満たしています。 ありがとう