آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

کار نکردن آلارم ویجت

f-Dehghan  11 سال پیش  11 سال پیش
+5 0

لطفا تست کنید و نظرتونو بگید .نمیدونم آلارمش کار میکنه یا نه؟ اگر مشکل دیگه ای هم داشت خوشحال میشم راهنمایی کنید.

لینک دانلود ویجت

+1 0
دانلود کردم ولی خطا میداد وقتی میخواستم نصب کنم (11 سال پیش)
0 0
چک میکنم. با عرض پوزش (11 سال پیش)
0 0
اصلاح شد (11 سال پیش)
0 0
اینگار فقط به صورت ویجت هست درسته؟ میشه بگید چه طوری میشه اینطور برنامه رو ساخت .. استاد هم آموزش دادن؟ که به صورت ویجت باشه (11 سال پیش)
0 0
اگر دوستان تست کردن و سالم بود کدهاش و توضیحاتی که بلد باشم براتون میذارم (11 سال پیش)
0 0
مت (11 سال پیش)
0 0
متاسفانه با مشکل مواجه شدم (11 سال پیش)
 برای این سوال 2 پاسخ وجود دارد.
پاسخ به سوال 
f-Dehghan  11 سال پیش
0 0

کد اینه درست کار میکنه تا چند ساعت ولی بعد متوقف میشه  کسی میتونه مشکلو پیدا کنه؟

 import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.Toast;


public class WidgetProvider extends AppWidgetProvider {

// our actions for our buttons
public static String REFRESH = "refresh";
public static String SHOMARESH = "shomaresh";
public static String ZEKR_SHOMAR = "ZEKR_SHOMAR";
public static String ZEKR_ROOZ = "ZEKR_ROOZ";
public static String ACTION_UPDATE_WIDGET = "ACTION_UPDATE_WIDGET";
static RemoteViews remoteViews;
static PendingIntent zekrshomarPendingIntent;
static PendingIntent zekrroozPendingIntent;
static PendingIntent refreshPendingIntent;
static PendingIntent shomareshPendingIntent;
static int mCount = 0;


@Override
public void onEnabled(Context context) {
Intent myIntent = new Intent(ACTION_UPDATE_WIDGET);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 2, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 1);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.AM_PM, Calendar.AM);
Toast.makeText(context, R.string.well, Toast.LENGTH_LONG).show();
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 86400000, pendingIntent);
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
getImageToSet();
pushWidgetUpdate(context, remoteViews);
super.onEnabled(context);
}


@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Intent myIntent = new Intent(ACTION_UPDATE_WIDGET);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 2, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 1);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.AM_PM, Calendar.AM);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 86400000, pendingIntent);
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);

Intent active = new Intent(context, WidgetProvider.class);
active.setAction(REFRESH);
refreshPendingIntent = PendingIntent.getBroadcast(context, 0, active, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.btnRefresh, refreshPendingIntent);

Intent active1 = new Intent(context, WidgetProvider.class);
active1.setAction(SHOMARESH);
shomareshPendingIntent = PendingIntent.getBroadcast(context, 1, active1, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.btnZekrShomar, shomareshPendingIntent);

Intent active2 = new Intent(context, WidgetProvider.class);
active2.setAction(ZEKR_SHOMAR);
zekrshomarPendingIntent = PendingIntent.getBroadcast(context, 3, active2, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.btnZekr, zekrshomarPendingIntent);

Intent active3 = new Intent(context, WidgetProvider.class);
active3.setAction(ZEKR_ROOZ);
zekrroozPendingIntent = PendingIntent.getBroadcast(context, 4, active3, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.btnRooz, zekrroozPendingIntent);

mCount = 0;
getImageToSet();
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
}


private static String getMessage() {
mCount++;
return String.valueOf(mCount);
}


public static void pushWidgetUpdate(Context context, RemoteViews remoteViews) {
ComponentName myWidget = new ComponentName(context, WidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(myWidget, remoteViews);
}


public static void zekrRoozListener(Context context) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
remoteViews.setViewVisibility(R.id.imgZekr, View.VISIBLE);
remoteViews.setViewVisibility(R.id.btnZekr, View.VISIBLE);
remoteViews.setViewVisibility(R.id.btnRooz, View.INVISIBLE);
remoteViews.setViewVisibility(R.id.rlshomaresh, View.INVISIBLE);
getImageToSet();
//REMEMBER TO ALWAYS REFRESH YOUR BUTTON CLICK LISTENERS!!!
remoteViews.setOnClickPendingIntent(R.id.btnRooz, zekrroozPendingIntent);

pushWidgetUpdate(context, remoteViews);
}


public static void zekrShomarListener(Context context) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
remoteViews.setViewVisibility(R.id.imgZekr, View.INVISIBLE);
remoteViews.setViewVisibility(R.id.btnZekr, View.GONE);
remoteViews.setViewVisibility(R.id.rlshomaresh, View.VISIBLE);
remoteViews.setViewVisibility(R.id.btnRooz, View.VISIBLE);
// remoteViews.setTextViewText(R.id.btnZekr, "zekrerooz");
mCount = 0;
remoteViews.setTextViewText(R.id.txtCount, "0");
getImageToSet();
//REMEMBER TO ALWAYS REFRESH YOUR BUTTON CLICK LISTENERS!!!
remoteViews.setOnClickPendingIntent(R.id.btnZekr, zekrshomarPendingIntent);

