I wrote this program to sync data with the server. Before checking it with the server. I wrote a program to send notifications every 15 minutes.
My phone is oppo A71
Android version 7.1
The following code is not working when I closed the app.
MainActivity.java
PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(
MyPeriodicWork.class,15, TimeUnit.MINUTES)
.addTag("send data") .build();
WorkManager.getInstance().enqueue(periodicWorkRequest);
MyPeriodicWork.java
public class MyPeriodicWork extends Worker {
private static final String FILE_NAME = "chata.txt";
private static final String TAG = "MyPeriodicWork";
public MyPeriodicWork(#NonNull Context context, #NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
#NonNull
#Override
public Result doWork() {
showNotif();
Log.e(TAG,"doWork:work is done");
return Result.success();
}
public void showNotif(){
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),0,intent,0);
Calendar calendar = Calendar.getInstance();
SimpleDateFormat mdformat = new SimpleDateFormat("HH:mm:ss");
String strDate = "Current Time : " + mdformat.format(calendar.getTime());
NotificationCompat.Builder notificationCompat = new NotificationCompat.Builder(getApplicationContext(),"14")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Event Handler")
.setContentText("Helloo"+strDate)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
notificationManagerCompat.notify(4,notificationCompat.build());
}
}
Do I need to add some permissions to manifest file. If yes what are those codes.
this problem on Chinese custom rom they have blacklisted all app except some big app like Facebook,whatsapp etc etc
Related
Since I'm struggling a lot with the Android Oreo background restriction, I was asking myself if working with the AlarmManager is even the best way of timing Job execution to e.g. 03:00 AM. I saw some people use JobScheduler, but it seems it's not that suitable for executing tasks every day at a given time.
I was trying just AlarmManager with a BroadcastReceiver, then inserted the BroadcastReceiver in a (in theory) self-starting service, but since an app isn't able to call startService() when in background this also doesn't work the way it should (and also seems kinda wrong).
Am I missing something? What's the current way to go?
Obviously there are ways, because otherwise Messengers, Games and other Apps won't be able to work the way they do.
public class BackgroundTaskWorker extends Worker {
public BackgroundTaskWorker(#NonNull Context context, #NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
#Override
public Result doWork() {
Log.i("WORKING","DOING SOME WORK");
Context con = getApplicationContext();
SharedPreferences preferences = con.getSharedPreferences(MainActivity.sharedPrefs, Context.MODE_PRIVATE);
SharedPreferences.Editor editPrefs = preferences.edit();
int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
String s_day = preferences.getString("DAY","0");
int old_day = Integer.parseInt(s_day);
if(old_day == 0){
Log.i("WORKING","old_day default");
editPrefs.putString("DAY",Integer.toString(day));
editPrefs.commit();
return Result.success();
}
else if(day == old_day) {
Log.i("WORKING", "day=old_day default");
return Result.success();
}
else {
Log.i("WORKING","old_day change");
editPrefs.putString("DAY",Integer.toString(day));
editPrefs.commit();
Log.d("BISASAM","triggered");
DateFormat date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.GERMANY);
Date dat = new Date();
Log.d("TRIGGERDATE",date.format(dat));
editPrefs.putString("REC", "Receiver called "+date.format(dat));
NotificationCompat.Builder builder= new NotificationCompat.Builder(con,"ID");
builder.setContentTitle("ALARM FIRED");
builder.setContentText("WORKER");
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
builder.setSmallIcon(R.drawable.kreuz);
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) {
Log.d("BUILDCHECK","correct");
CharSequence name = "NotChannel";
String desc = "Test Channel for Planer";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel("NOT",name,importance);
channel.setDescription(desc);
NotificationManager notManager = con.getSystemService(NotificationManager.class);
notManager.createNotificationChannel(channel);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(con);
builder.setChannelId("NOT");
notificationManager.notify(1,builder.build());
}
//TODO Test Tageswechsel Wiederholende Tasks
String today = preferences.getString("0",null);
String tomorrow = preferences.getString("1",null);
String next_week = preferences.getString("7",null);
String next_month = preferences.getString("30",null);
if(today != null) {
String[] repetitive = today.split(" ");
for (int j = 1; j < repetitive.length; j += 2) {
Log.d("PIKACHU",repetitive[j-1]);
switch(repetitive[j]){
case "1":
if(tomorrow!=null)
tomorrow += ","+ repetitive[j-1]+" "+repetitive[j];
else
tomorrow=repetitive[j-1]+" "+repetitive[j];
break;
case "7":
if(next_week!=null)
next_week += ","+ repetitive[j-1]+" "+repetitive[j];
else
next_week=repetitive[j-1]+" "+repetitive[j];
break;
case "30":
if(next_month!=null)
next_month += ","+ repetitive[j-1]+" "+repetitive[j];
else
next_month=repetitive[j-1]+" "+repetitive[j];
break;
default:
}
}
}
Log.d("PUTTING",tomorrow);
Log.d("PUTTING",next_week);
Log.d("PUTTING",next_month);
editPrefs.putString("1",tomorrow);
editPrefs.putString("7",next_week);
editPrefs.putString("30",next_month);
editPrefs.commit();
ArrayList<String> month = new ArrayList<>();
for (int i = 0; i < Jobs.month_length; i++) {
month.add(preferences.getString(Integer.toString(i),""));
}
for (int i=1;i<Jobs.month_length;i++){
month.set(i-1,month.get(i));
}
month.set(30,"");
for(int i=0;i<Jobs.month_length;i++){
editPrefs.putString(Integer.toString(i),month.get(i));
}
Log.d("COMMITED",month.toString());
editPrefs.commit();
}
// Indicate success or failure with your return value:
return Result.success();
}
}
private void registerWorker(){
unregisterWorker();
PeriodicWorkRequest request= new PeriodicWorkRequest.Builder(BackgroundTaskWorker.class,
20, TimeUnit.MINUTES)
.addTag("AUFGABEN_PLANER_BACK")
.build();
WorkManager.getInstance().enqueueUniquePeriodicWork("AUFGABEN_PLANER_BACK", ExistingPeriodicWorkPolicy.KEEP, request);
}
private void unregisterWorker(){
WorkManager.getInstance().cancelAllWorkByTag("AUFGABEN_PLANER_BACK");
}
registerWorker is called everytime MainActivity gets started (=> at the app start)
Use WorkManager for Scheduling task in background and foreground
Example for Periodic Request
PeriodicWorkRequest request= new PeriodicWorkRequest.Builder(WorkerClass.class,
24, TimeUnit.HOURS).setInitialDelay(THE_DELAY,TimeUnit.SECONDS).addTag("TAG").build()
WorkManager.getInstance().enqueueUniquePeriodicWork("TAG", ExistingPeriodicWorkPolicy.KEEP, request);
Create a worker class
public class WorkerClass extends Worker {
#Override
public Worker.WorkerResult doWork() {
// Do the work here
// Indicate success or failure with your return value:
return WorkerResult.SUCCESS;
// (Returning RETRY tells WorkManager to try this task again
// later; FAILURE says not to try again.)
}
}
Now call this class by
Example for One Time request
OneTimeWorkRequest request= new OneTimeWorkRequest.Builder(WorkerClass .class)
.setInitialDelay(delayedTime, TimeUnit.MILLISECONDS)
.addTag("TAG")
.build();
WorkManager.getInstance().enqueueUniquePeriodicWork("TAG", ExistingPeriodicWorkPolicy.KEEP, request);
where delayedTime is calculated time to do task
add this in build.gradle
implementation 'android.arch.work:work-runtime:2.1.0-alpha02'
check the latest release doc
https://developer.android.com/jetpack/androidx/releases/work
also you can convert your time
Android / Java convert String date to long type
I'm using WorkManager that schedule my notifications, it works when my smartphone is active, but it doesn't work when my smartphone is in standby. Why? There is some constraint that let me that? Or whatever?
Method notifyPush in CoreActivity.java
public static void notifyPush(String message, Context context)
{
//codice di un altro programma
// Make a channel if necessary
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
CharSequence name = Constants.VERBOSE_NOTIFICATION_CHANNEL_NAME;
String description = Constants.VERBOSE_NOTIFICATION_CHANNEL_DESCRIPTION;
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
// Add the channel
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
// Create the notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(Constants.NOTIFICATION_TITLE)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(DEFAULT_ALL);
//.setVibrate(new long[0]);
// Show the notification
NotificationManagerCompat.from(context).notify(Constants.NOTIFICATION_ID, builder.build());
}
NotifyWorker.java
package com.example.msnma.movienotifier.notify;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import com.example.msnma.movienotifier.CoreActivity;
import androidx.work.Data;
import androidx.work.Worker;
import static com.example.msnma.movienotifier.CoreActivity.notifyPush;
import static com.example.msnma.movienotifier.notify.Constants.KEY_MOVIE;
public class NotifyWorker extends Worker {
//private static final String TAG = BlurWorker.class.getSimpleName();
#NonNull
#Override
public Worker.Result doWork() {
Context applicationContext = getApplicationContext();
String message = getInputData().getString(Constants.KEY_MOVIE);
//setOutputData(new Data.Builder().putString(
//KEY_MOVIE, message.toString()).build());
try {
notifyPush(message , applicationContext);
return Worker.Result.SUCCESS;
} catch (Throwable throwable) {
// Technically WorkManager will return WorkerResult.FAILURE
// but it's best to be explicit about it.
// Thus if there were errors, we're return FAILURE
Log.e("NotifyWorker", "Error notification", throwable);
return Worker.Result.FAILURE;
}
}
}
Methods scheduleNotify and deleteNotify in MovieAdapter.java
private UUID scheduleNotify(Date d, int position)
{
long currentTime= System.currentTimeMillis();
//Calendar c = new Date;
long specificTimeToTrigger = d.getTime();
//d.getTimeToMillis();
long delayToPass = specificTimeToTrigger - currentTime;
/*OneTimeWorkRequest compressionWork =
new OneTimeWorkRequest.Builder(NotifyWorker.class)
.setInputData(message)
.setInitialDelay(delayToPass, TimeUnit.MILLISECONDS)
.build();*/
//inizialmente รจ molto semplice la notifica
OneTimeWorkRequest notifyRequest =
new OneTimeWorkRequest.Builder(NotifyWorker.class)
.setInputData(createInputDataForUri(movies.get(position)))
.setInitialDelay(delayToPass,TimeUnit.MILLISECONDS)
.build();
mWorkManager.enqueue(notifyRequest);
UUID notify_ID = notifyRequest.getId();
//WorkManager.getInstance().enqueue(compressionWork);
return notify_ID;
}
public void deleteNotify(UUID notify_ID)
{
WorkManager.getInstance().cancelWorkById(notify_ID);
}
WorkManager uses JobScheduler and that will batch jobs during maintenance windows to optimize battery usage.
Also, here is the constraint you are looking for.
Since Version 1.0.0-alpha06
A bug which causes PeriodicWork to not run on schedule when in Doze mode was fixed .
https://issuetracker.google.com/issues/111469837
I am having an issue on Oreo devices where notifications are simply just not displayed in the hud when they are sent to client. I can assure that they are being received in the background as i've created a custom vibration effect OnMessageReceived and this works but still nothing is displayed in the Android HUD.
Also, I've noticed another article saying Visual Studio kills the notification service when forcefully closed. This is true because it also killed my vibration effect, but with the app side loaded I can launch from the device and my custom effect is triggered.
I believe what I am doing is 1, registering my tags to the Azure-FCM service.
2nd, I am saying registering my API Endpoint and also the allowed templates.
I think there is something wrong with the payload templates I am registering,
and the payloads I am sending
See below..
Web API that generates Android payload
private string GetAndroidAlertJson(int? fromId, int notificationType, string message)
{
return new JObject(
new JProperty("data",
new JObject(
new JProperty("notification",
new JObject(
new JProperty("badge", 1),
new JProperty("body", message),
new JProperty("title", "wazzup?!"),
new JProperty("priority", "high")
)
),
new JProperty("type_id", notificationType),
new JProperty("user", fromId != null ? fromId.ToString() : ""),
new JProperty("message", message)
)
)
).ToString();
}
Xamarin.Android
//NotificationBuilder
return new NotificationCompat.Builder(ApplicationContext, PRIMARY_CHANNEL)
.SetContentTitle(title)
.SetContentText(body)
.SetSmallIcon(SmallIcon)
.SetPriority(2)
.SetVibrate(new long[0])
.SetAutoCancel(true);
//In MainActivity
public NotificationHelper(Context context) : base(context)
{
var chan1 = new NotificationChannel(PRIMARY_CHANNEL,
PRIMARY_CHANNEL, NotificationImportance.Max);
chan1.LightColor = 2;
chan1.LockscreenVisibility = NotificationVisibility.Public;
Manager.CreateNotificationChannel(chan1);
}
public NotificationCompat.Builder GetNotification1(String title, String body)
{
return new NotificationCompat.Builder(ApplicationContext, PRIMARY_CHANNEL)
.SetContentTitle(title)
.SetContentText(body)
.SetSmallIcon(SmallIcon)
.SetPriority(2)
.SetVibrate(new long[0])
.SetAutoCancel(true);
}
FCMService
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class FCMMessagingService : FirebaseMessagingService
{//Foreground Only
const string TAG = "MyFirebaseMsgService";
public override void OnMessageReceived(RemoteMessage message)
{
if (Debugger.IsAttached)
Debugger.Break();
CustomNotificationEffect();
try
{
if (message.Data.Count > 0)
{
var type_id = Convert.ToInt32(RetreiveNotification("type_id"));
var body = RetreiveNotification("message");
MainActivity.SendNotification(type_id, body);
}
}
catch (Exception e)
{
//Was NotificationType null? this should never be null anyways
}
string RetreiveNotification(string key)
{
string value = String.Empty;
message.Data.TryGetValue(key, out value);
return value;
}
}
[Service]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class FCMInstanceIDService : FirebaseInstanceIdService
{
const string TAG = "MyFirebaseIIDService";
public static string ProfilePushTag;
public async override void OnTokenRefresh()
{
var refreshedToken = FirebaseInstanceId.Instance.Token;
Console.WriteLine("Token Received!: " + refreshedToken);
await SendRegistrationToServer(refreshedToken);
}
public async Task SendRegistrationToServer(string token)
{
//We will have to send our token to the server here
//
string templateBodyFCM =
"{" +
"\"notification\" : {" +
"\"body\" : \"$(messageParam)\"," +
"\"title\" : \"Xamarin U\"," +
"\"icon\" : \"myicon\" }}";
var templates = new JObject();
//templateBodyFCM = "Pyx";
templates["genericMessage"] = new JObject
{
{ "body", templateBodyFCM}
};
try
{
var tags = new List<string>();
if (!String.IsNullOrWhiteSpace(ProfilePushTag))
{
// Register with Notification Hubs
var hub = new NotificationHub("HUB-NAME",
"AZURE-ENDPOINT"
, this);
tags.Add(ProfilePushTag);
var regID = hub.Register(token, tags.ToArray()).RegistrationId;
var hub2 = new MobileServiceClient("https://MyAPI");
await hub2.GetPush().RegisterAsync(token, templates);
}
}
catch (Exception e)
{
}
}
In Android O it's a must to use a channel with your Notification Builder
below is a sample code of how you should use it :
public NotificationCompat.Builder GetNotification1(String title, String body) {
var mynotif = new Notification.Builder(ApplicationContext)
.SetContentTitle(title)
.SetContentText(body)
.SetSmallIcon(SmallIcon)
.SetPriority(2)
.SetVibrate(new long[0])
.SetAutoCancel(true);
if (Build.VERSION.SdkInt >= BuildVersionCodes.O) {
mynotif.SetChannelId(PRIMARY_CHANNEL);
}
}
If you look at my Web API, everything is wrapped inside a "data" type. According to this article How to handle notification when app in background in Firebase the "data" types will not be displayed in the HUD, but the "notification" types will. removing this attribute resolved the issue and is now displayed in the HUD.
I'm writing an android app that tracks the user's location and shows the distance, time and price of the trip in a notification, all this tracked in a ForegroundService. The service tracks the location, price and the time, and I'm updating the notification every second.
I get this TransactionTooLargeException in production for the very first notification update, it only happens on Samsung devices running Android 8.0+.
This is what's happening:
I call the start method from the service:
public void start(MeasureService service) {
service.startForeground(NOTIFICATION_ID, getNotification(0, 0, 0));
}
I call the update method from the service:
public void update(int price, float meters, long time) {
mNotificationManager.notify(NOTIFICATION_ID, getNotification(price, meters, time));
}
Actually, these calls are called right after one another, the crash is coming from the update method. Can this (calling them one after the other) be a problem?
this is the getNotification:
private Notification getNotification(int price, float meters, long seconds) {
if (mNotificationBuilder == null) {
createNotificationBuilder();
}
return mNotificationBuilder
.setCustomContentView(getSmallView(price))
.setCustomBigContentView(getBigView(price, seconds, meters))
.build();
}
where the getSmallView and getBigView methods are like this:
private RemoteViews getSmallView(int price) {
String priceText = ...;
mSmallView.setTextViewText(R.id.price, priceText);
return mSmallView;
}
private RemoteViews getBigView(int price, long seconds, float meters) {
String priceText = ...;
String timeText = ...;
String distanceText = ...;
mBigView.setTextViewText(R.id.price, priceText);
mBigView.setTextViewText(R.id.time, timeText);
mBigView.setTextViewText(R.id.distance, distanceText);
return mBigView;
}
and this is how I create the notificationBuilder:
private void createNotificationBuilder() {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
mNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIFICATION_CHANNEL_ID);
mNotificationBuilder = mNotificationBuilder
.setSmallIcon(R.drawable.icon)
.setOngoing(true)
.setContentIntent(getOpenMeasurePageIntent());
}
and the getOpenMeasurePageIntent:
private PendingIntent getOpenMeasurePageIntent() {
Intent launchMeasureIntent = new Intent(mContext, MainActivity.class);
launchMeasureIntent.setAction(...);
launchMeasureIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
return PendingIntent.getActivity(mContext, 0, launchMeasureIntent, 0);
}
This is the crash log I get:
Caused by: java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 560988 bytes
16 at android.app.NotificationManager.notifyAsUser(NotificationManager.java:319)
17 at android.app.NotificationManager.notify(NotificationManager.java:284)
18 at android.app.NotificationManager.notify(NotificationManager.java:268)
19 at com.myapp.service.measure.MyNotification.void update(int,float,long) <- this is called from the timer
I found a lot of similar issues online, but they are usually about passing big chunks of data in the intent, which I believe I'm not doing.
Any idea what I might be doing wrong?
i think problem is in updating Notification every seconds.
Solution
i suggest you should update notification only when data likes(distance, price) changed.
I have a function that triggers the date to the firebase database node and sending notification when user inputs data to the android device. I want to to schedule timer to send this notification using an external cron job.I have the code below that successfully sends notification as soon as the user enters the date. Can any one help me please as I'm finding really hard to understand it.What do I have to modify to make it work?
This is the index.js
var functions = require('firebase-functions');
var admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Users/{userId}/description/{descId}')
.onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
var eventSnapshot = event.data;
var str1 = "Your profile title is ";
var str2 = "Date is ";
var strProfile = str1.concat(eventSnapshot.child("title").val());
var strStatus = str2.concat(eventSnapshot.child("date").val());
console.log(strProfile);
console.log(strStatus)
var topic = "android";
var payload = {
data: {
title: eventSnapshot.child("title").val(),
date: eventSnapshot.child("date").val()
}
};
// Send a message to devices subscribed to the provided topic.
return admin.messaging().sendToTopic(topic, payload)
.then(function (response) {
// See the MessagingTopicResponse reference documentation for the
// contents of response.
console.log("Successfully sent message:", response);
})
.catch(function (error) {
console.log("Error sending message:", error);
});
});
MyFirebaseMessagingService Activity
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
showNotification(remoteMessage.getData().get("title"), remoteMessage.getData().get("date"));
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
}
}
private void showNotification(String title, String date) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle("title is " + title)
.setSmallIcon(R.drawable.alex)
.setContentText("your deadline date is " + date)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
You can easily achieve this with the help of AlarmManager. When user inputs a date, get that date and set an Alarm for that specific date and time like this:
Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());//set the current time and date for this calendar
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR, cur_cal.get(Calendar.DAY_OF_YEAR));
cal.set(Calendar.HOUR_OF_DAY, 18);
cal.set(Calendar.MINUTE, 32);
cal.set(Calendar.SECOND, cur_cal.get(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cur_cal.get(Calendar.MILLISECOND));
cal.set(Calendar.DATE, cur_cal.get(Calendar.DATE));
cal.set(Calendar.MONTH, cur_cal.get(Calendar.MONTH));
Intent intent = new Intent(ProfileList.this,
IntentBroadcastedReceiver.class);
PendingIntent pintent = PendingIntent.getService(ProfileList.this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pintent);
Then you have to set up a Broadcast Receiver to handle the event. In onReceive() method of your Broadcast Receiver, you will call your web-service to send the request to your server.
public class MyBroadcastReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent) {
// Call your web-service here.
}
}
Don't forget to define receiver in manifest:
<receiver android:name=".MyBroadcastReceiver" >