简体   繁体   中英

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.

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

  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.

In your constructor:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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