小编Com*_*are的帖子

在Froyo上ListView随机IndexOutOfBoundsException

我有一个有大量下载的应用程序,我收到了很多这个错误:

 16783         AndroidRuntime  E  java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
 16783         AndroidRuntime  E    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
 16783         AndroidRuntime  E    at java.util.ArrayList.get(ArrayList.java:311)
 16783         AndroidRuntime  E    at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:16
                                  4)
 16783         AndroidRuntime  E    at android.widget.ListView.dispatchDrawWithExcessScroll_Default(ListView.java:3
                                  288)
 16783         AndroidRuntime  E    at android.widget.ListView.dispatchDraw(ListView.java:3029)
 16783         AndroidRuntime  E    at android.view.View.draw(View.java:6743)
 16783         AndroidRuntime  E    at android.widget.AbsListView.draw(AbsListView.java:2549)
 16783         AndroidRuntime  E    at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
 16783         AndroidRuntime  E    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
 16783         AndroidRuntime  E    at android.view.View.draw(View.java:6743)
 16783         AndroidRuntime  E    at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
 16783         AndroidRuntime  E    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
 16783         AndroidRuntime  E    at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
 16783         AndroidRuntime …
Run Code Online (Sandbox Code Playgroud)

java android listview indexoutofboundsexception commonsware-cwac

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

我们如何使用Android N网络安全配置获得自签名证书?

我试图测试N Developer Preview的网络安全配置功能的所有方面.我有大部分工作,但我被自签名证书场景困扰.

根据文档,Android N应该对PEM或DER文件感到满意,因为它适用于其他证书验证方案.但是,我不使用自签名证书,并且我尝试使用此工作继续运行到证书路径验证异常中.

为了测试,我thin用作服务器,在我的开发机器上运行,可以通过N模拟器访问.自签名证书适用于我的开发机器上的浏览器,如果我切换到运行thinsans SSL,应用程序可以很好地到达服务器.所以,这不是连接问题.

我使用本网站上的说明创建了自签名证书:

sudo openssl genrsa -out "/etc/[webserver]/ssl/example.key" 2048
sudo openssl req -new -key "/etc/[webserver]/ssl/example.key" \
                 -out "/etc/[webserver]/ssl/example.csr"
sudo openssl x509 -req -days 365 -in "/etc/[webserver]/ssl/example.csr" \
                  -signkey "/etc/[webserver]/ssl/example.key"  \
                  -out "/etc/[webserver]/ssl/example.crt"
Run Code Online (Sandbox Code Playgroud)

根据此Stack Overflow回答,该example.crt文件是PEM文件.在其他地方,我看到了创建"组合PEM"文件的说明.但是,我尝试了这两个,没有运气.

在网络安全配置方面的东西,我曾经尝试都<domain-config><debug-overrides>.后者看起来像:

<?xml version="1.0" encoding="utf-8"?>

<network-security-config>
  <debug-overrides>
    <trust-anchors>
      <certificates src="@raw/selfsigned"/>
    </trust-anchors>
  </debug-overrides>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

但是,在任何一种情况下我都会得到验证错误.

作为原始资源,我们究竟应该将PEM或DER文件作为原始资源投入使用?

ssl android android-7.0-nougat

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

Android Studio:使用AndroidAnnotations

所以我想尝试新的Android Studio并导入我的eclipse项目(我生成了一个gradle构建文件).工作得很好.

唯一似乎不起作用的库是AndroidAnnotations.我在File> Settings> Compiler> Annotation Processing下选择了androidannotations-2.7.jar文件.

作为生产源目录,我选择了"gen".但是不会生成像MainActivity_这样的生成文件.我错了什么?

android intellij-idea android-annotations android-studio

19
推荐指数
2
解决办法
2万
查看次数

自定义首选项,targetSdkVersion ="11":缺少缩进?

我有几个自定义DialogPreference实现,例如这个:

package apt.tutorial;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.TimePicker;

public class TimePreference extends DialogPreference {
    private int lastHour=0;
    private int lastMinute=0;
    private TimePicker picker=null;

    public static int getHour(String time) {
        String[] pieces=time.split(":");

        return(Integer.parseInt(pieces[0]));
    }

