我一直在Android webview上尝试SSL会话重用.我们注意到,如果连续请求在~5秒内发生,则会重新使用ssl会话.在服务器(nginx)中我们设置了ssl_session_timeout 10m
意义,10分钟,保持活动是30秒.
好像Android webview控件在5秒后销毁session-id.
我们如何重用ssl会话至少30秒?
这是最简单的问题.
我使用HttpUrlConnection对象通过代理创建到我的服务器的HTTPS连接.
我的代理关闭连接但我的代码仍尝试重用相同的连接.所以我得到了EOFException.
我该如何处理这类案件?
我已经签署了一份申请,并准备上市.但我想在Amazon Appstore和Android Market上同步发布它.我有几个问题,我无法在任何地方找到正确的答案.
现在关于亚马逊appstore -
我想做的只是Android中的水平旋转木马.
如果我有3个屏幕AB和C,那么我希望我的ViewPager允许我像A < - > B,B < - > C,C < - > A一样移动.
GTalk for Android的对话可以像这样切换.三星的主屏幕和应用程序屏幕可以像这样切换.
AB和C是片段,我正在使用扩展FragmentPagerAdapter的适配器.所有片段都将包含webview.
谁能引导我朝着正确的方向前进?
在我的Android应用程序中,我试图通过执行POST请求从服务器提取数据.
我正在使用HttpURLConnection
类来发出请求,因为Apache HttpClient
不再由android维护.
这就是我正在做的事情.
private boolean callWS() {
try {
// To avoid the bug in httpurlconnection prior froyo which
// causes the getInputStream to return headers along with response
if (Build.VERSION.SDK_INT < 8)
System.setProperty("http.keepAlive", "false");
mHttpResponseCode = 0;
mErrorMessage = "";
// Initialize connection
URL connectURL = new URL(mServerUrl);
HttpURLConnection conn = (HttpURLConnection) connectURL.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(true);
conn.setReadTimeout(30000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
// Set some headers
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Accept-Encoding", "deflate, gzip");
connection.setRequestProperty("Content-Length", mParameters.length() + "");
// Connect …
Run Code Online (Sandbox Code Playgroud) 我的一些用户在尝试连接时会遇到很多这样的异常.
java.io.IOException: Unexpected response code for CONNECT: 400
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeTunnel(HttpsURLConnectionImpl.java:509)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:463)
at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:442)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
Run Code Online (Sandbox Code Playgroud)
400意味着错误的请求但几秒钟后相同的请求成功.我仔细检查了请求,并没有任何问题.我也检查了服务器日志,看来请求甚至没有到达我们的服务器.
我正在使用简单HttpUrlConnection
的连接.
URL connectURL = new URL(url);
HttpURLConnection conn = (HttpURLConnection) connectURL.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(true);
conn.setReadTimeout(30000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Accept-Encoding", "deflate, gzip");
connection.setRequestProperty("Content-Length", postParameters.length() + "");
conn.connect();
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
writer.write(mRequestObj.getPostParameters());
writer.flush();
writer.close();
responseCode = conn.getResponseCode();
BufferedInputStream bis = null;
try {
bis = new BufferedInputStream(conn.getInputStream());
}
catch(IOException io) {
if(conn.getErrorStream() != …
Run Code Online (Sandbox Code Playgroud) 我想创建一个内容提供程序,它将从Web服务器中获取结果.就像我发送一些帖子参数到我的网络服务器,它返回我一些JSON响应,我必须解析并在Android的快速搜索框中显示它.
我已经查看了SearchableDictionary,但他们似乎没有连接到服务器来获得结果.我在网上搜索但没有适当的例子.
我该怎么做?
我有一个listview,可能无限滚动加载无限项.
列表视图中的每个项目都有一个或两个我懒得加载的图像.
一切都很好但是当我滚动很长时间它会在log cat中崩溃
08-07 15:26:25.231: E/AndroidRuntime(30979): FATAL EXCEPTION: Thread-60
08-07 15:26:25.231: E/AndroidRuntime(30979): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-07 15:26:25.231: E/AndroidRuntime(30979): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
08-07 15:26:25.231: E/AndroidRuntime(30979): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
08-07 15:26:25.231: E/AndroidRuntime(30979): at com.test.android.helper.LazyImageLoader.decodeFile(LazyImageLoader.java:171)
08-07 15:26:25.231: E/AndroidRuntime(30979): at com.test.android.helper.LazyImageLoader.getBitmap(LazyImageLoader.java:112)
08-07 15:26:25.231: E/AndroidRuntime(30979): at com.test.android.helper.LazyImageLoader.access$2(LazyImageLoader.java:106)
08-07 15:26:25.231: E/AndroidRuntime(30979): at com.test.android.helper.LazyImageLoader$ImageLoader.run(LazyImageLoader.java:197)
Run Code Online (Sandbox Code Playgroud)
在我的懒惰图像加载器中,我将位图存储在a中WeakHashMap
.垃圾收集器应该收集位图吗?
我懒惰的图像加载器就是这样的.
我displayImage()
从我的适配器调用url和imageview的引用
public void displayImage(String url, ImageView imageView, int defaultImageResourceId){
latestImageMetaData.put(imageView, url);
if(weakhashmapcache.containsKey(url)){
imageView.setImageBitmap(weakhashmapcache.get(url));
}
else{
enqueueImage(url, imageView, defaultImageResourceId);
imageView.setImageResource(defaultImageResourceId);
}
}
Run Code Online (Sandbox Code Playgroud)
所以如果我在缓存中找到图像,我会直接设置它,否则我会用函数对它进行排队enqueueImage()
. …
我想在"设置"屏幕中显示一个按钮.这里已经提出了这个确切的问题.但遗憾的是没有答案.:(
为了达到这个目的,我创建了一个这样的自定义首选项 -
public class CustomPreference extends Preference {
private LinearLayout mWidgetContainer;
private View mRowView;
public CustomPreference(Context context) {
super(context);
}
public CustomPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected View onCreateView(ViewGroup parent) {
LayoutInflater viewInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mRowView = viewInflater.inflate(R.layout.preferences_row_view, parent, false);
mWidgetContainer = (LinearLayout) mRowView.findViewById(android.R.id.widget_frame);
Button button = new Button(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
button.setLayoutParams(params);
button.setBackgroundResource(R.drawable.listview_row_bg);
button.setTextSize(14); …
Run Code Online (Sandbox Code Playgroud) 我刚开始为Android L Material主题设计我的应用程序.我知道我们必须首先检查我们现有的应用程序是否与ART,新的WebView以及所有这些都能正常工作,但更进一步我希望我的应用程序在Android L正式发布时准备好发布.但是我发现文档很少,而且我无法找到我所遇到的一些问题的答案 -
材料主题本身是否适用于旧版Android?
现在公开可用的Android L SDK是否足以开始使用它构建应用程序?我发现了一些关于堆栈溢出的帖子,其中普通人已经说要推迟Android L发布.
设计规范中提到了一些内容,但没有相关文档.例如,"工具栏"正在根据Google IO 2014 App的来源替换"ActionBar" .但是为什么在Android L入门页面中没有提到它?它是否会通过支持库向后兼容旧版本?
有关如何实现此页面中提到的扩展应用栏的示例代码?
我已经定义了这样的布局 -
`
<ImageView
android:id="@+id/first_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/square" />
<ImageView
android:id="@+id/second_big_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/first_icon"
android:scaleType="fitXY"
android:src="@drawable/square_big" />
<TextView
android:id="@+id/line1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_alignTop="@id/second_big_image"
android:layout_toRightOf="@+id/second_big_image"
android:text="AND Here is the text" />
Run Code Online (Sandbox Code Playgroud)
`
在屏幕上,我看到它是这样的.我不明白为什么文本顶部会有一些空间.即使我将它对齐到第二个图像的顶部,它仍然没有对齐.我该怎么做?
我已经尝试过android:alignParentTop="true"
也android:gravity="top"
.但似乎没有任何效果.可能这是android textview的行为,但我还是想摆脱那个空间.
设置android:layout_marginTop="-4dip"
使它看起来像我想要的.但这是正确的做法吗?