如何在Android设备上的特定日期显示图像

时间:2014-02-18 17:37:03

标签: android image date

您好我想知道如何让应用显示特定于设备当前日期的图像。因此,如果它是1月1日它将显示该日期的相应图像,如果它是3月5日它显示3月5日的图像。

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;


public class WidgetIntentReceiver extends BroadcastReceiver {
    private static int currentImage = 0;

    int[] images = {R.drawable.j_1, R.drawable.j_2,R.drawable.j_3,R.drawable.j_4,
            R.drawable.j_5, R.drawable.j_6, R.drawable.j_7, R.drawable.j_8,
            R.drawable.j_9, R.drawable.j_10, R.drawable.j_11, R.drawable.j_12,
            R.drawable.j_13, R.drawable.j_14, R.drawable.j_15, R.drawable.j_16,
            R.drawable.j_17, R.drawable.j_18, R.drawable.j_19, R.drawable.j_20,
            R.drawable.j_21, R.drawable.j_22, R.drawable.j_23, R.drawable.j_24,
            R.drawable.j_25, R.drawable.j_26, R.drawable.j_27, R.drawable.j_28,
            R.drawable.j_29, R.drawable.j_30, R.drawable.j_31, 

            R.drawable.f_1, R.drawable.f_2, R.drawable.f_3, R.drawable.f_4, 
            R.drawable.f_5, R.drawable.f_6, R.drawable.f_7, R.drawable.f_8,
            R.drawable.f_9, R.drawable.f_10, R.drawable.f_11, R.drawable.f_12,
            R.drawable.f_13, R.drawable.f_14, R.drawable.f_15, R.drawable.f_16,
            R.drawable.f_17, R.drawable.f_18, R.drawable.f_19, R.drawable.f_20,
            R.drawable.f_21, R.drawable.f_22, R.drawable.f_23, R.drawable.f_24,
            R.drawable.f_25, R.drawable.f_26, R.drawable.f_27, R.drawable.f_28,};

    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals("android.appwidget.intent.action.CHANGE_PICTURE"));
        RemoteViews remote = new RemoteViews(context.getPackageName(),R.layout.widget_layout);
        remote.setImageViewResource(R.id.widget_image_view, getImageToSet());

    }



    private int getImageToSet(){
        currentImage++;
        return currentImage = currentImage % images.length ;
    }
}




<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@color/black"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/ImageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/image_view_text"
        android:src="@drawable/j_1" />


    <Button
        android:id="@+id/upButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/ImageView"
        android:layout_alignTop="@+id/ImageView"
        android:text="@string/button_view_text_up" />



    <Button
        android:id="@+id/downButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/ImageView"
        android:layout_alignTop="@+id/ImageView"
        android:text="@string/button_view_text_down" />

</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

你可以通过双向实现它

1。 ExifInterface

  String myAttribute=getTagString(ExifInterface.TAG_DATETIME, exif);
  private String getTagString(String tag, ExifInterface exif)
   {
    return(tag + " : " + exif.getAttribute(tag) + "\n");
   }

2. File Modified time if file.exists()并获取修改文件的时间。

答案 1 :(得分:0)

在你的构造函数中:

public WidgetIntentReceiver()
{
    currentImage = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
}