    public static int getMinute(String time) {
        String[] pieces=time.split(":");

        return(Integer.parseInt(pieces[1]));
    }

    public TimePreference(Context ctxt) {
        this(ctxt, null);
    }

    public TimePreference(Context ctxt, AttributeSet attrs) {
        this(ctxt, attrs, 0); …
Run Code Online (Sandbox Code Playgroud)

android android-preferences android-3.0-honeycomb

18
推荐指数
2
解决办法
4715
查看次数

更新WebView导航UI的推荐事件是什么?

WebView提供goBack()goForward()实现典型的后退按钮行为,可以绑定到按钮,操作栏项或任何其他:

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
      case R.id.back:
        if (webView.canGoBack()) {
          webView.goBack();
        }
        break;

      case R.id.fwd:
        if (webView.canGoForward()) {
          webView.goForward();
        }
        break;

      case R.id.reload:
        webView.reload();
        break;

      default:
        return(super.onOptionsItemSelected(item));
    }

    return(true);
  }
Run Code Online (Sandbox Code Playgroud)

WebView也有canGoBack()canGoForward(),告诉你,如果这些是给在当前的导航历史可行的方案WebView,如上文所示周围的卫兵goBack()goForward()电话.

从理论上讲,canGoBack()canGoForward()可用于启用或禁用按键,操作栏项目,或什么的.这将为您提供典型的浏览器UI,其中后退和前进按钮仅在用户具有实际效果时可用.

什么是不明显的时候,我们应该呼吁canGoBack()canGoForward()和启用/禁用这些按钮.应该是:

  • onPageStarted()在一个习俗WebViewClient
  • doUpdateVisitedHistory()在一个习俗WebViewClient
  • 在其他一些回调?
  • 这些的一些组合?
  • 每一秒左右纯粹在计时器上,因为我们没有可靠的回调来确定何时应该更新?

android android-webview

18
推荐指数
1
解决办法
343
查看次数

我们如何在Android库模块中继承测试类?

我有一个带有两个库模块的Android Studio项目:foo-modulebar-module.每个都实现一个库,foo-module定义一个策略接口,并bar-module依赖foo-module并实现这样的策略.foo-module有一个instrumentation tests(foo-module/src/androidTest/)来测试它的核心代码,使用存根策略实现,并且bar-module应该有自己的仪器测试.

AbstractTests在一个类中定义了foo-module/src/androidTest/大部分实际测试.我还有一个StubTests类,foo-module/src/androidTest/它扩展AbstractTests并实现了abstract完成测试用例的必要方法(提供了策略的实现等).一切都很好.

bar-module/src/androidTest/,我创建了一个BarStrategyTests专门用于镜像的类StubTests,但提供了实现的策略bar-module.但是,BarStrategyTests看不到AbstractTests,即使我compile project(':foo-module')在我的build.gradle文件中,并且主要(非测试)类bar-module可以在主要(非测试)类中正常工作foo-module.IOW,虽然project()依赖项处理常规代码,但它不处理androidTest/代码.我得到"错误:包com.commonsware.foo.test不存在".

我也尝试添加androidTestCompile project(':foo-module'),结果相同.

在模块之间共享仪器测试代码的方法是什么?

暂时,我可以克隆AbstractTests,但这不是一个很好的长期解决方案.

这个问题涵盖了普通Java的类似基础.有没有人在一个答案中尝试过这些选项并让它们用于Android仪器测试?第一个选项(将常用测试代码移动到另一个模块作为常规非测试代码)似乎是合理的,但我不知道其他两个是否适用于com.android.library插件而不是java插件.

android android-gradle-plugin

18
推荐指数
1
解决办法
1554
查看次数

Android许可样本返回代码3.这是什么意思?

我试过许可样品.它说"应用程序错误= 3".我在developer.android.com上找到了许可响应代码表,但是3号对应于上面的列表?那段代码是什么意思?

android android-lvl

17
推荐指数
1
解决办法
9249
查看次数

棒棒糖通知setVisibility()不起作用?

我正在尝试编写一个使用的演示setVisibility()来控制Android 5.0锁屏上显示的内容Notification.但是,似乎没有效果:

  • 默认设置VISIBILITY_PRIVATE仍然显示私有Notification,而不是公共对应

  • VISIBILITY_SECRET 通知仍会显示在锁定屏幕上

