小编Vis*_*kar的帖子

ACCESS_COARSE_LOCATION权限在Android上提供了单元格塔精度

我正在使用requestLocationUpdates()函数进行一些测试FusedLocationApi.我使用的是PRIORITY_BALANCED_POWER_ACCURACY.城市街区精度对我来说很好.

当我请求ACCESS_FINE_LOCATION权限时,我得到一个100米的精度,这是很好的GPS关闭.由于我不需要GPS精度但是城市街区精度,我只想请求ACCESS_COARSE_LOCATION许可.但是当我申请ACCESS_COARSE_LOCATION许可时,我得到了2公里的精度.似乎设备不再使用Wifi权限,只有单元塔精度.

如何使用ACCESS_COARSE_LOCATION权限获得更好的精度?

注意:GPS我的测试设备已禁用.

permissions gps android android-location fusedlocationproviderapi

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

在顶部更新时,RecyclerView崩溃

我有一个RecyclerView在我的应用程序一切正常工作我在滚动时最后一项是可见的我在底部添加更多的项目,它工作正常.现在问题是我有一个Handler每5秒运行一次并检查Web服务是否有任何更新,如果有任何更新我只是将数据加载到它的顶部,RecyclerView当我还没有滚动时工作正常的RecyclerView,但是当我滚动在它和Handler被称为(因为它是每5秒钟之后调用),则在更新RecyclerView顶部上的应用程序崩溃.

更新顶部的功能:

public void addOnTop(ArrayList<ItemPOJO> topItemList) {
    for (int i = topItemList.size() - 1; i >= 0; i--) {
        itemList.add(0, topItemList.get(i));
    }
    notifyItemRangeInserted(0, topItemList.size());
    notifyDataSetChanged();
}
Run Code Online (Sandbox Code Playgroud)

这是错误日志:

java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{419b8760 position=5 id=-1, oldPos=-1, pLpos:-1 no parent}
        at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4214)
        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4345)
        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4326)
        at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1955)
        at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1364)
        at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1327)
        at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1155)
        at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1012)
        at android.support.v7.widget.RecyclerView.scrollByInternal(RecyclerView.java:1363)
        at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2227)
        at android.view.View.dispatchTouchEvent(View.java:7190)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2274)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2009)
        at …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview recyclerview-layout

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

使用PrintWriter通过Socket连接将PDF文件打印到打印机

我必须使用具有特定IP地址的打印机打印pdf文件.我能够打印特定的文本,但我想打印文件或HTML解析文本.

我的代码:

try {
    Socket sock = new Socket("192.168.0.131", 9100);
    PrintWriter oStream = new PrintWriter(sock.getOutputStream());
    oStream.println("HI,test from Android Device");
    oStream.println("\n\n\n");
    oStream.close();
    sock.close();
} catch (UnknownHostException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

还请说明投票的原因

编辑

很多人都建议PDL,但如何将pdf转换为PDL?

java sockets android

9
推荐指数
1
解决办法
2109
查看次数

使用iText库将html转换为pdf时未应用hr的内联CSS

我正在使用Itext库为android将html转换为pdf,这是正常工作但在某些事情它没有正确解析.我想创建一个红色的虚线分隔符,但它总是给我一个深灰色的实线分隔符.

我的html标签是

<hr noshade style="border: 0; width:100%;border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: red">
Run Code Online (Sandbox Code Playgroud)

我的转换代码

        Document document = new Document(PageSize.A4);

        //this sets the margin to the created pdf
        document.setMargins(35, 35, 150, 100);

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(fileWithinMyDir));
        if (isPrescription) {
            HeaderFooterPageEvent event = new HeaderFooterPageEvent();
            writer.setPageEvent(event);
        } else {
            CertificateFooterPageEvent event = new CertificateFooterPageEvent();
            writer.setPageEvent(event);
        }
        document.open();
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        htmlContext.setImageProvider(new AbstractImageProvider() {
            public String getImageRootPath() {

                Uri uri = Uri.parse("file:///android_asset/");

                return uri.toString();
            }
        });


        CSSResolver cssResolver = …
Run Code Online (Sandbox Code Playgroud)

html android itext xmlworker

9
推荐指数
1
解决办法
1288
查看次数

在Android设计库TabLayout中选择时更改图标和标题颜色

我正在使用TabLayout设计库我想要实现的是

