我是Android開發新手。解決Uri在壞位圖上失敗Uri
請幫我解決以下問題。我得到錯誤「的System.out - resolveuri失敗的壞位URI」上logcat的時候我嘗試使用功能來更新窗口小部件,
remoteViews.setImageViewUri(R.id.clockview, buildUpdate("CURRENTTIME", c));
awm.updateAppWidget(awID, remoteViews);
我附上我的代碼: -
public Uri buildUpdate(String time, Context context) {
date = new Date();
sec = (float) date.getSeconds();
min = (float) date.getMinutes();
hour = (float) date.getHours() + min/60.0f;
bitmap = Bitmap.createBitmap(200, 200, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint p = new Paint();
p.setAntiAlias(true);
p.setColor(0xFFFF0000);
p.setStrokeWidth(2);
canvas.drawLine(
x,
y,
(float) (x + (r - 15)
* Math.cos(Math
.toRadians((hour/12.0f * 360.0f) - 90f))),
(float) (y + (r - 10)
* Math.sin(Math
.toRadians((hour/12.0f * 360.0f) - 90f))), p);
...
...
OutputStream outStream = null;
File file = new File("data/clockbitmap.PNG");
try {
outStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
}
catch(Exception e)
{}
uri = Uri.parse(file.getAbsolutePath());
Log.d("File","filename "+file);
Log.d("here", "Does this exist? " + String.valueOf
(file.exists()));
Log.d("here",uri.getPath());
return uri;
}
請幫助我解決這個問題。 :(
。順便說一句,buildUpdate()不是一個好的方法名稱.... –