بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
کار نکردن آلارم
سلام
من یک دیالوگی دارم که در اون کاربر میتونه آلارم ذخیره کنه
طریقه کار به این صورت هست که ابتدا فیلد های مربوط به سال,ماه,روز,ساعت و دقیقه پر میشه بعد یک تبدیل شمسی به میلادی بر روی تاریخ انجام میشه و در آخر همگی برای آلارم (نوتیفیکیشن)ذخیره می شوند.
ولی نمیدونم چرا کار نمی کنه!
در این جا تابع setTime مقدار ها رو از EditText ها میگیره و اون ها رو ذخیره میکنه و تابع Roozh تبدیل شمسی به میلادی رو انجام میده
public class setTime extends Activity {
public static custumPicker year;
public static custumPicker month;
public static custumPicker day;
public static custumPicker hour;
public static custumPicker minute;
private int years, months, days, hours, minutes;
int Y;
int Mo;
int D;
int H;
int Mi;
public void data()
{
Y = Integer.valueOf(year.edtValue.getText().toString());
Mo = Integer.valueOf(month.edtValue.getText().toString());
D = Integer.valueOf(day.edtValue.getText().toString());
H = Integer.valueOf(hour.edtValue.getText().toString());
Mi = Integer.valueOf(minute.edtValue.getText().toString());
Roozh PtoG = new Roozh();
PtoG.PersianToGregorian(Y, Mo, D);
this.setHours(H);
this.setMinutes(Mi);
}
public void setYears(int year) {
this.years = year;
}
public int getYears()
{
return this.years;
}
public void setMonths(int month) {
this.months = month;
}
public int getMonths()
{
return this.months;
}
public void setDays(int day) {
this.days = day;
}
public int getDays()
{
return this.days;
}
public void setHours(int hour) {
this.hours = hour;
}
public int getHours()
{
return this.hours;
}
public void setMinutes(int minute) {
this.minutes = minute;
}
public int getMinutes()
{
return this.minutes;
}
}
public class Roozh {
private int day, month, year;
private int jY, jM, jD;
public int gY, gM, gD;
private int leap, march;
setTime date = new setTime();
private int Jal2JD(int jY, int jM, int jD) {
JalCal(jY);
int jd = JG2JD(gY, 3, march, 1) + (jM - 1) * 31 - jM / 7 * (jM - 7)
+ jD - 1;
return jd;
}
private void JD2JG(int JD, int J1G0) {
int i, j;
j = 4 * JD + 139361631;
if (J1G0 == 0) {
j = j + (4 * JD + 183187720) / 146097 * 3 / 4 * 4 - 3908;
}
i = (j % 1461) / 4 * 5 + 308;
gD = (i % 153) / 5 + 1;
gM = ((i / 153) % 12) + 1;
gY = j / 1461 - 100100 + (8 - gM) / 6;
Log.i("time", gD + "/" + gM + "/" + gY);
}
public void PersianToGregorian(int year, int month, int day) {
int jd = Jal2JD(year, month, day);
JD2JG(jd, 0);
date.setYears(gY);
date.setMonths(gM);
date.setDays(gD);
}
}
حالا در یک کلاس دیگه این مقدار ها رو گرفتم و برای آلارم ذخیره کردم
btnsavealarm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
setTime sT = new setTime();
sT.data();
int year = sT.getYears();
int month = sT.getMonths();
int day = sT.getDays();
int hour = sT.getHours();
int minute = sT.getMinutes();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
Intent myIntent = new Intent(MapReminderActivity.this, MyAlarmService.class);
pendingIntent = PendingIntent.getService(MapReminderActivity.this, 0, myIntent, 0);
G.alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
});
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);
MapReminderActivity main = new MapReminderActivity();
mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(), ActivityAlarm.class);
Notification notification = new Notification(R.drawable.home_location, "test", 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(), "test", "notification", pendingNotificationIntent);
mManager.notify(0, notification);
}
@Override
public void onDestroy()
{
super.onDestroy();
}
}
ولی داخل کلاس MyAlarmService نمیره
این هم از manifest برنامه :
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<service
android:name=".MyAlarmService"
android:enabled="true" />
ببخشید اگه سوالم خیلی طولانی شد
ممنون میشم کمک کنید
0
0
؟ (11 سال پیش)
0
0
بیا بالا! (11 سال پیش)
+1
0
دوست عزیز لطفا سوالتون رو خلاصه کنید، اگر اشتباه نکنم در ست کردن آلارم، ماه از 0 شروع میشد. Log بگیرید ببینید آلارمی که ست میکنید به درستی ست میشه یا اعداد اشتباه ست میشن. (11 سال پیش)
0
0
اعداد به درستی ست میشن
برای ست کردن ماه هم (month -1) قرار دادم (11 سال پیش)
+1
0
اگر مشکلتون حل شد، یک حل شده به صورت سوال اضافه کنید (11 سال پیش)
0
0
حل نشده! مشکل من اینه که داخل کلاس MyAlarmService نمیره (11 سال پیش)
0
0
دوستان لطفا کمکم کنید :( (11 سال پیش)
0
0
Log گرفتم این خطا رو داد
Unable to start service Intent { flg=0x4 cmp=com.Test.App.Alarm/.custom_alarm.MyAlarmService (has extras) } U=0: not found
تو نت هم سرچ کردم اما چیزی دستگیرم نشد.
استادید محترم لطفا یه راهنمایی بکنید.
ممنون (11 سال پیش)
برای این سوال پاسخی وجود ندارد.
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .