这是我的程序的工作方式:
1)从服务器显示图片
2)用户更改图片并将其上传到服务器
3)通过从服务器重新下载来显示图片
这是我从服务器获取图片的方式:
String src = "http://www.getyourpicture.com/mypicture.jpg"
HttpGet httpRequest = new HttpGet(URI.create(src) );
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse)httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();
Bitmap dp = BitmapFactory.decodeStream(instream);
//display dp from here...
Run Code Online (Sandbox Code Playgroud)
这里的问题是,每当我"重新下载"图像时,它仍会显示旧图片.为了确认我已经上传了图片,我已经检查了服务器上包含图片的文件夹,甚至在浏览器上访问了该链接.两种方法都表明图片确实已上传.所以我已经缩小了Android可能拥有一个不会"刷新"图像链接的http缓存管理器的可能性.
所以,如果我的问题的答案是"是",我如何强制应用程序不使用缓存?
如果答案是"不",那么我忽略了什么?
我正在尝试使用自己的自定义字体实现自定义textview.
有没有办法在做Super.onDraw()之前设置字体?
以便将常用字体替换为我想要使用的自定义字体.
就像是:
protected void onDraw(Canvas canvas)
{
Typeface font1 = Typeface.createFromAsset(context.getAssets(), "fonts/myfonts.ttf");
this.setTypeface(font1);
this.setTextSize(18);
super.onDraw(canvas);
}
Run Code Online (Sandbox Code Playgroud)
我知道上面的代码不起作用.
或者我别无选择,只能使用drawText()来做到这一点?
我成功地将联系人插入到地址簿中,我需要在我的应用程序中保存联系人的参考.我认为保存引用的最佳方法是获取RawContacts ID本身.
有没有办法让我在插入新联系人后立即从地址簿中取回ID?或者我是否必须获取所有记录并将其与我的数据进行比较以获取RawContacts ID?
我使用此代码执行插入操作:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME, null)
.withValue(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_DISABLED)
.build());
Run Code Online (Sandbox Code Playgroud)
我感谢任何输入,无论是变通方法还是API.谢谢!