IOW,一切都表现得好像VISIBILITY_PUBLIC有效,至少当我测试运行Android 5.0图像的Nexus 7时,我们在Android 5.0发布后不久就给出了(构建LPX13D).所以我不知道问题是否与我的代码,此设备或Android中的错误有关.

我有两个版本的相同示例应用程序:

  • 一个使用NotificationCompatNotificationManagerCompat

  • 其他的用途NotificationNotificationManager使用minSdkVersion的21和targetSdkVersion21

(请注意,这些项目主要用于Android Studio; Eclipse用户可以导入项目,但可能需要进行少量修复,特别是对于support-v13第一个示例的库引用)

样本用于AlarmManager触发Notification工作,主要是因为您有机会返回锁定屏幕以查看结果.这是BroadcastReceiverAlarmManager(显示NotificationCompat版本)触发的:

/***
 Copyright (c) 2014 CommonsWare, LLC
 Licensed under the Apache License, Version 2.0 (the "License"); you may not
 use this file except in compliance with the License. You may …
Run Code Online (Sandbox Code Playgroud)

android android-notifications android-5.0-lollipop

17
推荐指数
1
解决办法
8186
查看次数

我们如何在启用Debug的Android 6.0设备上更轻松地切换MTP?

在Android 6.0中,MTP不再自动运行:

现在,通过USB端口的设备连接默认设置为仅充电模式.要通过USB连接访问设备及其内容,用户必须明确授予此类交互的权限.如果您的应用支持用户通过USB端口与设备进行交互,请考虑必须明确启用交互.

至少每次插入USB电缆时都需要重新授权MTP,并且可能比这更频繁(超时?).

启用USB调试后,我发现让MTP共享在设备上工作的唯一解决方案是:

  • 进入设置>开发人员选项
  • 向下滚动到"选择USB配置"
  • 该选项的值切换到任何东西,但 MTP,如"仅充电"(如果是在MTP现在)
  • 将该选项的值切换为MTP
  • 刷新您的MTP客户端(例如,在Ubuntu 15.04上,关闭并重新打开显示设备内容的窗口)

当您尝试在外部存储上使用设备的文件时,这会更加严重.

是否有一种命令行方式可以让MTP继续运行,而不是编写自动化上述过程的UIAutomator"测试"?或者,有没有其他方法可以让MTP在没有这种准备过程的情况下工作?

android android-6.0-marshmallow

17
推荐指数
1
解决办法
2801
查看次数

25.1.0 Android支持lib正在打破fab行为

我升级到最新的支持库版本,并且滚动FAB行为无效.向下滚动RecyclerView时,它会向下滚动,但是当再次向上滚动时则不会向下滚动.它保持隐藏.降级到25.0.1似乎缓解了这个问题.这里参考的是我用于此的代码.

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/drawer_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:animateLayoutChanges="true"
  android:fitsSystemWindows="true"
  tools:context=".mainhost.MainActivity"
  tools:openDrawer="start">

  <android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main_coordinator_layout_root_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".mainhost.MainActivity">

    <android.support.design.widget.AppBarLayout
      android:id="@+id/appbar_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme.AppBarOverlay">

      <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways|snap">

        <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:focusableInTouchMode="true"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

      </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <!-- Layout for content is here. This can be a RelativeLayout  -->

    <FrameLayout
      android:id="@+id/content_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginLeft="-3dp"
      android:layout_marginRight="-3dp"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context="com.globyworks.citykey.mainhost.MainActivity" />


    <android.support.design.widget.FloatingActionButton
      android:id="@+id/fab"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom|end"
      android:layout_margin="@dimen/fab_margin"
      app:layout_behavior="com.globyworks.citykey.helpers.ScrollingFABBehavior"
      android:src="@drawable/drawer_new_report_white" />

  </android.support.design.widget.CoordinatorLayout>


  <android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    app:menu="@menu/menu_drawer"> …
Run Code Online (Sandbox Code Playgroud)

android android-support-library floating-action-button

17
推荐指数
1
解决办法
1395
查看次数