小编cap*_*wag的帖子

覆盖库使用的 maxSdkVersion

这是场景。我的应用程序 (A) 正在使用库 (B)。

我的应用程序 (A) 正在使用 READ_PHONE_STATE 权限,它在 manifest.xml 中声明为

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Run Code Online (Sandbox Code Playgroud)

而库 (B) 也使用相同的权限 READ_PHONE_STATE,但 maxSdkVersion 设置为 22。

<uses-permission
    android:name="android.permission.READ_PHONE_STATE"
    android:maxSdkVersion="22"/>
Run Code Online (Sandbox Code Playgroud)

所以现在的问题是,当应用程序构建时,在最终的 _merged_manifest_ 中,我设置了maxSdkVersion="22",因此我当前运行牛轧糖的设备无法请求此特定权限。

目前我找到了一个解决方案来覆盖我的应用程序(A)manifest.xml中的这个值

<uses-permission
    tools:replace="android:maxSdkVersion"
    android:name="android.permission.READ_PHONE_STATE"
    android:maxSdkVersion="28"/>
Run Code Online (Sandbox Code Playgroud)

但这需要我每次更新应用程序中的 sdk 版本时都更新maxSdkVersion (A)。

所以我的问题是

  1. 有没有办法使用我的manifest.xml中的一些命名空间来忽略库(B)设置的maxSdkVersion,例如tools:ignore
  2. 在build.gradle中自动将maxSdkVersion设置为最新的sdkVersion,无需手动更改

android android-manifest build.gradle

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

如何在表格标题下方添加边框底部或水平线

我想在th下面创建一条水平线。以下是我想要实现的目标

表格需要下划线

我已经创建了表格,并且全部使用以下 html 标记

<table>
      <tr>
        <th>Table</th>
        <th>&#37; of Time Index Used</th>
        <th>Rows in Table</th>
      </tr>
      <tr>
        <td>tweet_groups</td>
        <td>67</td>
        <td>20,488</td>
      </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

那么如何添加水平线呢?

html css

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

是否有一种惯用的方法来处理 if else 分支中的空值?

我在想是否有一种更简洁的方式来表达这段代码。

return if (response.isSuccessful()) {
    response.body
else null
Run Code Online (Sandbox Code Playgroud)

我在这里指的是else null部分。Kotlin 中几乎类似的语句是

return response?.let {
    it.body
} ?: null
Run Code Online (Sandbox Code Playgroud)

但是在上面的情况下,我们可以在没有该?: null部分的情况下编写相同的代码,编译器会自动分配空值。那么为什么 Kotlin 的 if 语句需要nullelse 部分呢?

return if (response.isSuccessful()) {
    response.body
}
Run Code Online (Sandbox Code Playgroud)

android if-statement kotlin

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

使用JavaMail API如何从GMail获取前20封邮件然后接下来的20封邮件?

我是JavaMail API的新手,目前正在从Tutorialspoint学习.现在我可以使用以下代码从我的邮件中获取所有电子邮件

import java.util.Properties;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Store;

public class CheckingMails {

public static void check(String host, String storeType, String user,
  String password) 
{
  try {

  Properties properties = new Properties();

  properties.put("mail.pop3.host", host);
  properties.put("mail.pop3.port", "995");
  properties.put("mail.pop3.starttls.enable", "true");
  Session emailSession = Session.getDefaultInstance(properties);

  Store store = emailSession.getStore("pop3s");

  store.connect(host, user, password);

  Folder emailFolder = store.getFolder("INBOX");
  emailFolder.open(Folder.READ_ONLY);

  Message[] messages = emailFolder.getMessages();
  System.out.println("messages.length---" + messages.length);

  for (int i = 0, n = messages.length; i < n; i++) …
Run Code Online (Sandbox Code Playgroud)

java email jakarta-mail

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

如何获取父节点的值作为字符串?

Firebase图片

所以在上面的数据结构中,我想获得价值Aprilia Caponord 1200(在图中标出).我有Firebase引用Aprilia(根节点),我可以获取所有键/值对数据.

这是我的代码

@override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChild()) {
    Map<?, ?> value = (Map<?, ?>) child.getValue();
    String bike_price = value.get("price").toString();
    String image_url = value.get("image_url").toString();
    }
}
Run Code Online (Sandbox Code Playgroud)

很明显,我可以获得具有键/值关系的子节点的所有值.但我无法专门获取父节点的名称.那么如何以String格式获取父节点的值?

如果我打印child.getValue().toString(),我得到JSON值,但我对解析JSON不感兴趣.是否有任何特定的方法来获取父节点值?

{Aprilia Caponord 1200={image_url=____________, price=18.35}.. }
Run Code Online (Sandbox Code Playgroud)

java android firebase firebase-realtime-database

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

如何在BehaviourSubject中设置默认值

可能是一个菜鸟问题.如何为BehaviourSubject设置默认值.

我有一个有两个不同值的枚举

enum class WidgetState {
    HIDDEN,
    VISIBLE
}
Run Code Online (Sandbox Code Playgroud)

并且是发出状态的行为主体

val widgetStateEmitter: BehaviorSubject<WidgetState> = BehaviorSubject.create()
Run Code Online (Sandbox Code Playgroud)

写入视图逻辑时,我的发射器开始发射.但是默认情况下它是HIDDEN.如何将默认值设置为WidgetState.HIDDEN到我的发射器widgetStateEmitter

android kotlin rx-java

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

如何在RecyclerView中获取CardView的宽度

所以这是我的RecyclerView的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/bikename_recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是由RecyclerView的适配器充气的布局.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/bikenames_cardview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:orientation="vertical" >

            <ImageView
                android:id="@+id/bikenames_imageview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/bikenames_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    </android.support.v7.widget.CardView>

 </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

所以在这里我需要在我的Activity或RecyclerView适配器中找到CardView(@ id/bikenames_cardview)的宽度.我也写了RecyclerView适配器.

适配器代码

public class BikeNamesAdapter extends RecyclerView.Adapter<BikeNamesViewHolder> {

    BikeNames bikeNames;
    Context context;

    public BikeNamesAdapter(BikeNames bikeNames) {
        this.bikeNames = bikeNames;
    }

    @Override
    public int getItemCount() {
        return bikeNames.getLength();
    }

    @Override
    public BikeNamesViewHolder onCreateViewHolder(ViewGroup …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-recyclerview

0
推荐指数
1
解决办法
4372
查看次数