我的應用程序是一個小部件,其背景是一個imageView。 在WidgetProvider的的onUpdate()方法,我把位圖從SD卡這個ImageView的內部調用這個方法:當SD卡安裝/卸載時,Widget丟失位圖背景
public static void changeSkinWidget(Context context,String imageBackgroundPath) throws IOException{
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.widget);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Log.i(Constants.DebugTag,"changeSkinWidget receive new path " +imageBackgroundPath);
//Change Background Skin :
FileInputStream is;
try {
is = new FileInputStream(new File(imageBackgroundPath
+ "background.png"));
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(is);
views.setImageViewBitmap(R.id.ImageBackground01, bm);
ComponentName thisWidget = new ComponentName(context,
MyWidget.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(thisWidget, views);
bis.close();
is.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
的問題是,我總是掛載/卸載SD卡,小部件失去這個位圖,以及ImageView的得到佈局聲明(src = R.drawable.defaultbackground)中找到的defaut drawable,看起來我的小部件已重新加載。 要跟蹤這個我把onReceive()方法: Log.i(Constants.DEBUG_TAG,「RECEIVE INTENT:」+ intent.getAction()); 但logcat中沒有任何內容......我預計可能會有一個ACTION_APPWIDGET_UPDATE 操作的意圖,但沒有任何結果。
我也試圖調用recycle()到我的位圖...這並不能解決問題。
我沒有得到任何奇怪的錯誤看,同時安裝/卸載到logcat的......
任何幫助將感激! Christophe。
謝謝你的回答。但它並沒有解決問題,只是爲了測試我試圖寫我的PNG內部存儲,並從這個內部存儲文件創建一個新的位圖....但問題在這裏:-(任何想法? – 2011-05-03 06:52:12
對不起,關於該問題。我會研究另一種解決方案。你使用的是什麼版本的Android?可能與http://code.google.com/p/android/issues/detail?id=8489 – 2011-05-03 09:31:51
有關嗎?你是對的! !!!!!! – 2011-05-03 09:54:17