小编Sud*_*hat的帖子

SSL会话未在Android WebView中重用

我一直在Android webview上尝试SSL会话重用.我们注意到,如果连续请求在~5秒内发生,则会重新使用ssl会话.在服务器(nginx)中我们设置了ssl_session_timeout 10m 意义,10分钟,保持活动是30秒.

好像Android webview控件在5秒后销毁session-id.

我们如何重用ssl会话至少30秒?

ssl android android-webview

20
推荐指数
1
解决办法
887
查看次数

Android HttpURLConnection抛出EOFException

这是最简单的问题.

我使用HttpUrlConnection对象通过代理创建到我的服务器的HTTPS连接.

我的代理关闭连接但我的代码仍尝试重用相同的连接.所以我得到了EOFException.

我该如何处理这类案件?

android httpurlconnection eofexception

15
推荐指数
3
解决办法
1万
查看次数

将应用程序提交到Android Market和Amazon Appstore

我已经签署了一份申请,并准备上市.但我想在Amazon Appstore和Android Market上同步发布它.我有几个问题,我无法在任何地方找到正确的答案.

  1. 我支付25美元在Android市场上创建我的帐户后,该帐户需要多长时间才能生效?
  2. 我知道没有审核流程.但是可以上传我的.apk文件而不是发布它吗?

现在关于亚马逊appstore -

  1. 创建帐户后,我的帐户需要多长时间才能生效?
  2. 申请审核流程需要多长时间?
  3. 申请审核申请上线后需要多长时间?
  4. 我可以上传apk,在我发布之前检查并等待吗?

android amazon-appstore google-play

8
推荐指数
1
解决办法
2717
查看次数

如何创建轮播ViewPager?

我想做的只是Android中的水平旋转木马.

如果我有3个屏幕AB和C,那么我希望我的ViewPager允许我像A < - > B,B < - > C,C < - > A一样移动.

GTalk for Android的对话可以像这样切换.三星的主屏幕和应用程序屏幕可以像这样切换.

AB和C是片段,我正在使用扩展FragmentPagerAdapter的适配器.所有片段都将包含webview.

这里和这里看过这里,但似乎没有人做我想做的事.

谁能引导我朝着正确的方向前进?

android android-viewpager

7
推荐指数
1
解决办法
6623
查看次数

getHttpResponseCode()在android 2.2中返回-1

在我的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)

https android httpurlconnection

7
推荐指数
1
解决办法
556
查看次数

CONNECT的意外响应代码:400

我的一些用户在尝试连接时会遇到很多这样的异常.

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)

android httpurlconnection

6
推荐指数
1
解决办法
1928
查看次数

Content Provider从Web服务器获取结果?

我想创建一个内容提供程序,它将从Web服务器中获取结果.就像我发送一些帖子参数到我的网络服务器,它返回我一些JSON响应,我必须解析并在Android的快速搜索框中显示它.

我已经查看了SearchableDictionary,但他们似乎没有连接到服务器来获得结果.我在网上搜索但没有适当的例子.

我该怎么做?

android android-searchmanager

5
推荐指数
1
解决办法
6252
查看次数

java.lang.OutOfMemoryError:位图大小超过ListView中的VM预算和延迟加载图像

我有一个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(). …

android listview bitmap out-of-memory android-listview

5
推荐指数
1
解决办法
1244
查看次数

在"首选项行"中添加一个按钮

我想在"设置"屏幕中显示一个按钮.这里已经提出这个确切的问题.但遗憾的是没有答案.:(

在此输入图像描述

为了达到这个目的,我创建了一个这样的自定义首选项 -

  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 android-preferences

5
推荐指数
1
解决办法
3234
查看次数

我们应该为Android L Material主题设计吗?

我刚开始为Android L Material主题设计我的应用程序.我知道我们必须首先检查我们现有的应用程序是否与ART,新的WebView以及所有这些都能正常工作,但更进一步我希望我的应用程序在Android L正式发布时准备好发布.但是我发现文档很少,而且我无法找到我所遇到的一些问题的答案 -

  1. 材料主题本身是否适用于旧版Android?

  2. 现在公开可用的Android L SDK是否足以开始使用它构建应用程序?我发现了一些关于堆栈溢出的帖子,其中普通人已经说要推迟Android L发布.

  3. 设计规范中提到了一些内容,但没有相关文档.例如,"工具栏"正在根据Google IO 2014 App的来源替换"ActionBar" .但是为什么在Android L入门页面中没有提到它?它是否会通过支持库向后兼容旧版本?

  4. 有关如何实现此页面中提到的扩展应用栏的示例代码?

android material-design android-5.0-lollipop

5
推荐指数
1
解决办法
630
查看次数

textview中文本顶部的额外空间?

我已经定义了这样的布局 -

`

<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"使它看起来像我想要的.但这是正确的做法吗?

android relativelayout android-layout

3
推荐指数
1
解决办法
3228
查看次数