pushWidgetUpdate(context, remoteViews);
}


public static void widgetRefreshListener(Context context) {
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
mCount = 0;
remoteViews.setTextViewText(R.id.txtCount, "0");
//REMEMBER TO ALWAYS REFRESH YOUR BUTTON CLICK LISTENERS!!!
remoteViews.setOnClickPendingIntent(R.id.btnRefresh, refreshPendingIntent);

pushWidgetUpdate(context, remoteViews);
}


public static void updateWidgetPictureAndButtonListener(Context context) {
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
String message = getMessage();
getImageToSet();
remoteViews.setTextViewText(R.id.txtCount, message);
//REMEMBER TO ALWAYS REFRESH YOUR BUTTON CLICK LISTENERS!!!
remoteViews.setOnClickPendingIntent(R.id.btnZekrShomar, shomareshPendingIntent);
pushWidgetUpdate(context, remoteViews);
}


public static void getImageToSet() {
Calendar calendar = Calendar.getInstance();
int getrooz = calendar.get(Calendar.DAY_OF_WEEK);
if (getrooz == 1) {
remoteViews.setImageViewResource(R.id.imgZekr, R.drawable.imag2);
}
if (getrooz == 2) {
remoteViews.setImageViewResource(R.id.imgZekr, R.drawable.imag3);
}
if (getrooz == 3) {
remoteViews.setImageViewResource(R.id.imgZekr, R.drawable.imag4);
}
if (getrooz == 4) {
remoteViews.setImageViewResource(R.id.imgZekr, R.drawable.imag5);
}
if (getrooz == 5) {
remoteViews.setImageViewResource(R.id.imgZekr, R.drawable.imag6);
}
if (getrooz == 6) {
remoteViews.setImageViewResource(R.id.imgZekr, R.drawable.imag7);
}
if (getrooz == 7) {
remoteViews.setImageViewResource(R.id.imgZekr, R.drawable.imag1);
}
}


@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("shomaresh")) {
updateWidgetPictureAndButtonListener(context);
}
else if (intent.getAction().equals("refresh")) {
widgetRefreshListener(context);
}
else if (intent.getAction().equals("ZEKR_SHOMAR")) {
zekrShomarListener(context);
}
else if (intent.getAction().equals("ZEKR_ROOZ")) {
zekrRoozListener(context);
}
else if (intent.getAction().equals("ACTION_UPDATE_WIDGET")) {
updateWidgetPictureAndButtonListener(context);

} else {
super.onReceive(context, intent);
}
}
}

این هم توی فایل xml زدم ممکنه از اینجا باشه؟

 android:updatePeriodMillis="86400000"
0 0
کسی نخونده؟ جوابو نمی دونید دوستان؟ (11 سال پیش)
+1 0
علت کرش چی بوده؟ اون رو بنویسید بهتر میشه نظر داد. (11 سال پیش)
0 0
نمیدونم روی گوشی ریختم .معلوم نمیشه stop میزنه .اگه ممکنه پروژه رو تست کنید کلش اون بالاست توی امولیتور مشکلی نداره خیلی گیجم کرده به نظر همه چی درست میاد ولی نمیفهمم مشکل کجاست (11 سال پیش)
پاسخ به سوال 
f-Dehghan  11 سال پیش
0 0

سرچ کردم راه حلو این داده بود کسی میتونه شفاف برام توضیح بده؟

The problem is that you can't do a partiall update for a widget, you must set all the widget features, such as the set of PendingIntent's every time you push a new remoteView. (Partiall updates are only available for API14 and up...).

The reason your widgets are loosing their pendingIntents is that the android system saves the remoteView, and rebuilds your widget with it, in case it resets the widget (shortage of memmory, TaskManager/taskKiller in use, etc...), so you must set all the update code for the widget in the remoteView in your updateService. Otherwise, it's just won't set the pendingIntents again.

So just add the code setting the pendingIntents to the service and your problem will be solved =]

0 0
کسی میتونه اینو بطور مفهوم توضیح بده من نفهمیدم (11 سال پیش)
0 0
دوستان کسی توی این مورد اطلاعی نداره همه اینترنتو زیرو رو کردم...نشد (11 سال پیش)
0 0
یه نفر اینو به من بگه دیگه...... (11 سال پیش)
0 0
اولش هیچ مشکلی نیست خوب کار میکنه بعد از چند ساعت انگار قفل میشه هیچ کاری نمیکنه این صفحه بالا گفته pendingintent اش رو گم میکنه چرا؟معلوم نیست...API14 هم نمیدونم یعنی چی؟ (11 سال پیش)
+1 0
میگن کد هایی که برای ست کردن pendingIntent رو نوشتید به درون سرویستون انتقال بدید. در مورد api 14 هم باید بگم شما از هر چیزی که در برنامتون استفاده میکنید، یک minimum api داره. من با برنامه نویسی ویجت آشنایی ندارم ولی اگر از اندروید استادیو استفاده میکنید خودش یک خط قرمز زیر کدی که بالاتر از minimum sdk در gradle تعریف شده باشه میندازه. اگر هم کدهاتون از api بالای 8 استفاده نمیکنه که نیازی نیست minimum sdk رو تغییر بدید. api 14 == android version 4 (11 سال پیش)
0 0
لطف کردید.با ایکلیپس کار میکنم .مشکل همون pendingintent باید باشه .باید روش کار کنم . ممنون از پاسختون (11 سال پیش)

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .