如何在Android中设置实时壁纸的剩余天数

如何在Android中设置实时壁纸的剩余天数,android,live-wallpaper,Android,Live Wallpaper,我创建了一个应用程序来计算Android中的剩余天数。我也有现场壁纸应用程序 现在我想在实时壁纸屏幕上设置剩余的天数。我该怎么做 如果客户端可以访问Internet,您可以使用web服务,或者您可以将日期存储在某个位置并进行更新,如果您了解Java,则使用web服务非常简单。此应用程序与Twilight Screenboard相同。您是对的。。但如果我想让它在设备中变得简单。类似于实时墙纸服务..在墙纸画布StaticLayout layout=new StaticLayout(text,txt

我创建了一个应用程序来计算Android中的剩余天数。我也有现场壁纸应用程序


现在我想在实时壁纸屏幕上设置剩余的天数。我该怎么做

如果客户端可以访问Internet,您可以使用web服务,或者您可以将日期存储在某个位置并进行更新,如果您了解Java,则使用web服务非常简单。

此应用程序与Twilight Screenboard相同。您是对的。。但如果我想让它在设备中变得简单。类似于实时墙纸服务..在墙纸画布StaticLayout layout=new StaticLayout(text,txtpaint,textW,layout.Alignment.ALIGN\u NORMAL,1.3f,0,false)中使用这样的代码写入时间日期;translate(xoffs,yoffs)//定位文本布局。绘制(txtcanvas);
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class DateTest {

public class DateTest {

static SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");

public static void main(String[] args) {

  TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));

  //diff between these 2 dates should be 1
  Date d1 = new Date("01/01/2007 12:00:00");
  Date d2 = new Date("01/02/2007 12:00:00");

  //diff between these 2 dates should be 1
  Date d3 = new Date("03/24/2007 12:00:00");
  Date d4 = new Date("03/25/2007 12:00:00");

  Calendar cal1 = Calendar.getInstance();cal1.setTime(d1);
  Calendar cal2 = Calendar.getInstance();cal2.setTime(d2);
  Calendar cal3 = Calendar.getInstance();cal3.setTime(d3);
  Calendar cal4 = Calendar.getInstance();cal4.setTime(d4);

  printOutput("Manual   ", d1, d2, calculateDays(d1, d2));
  printOutput("Calendar ", d1, d2, daysBetween(cal1, cal2));
  System.out.println("---");
  printOutput("Manual   ", d3, d4, calculateDays(d3, d4));
  printOutput("Calendar ", d3, d4, daysBetween(cal3, cal4));
}


private static void printOutput(String type, Date d1, Date d2, long result) {
  System.out.println(type+ "- Days between: " + sdf.format(d1)
                    + " and " + sdf.format(d2) + " is: " + result);
}

/** Manual Method - YIELDS INCORRECT RESULTS - DO NOT USE**/
/* This method is used to find the no of days between the given dates */
public static long calculateDays(Date dateEarly, Date dateLater) {
  return (dateLater.getTime() - dateEarly.getTime()) / (24 * 60 * 60 * 1000);
}

/** Using Calendar - THE CORRECT WAY**/
public static long daysBetween(Calendar startDate, Calendar endDate) {
  Calendar date = (Calendar) startDate.clone();
  long daysBetween = 0;
  while (date.before(endDate)) {
    date.add(Calendar.DAY_OF_MONTH, 1);
    daysBetween++;
  }
  return daysBetween;
}
}