2014-02-18 31 views
0

您好我想知道如何讓應用程序顯示特定於設備當前日期的圖像。因此,如果是1月1日,它將顯示該日期的相應圖像,如果是3月5日,則顯示3月5日的圖像。我如何使圖像顯示在Android設備上的特定日期

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> 
+0

所以你要讀取的圖像的EXIF數據,如拍攝日期? – nikis

+0

你可以分享一些代碼,看看你已經嘗試過嗎? – Merlevede

+0

你想要在你的應用中顯示這個圖像,或者你想創建一個彈出窗口或小部件? –

回答

0

在你的構造:

public WidgetIntentReceiver() 
{ 
    currentImage = Calendar.getInstance().get(Calendar.DAY_OF_YEAR); 
} 
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如果file.exists()acheive,並得到修改文件的時間。

相關問題