我想实现

我已经尝试了很多教程,我可以通过自定义选项卡来实现它,但是当选择选项卡时会出现限制我想要更改文本颜色以及图标的图像,这是通过引用无法实现的到目前为止我读过的任何教程.到目前为止,我已经尝试过这个了FragmentStatePagerAdapter

public View getTabView(int position) {
    View tab = LayoutInflater.from(mContext).inflate(R.layout.tabbar_view, null);
    TextView tabText = (TextView) tab.findViewById(R.id.tabText);
    ImageView tabImage = (ImageView) tab.findViewById(R.id.tabImage);
    tabText.setText(mFragmentTitles.get(position));
    tabImage.setBackgroundResource(mFragmentIcons.get(position));
    if (position == 0) {
        tab.setSelected(true);
    }
    return tab;
}
Run Code Online (Sandbox Code Playgroud)

android android-tablayout

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

在按钮的android选择器中使用SVG

我正在使用 svg 作为图标,因为ImageView它可以使用app:srcCompat但当我想将它Buttons用作选择器时,应用程序崩溃,资源未找到异常,对于 api 低于 21 的设备

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_enabled" android:state_enabled="true" />
    <item android:drawable="@drawable/button_disabled" android:state_enabled="false" />
</selector>
Run Code Online (Sandbox Code Playgroud)

其中 button_enabled 和 button_disabled 都是 svg

svg android

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

Google PlacePicker在使用resultCode 2启动后立即关闭

在我的项目PlacePicker工作正常,但今天突然在使用resultCode 2启动后立即关闭.

这是logcat输出

07-06 16:06:36.596   1023-20519/? W/Places? e.a:638: gLocReplyElement
unsuccessful status: 1

07-06 16:06:36.596   1023-20519/? W/Places? e.a:665: gPlaceQueryResult
unsuccessful responseCode: 26

07-06 16:06:36.596  21086-21708/? E/PlacePicker?
PLACES_API_QUOTA_FAILED
Run Code Online (Sandbox Code Playgroud)

任何的想法?PLACES_API_QUOTA_FAILED错误代码是什么意思?

android google-places-api

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

Android Realm默认数据库清除

如何清除android中的默认域数据库?我尝试了下面的代码,但无法解析方法deleteRealmFile.

方法1:

try {
   Realm.deleteRealmFile(context);
  //Realm file has been deleted.

} catch (Exception ex){
   ex.printStackTrace();
  //No Realm file to remove.
}
Run Code Online (Sandbox Code Playgroud)

我试图删除使用配置.

方法2:

try {
     Realm.deleteRealm(realm.getConfiguration());
     //Realm file has been deleted.
} catch (Exception ex){
     ex.printStackTrace();
     //No Realm file to remove.
}
Run Code Online (Sandbox Code Playgroud)

但是给出了错误:

java.lang.IllegalStateException: It's not allowed to delete the file associated with an open Realm. Remember to close() all the instances of the Realm before deleting its file.
Run Code Online (Sandbox Code Playgroud)

android realm

5
推荐指数
2
解决办法
7502
查看次数

单击重叠的UI元素

我有Fragment一半占了一半Activity.在它背后,一个ListView.问题是,当用户点击其上的任何地方Fragment与行上的一行重叠时ListView,行会被点击并onClick调用它的方法.

一种解决方法是给一个onClickLinearLayout了在Fragment布局XML文件中,就像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.karimnseir.instabeat.IBMenuFragment"
    android:background="@color/material_blue_grey_950"
    android:onClick="doNothing">
Run Code Online (Sandbox Code Playgroud)

我不认为这是非常优雅的,因为我必须doNothing为每个Activity使用它的人添加一个方法Fragment

如果没有办法阻止onClicks在元素后面被调用Fragment,那么如何在onClick没有虚拟方法的情况下仍然给它一个null 呢?

谢谢

android android-fragments

4
推荐指数
1
解决办法
373
查看次数

如何在android-saripaar中重新检查字段?

我使用android-saripaar库.

我可以使用查看EditText输入数据正确性的所有字段validate().如果我EditText在正确的数据中填写错误,只要我再次调用a,错误就不会消失validate().

如何仅在确定输入文本后检查有效性EditText并从中删除错误?

谢谢.

java android android-edittext saripaar

4
推荐指数
1
解决办法
1366
查看次数