سرویس آلارم منیجر
با سلا خدمت دوستان عزیز من یک سوال دارم
آیا امکان داره سرویس الارم منیجر به جای استفاده کردن از تاریخ به یک مقدار حساس باشد؟ بفرض براش تعریف کنیم که اگر یک مقداری برابر با true شد گوشی آلارم بده.
این true شدن هم زمان بخصوصی نداره و بستگی به این داره که چه زمانی کوری گرفت از دیتابیس مقداری داخل خودش داشته باشه.
چنین چیزی امکان داره؟؟
من با استفاده از این لینک کد های زیر را نوشتم اما ایراد برنامه این هست که برنامه تا باز میشه نایفکشن ظاهر میشه و حتی ساعت هم براش مهم نیست.
کلاس main acticity:
privatePendingIntent pendingIntent;
privateCalendar calendar;
publicint setHours =18;
publicint setMinutes =26;
publicint setSeconds =0;
setHours =Integer.parseInt(hours.getText().toString());
setMinutes =Integer.parseInt(minutes.getText().toString());
setSeconds =Integer.parseInt(seconds.getText().toString());
calendar =Calendar.getInstance();
Calendar c =Calendar.getInstance();
calendar.set(Calendar.MONTH, c.get(Calendar.MONTH));
calendar.set(Calendar.YEAR, c.get(Calendar.YEAR));
calendar.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH));
calendar.set(Calendar.HOUR_OF_DAY, setHours);
calendar.set(Calendar.MINUTE, setMinutes);
calendar.set(Calendar.SECOND, setSeconds);
calendar.set(Calendar.AM_PM,Calendar.PM);
Cursor cursor=G.database.rawQuery("SELECT * FROM data2 WHERE date2 LIKE '%"+dateFarsi2+"%' AND done='false'", null);
if(cursor.getcount!=0){
Intent myIntent =newIntent(MainActivity.this,MyReceiver.class);
pendingIntent =PendingIntent.getBroadcast(MainActivity.this,0, myIntent,0);
AlarmManager alarmManager =(AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
}
publicclassMyReceiverextendsBroadcastReceiver
{
@Override
publicvoid onReceive(Context context,Intent intent)
{
Vibrator vibrator =(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
Intent service1 =newIntent(context,MyAlarmService.class);
context.startService(service1);
}
}
public class MyAlarmService extends Service
{
private NotificationManager mManager;
@Override
public IBinder onBind(Intent arg0)
{
return null;
}
@Override
public void onCreate()
{
super.onCreate();
}
@SuppressWarnings("static-access")
@Override
public void onStart(Intent intent,int startId)
{
super.onStart(intent, startId);
mManager =(NotificationManager)this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 =newIntent(this.getApplicationContext(),NextActivity.class);
Notification notification =newNotification(R.drawable.ic_launcher,"message!",System.currentTimeMillis());
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent =PendingIntent.getActivity(this.getApplicationContext(),0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |=Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(this.getApplicationContext(),"AlarmManagerDemo","This a test message!", pendingNotificationIntent);
Toast.makeText(this,"salaaaaaaaaaaaaaam",Toast.LENGTH_LONG).show();
MakeSomeSound();
mManager.notify(0, notification);
}
public void MakeSomeSound(){
try{
Uri notification =RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r =RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
}
catch(Exception e){
e.printStackTrace();
}
}
@Override
publicvoid onDestroy()
{
// TODO Auto-generated method stub
super.onDestroy();
}
}
امیر جان شما میخوای زمانی که یک مقدار در دیتابیس تغییر کرد یک متد کال بشه، خوب برنامه آنلاین نیست پس فقط از توی خود برنامه میشه که این مقدار تغییر کنه،، پس زمانی که تغییر انجام شد باید متد مورد نظرت رو کال کنی، اینکه هر روز بری اون متغیر رو چک کنی کار درستی نیست، ولی در صورتی که حتما میخوای این کار راس یک ساعتی انجام بشه درسته.
امیر جان کدت رو چک کردم هیچ مشکلی نمیبینم، دیباگ کن ببین توی calenderet چه مقادیری ذخیره شده، معمولا زمانی نوتیفیکیشن ارسال میشه که تایمی که ست کرده باشی گذشته باشه ولی بازم بدون دیباگ نمیشه فهمید.
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .