简体   繁体   English

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

[英]how can I make images show on a specific date on android device

Hi I'm wondering how to make an app show an image specific to the current date of the device. 嗨,我想知道如何使应用程序显示特定于设备当前日期的图像。 So if it's the 1st of January it will show the corresponding image for that date, and if it's the 5th of march it shows the image for the 5th of march. 因此,如果是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>

Yo can acheive it by two way 哟可以通过两种方法来实现

1. ExifInterface 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() and get time of modified file. 2. File.exists()的文件修改时间 ,并获取修改文件的时间。

In your constructor: 在您的构造函数中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM