小编Shu*_*udy的帖子

如何获取onActivityresult中的图片路径(Intent数据为null)

我必须启动相机,当用户完成图片时,我必须将其拍摄并在视图中显示.

看看http://developer.android.com/guide/topics/media/camera.html我做了:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bLaunchCamera = (Button) findViewById(R.id.launchCamera);
        bLaunchCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "lanzando camara");

                //create intent to launch camera
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                imageUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); //create a file to save the image
                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); //set the image file name

                //start camera
                startActivityForResult(intent, CAMERA_REQUEST);
            }
        });

/**
     * Create a File Uri for saving image (can be sued to save video to)
     **/
    private Uri getOutputMediaFileUri(int …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-camera-intent

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

尝试部署Firebase函数时出现ESLint错误

我尝试部署fireabase示例,但是当我尝试部署它时,CLI会启动一个错误:

[码]

const functions = require('firebase-functions'); //to activate firebase functions

const admin = require('firebase-admin'); //to active firebase database permissions

admin.initializeApp(functions.config().firebase);

exports.addMessage = functions.https.onRequest((req, res) => {
// [END addMessageTrigger]
  // Grab the text parameter.
  const original = req.query.text;
  // [START adminSdkPush]
  // Push the new message into the Realtime Database using the Firebase Admin SDK.
  admin.database().ref('/messages').push({original: original}).then(snapshot => {
    // Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
    res.redirect(303, snapshot.ref);
  });
  // …
Run Code Online (Sandbox Code Playgroud)

javascript firebase eslint google-cloud-functions firebase-cli

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

以编程方式更改Chip Widget样式不起作用-Android

我正在用Chips做一份清单。我希望可以选择这种芯片,因此,请看https://material.io/develop/android/components/chip/,我可以找到一个“选择芯片”。

由于需要动态创建和添加,因此必须配置特定的颜色,颜色波纹,...

所以我要配置的是:

val chip = Chip(context, null, R.style.CustomChipChoice)
            chip.isClickable = true
            chip.isCheckable = true
            chip.isCheckedIconVisible=false
            chip.height = ScreenUtils.dpToPx(40)
            chip.chipCornerRadius = (ScreenUtils.dpToPx(20)).toFloat()
            chip.chipStrokeWidth = (ScreenUtils.dpToPx(2)).toFloat()
            chip.setTextAppearanceResource(R.style.ChipTextStyle)
            return chip
Run Code Online (Sandbox Code Playgroud)

我尝试的R.style.CustomChipChoice是:

CustomChipChoice样式

<style name="CustomChipChoice" parent="@style/Widget.MaterialComponents.Chip.Choice">
        <item name="chipBackgroundColor">@color/background_color_chip_state_list</item>
        <item name="chipStrokeColor">@color/background_color_chip_state_list</item>
        <item name="rippleColor">@color/topic_social_pressed</item>
</style>
Run Code Online (Sandbox Code Playgroud)

background_color_chip_state_list

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/topic_social_selected" android:state_checked="true" />
    <item android:color="@color/topic_social_pressed" android:state_pressed="true" />
    <item android:color="@color/topic_unselected_background" />
</selector>
Run Code Online (Sandbox Code Playgroud)

stroke_color_chip_state_list

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

如您所见,我将芯片制作为可点击且可检查的(隐藏不需要的选中图标)。

但是当我测试它时,没有设置颜色。芯片看起来只是默认的颜色(灰度)

这种自定义样式可以在哪里应用或如何应用?

PS:

我进行了快速测试,以查看我的CustomStyle是否格式错误/等。

我通过xml添加了一个视图,并且运行良好。

<android.support.design.chip.Chip
                android:id="@+id/test" …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-chips material-components material-components-android

7
推荐指数
3
解决办法
1262
查看次数

Android Studio Error JUNIT4 !!! 预期JUnit版本3.8或更高版本:

我正在做Android项目(在Android Studio中),里面有一个纯Java的小SDK.

所以我想要的是从JUnit4进行测试.

我以这种方式配置了Gradlle文件:

apply plugin: 'android'

android {
    compileSdkVersion "Google Inc.:Google APIs:19"
    buildToolsVersion "19.0.1"

    lintOptions{
        checkReleaseBuilds false
    }

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 28
        versionName "4.0.5"
    }

    signingConfigs {
        debug {
        }

        release {
        }

    }

    buildTypes {

        debug{
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable true
            buildConfigField "boolean", "LOG_ENABLED", "true"
            signingConfig signingConfigs.debug
        }

        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable false
            buildConfigField "boolean", "LOG_ENABLED", "false"
            signingConfig signingConfigs.release
        }
    }

    productFlavors{
        develFlavor{
        }

        testFlavor{
        }

        trainingFlavor{
        } …
Run Code Online (Sandbox Code Playgroud)

android junit4 android-studio build.gradle android-gradle-plugin

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

使用Kotlin处理错误RXJava Android

嗨,我是RxJava和Kotlin的新手,我放弃了一些关于它的概念.

我有这样的"api":

interface VehiclesService {
    @GET("/vehicles/")
    fun getVehicles(): Single<List<Vehicle>>
}
Run Code Online (Sandbox Code Playgroud)

然后我创建了改造客户端等.像这样:

var retrofit = RetrofitClient().getInstance()
vehiclesAPI = retrofit!!.create(VehiclesService ::class.java)
Run Code Online (Sandbox Code Playgroud)

最后我打电话:

private fun fetchData() {
        compositeDisposable.add(vehiclesAPI .getVehicles()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe { vehicles -> displayData(vehicles) }
        )
    }
Run Code Online (Sandbox Code Playgroud)

这是我尝试启动时出现错误的地方:

The exception was not handled due to missing onError handler in the subscribe() method call
Run Code Online (Sandbox Code Playgroud)

我知道错误是非常明确的.所以我知道缺少什么,但我不知道的是如何处理这个错误.

我尝试添加:.doOnError { error -> Log.d("MainClass",error.message) }但仍然告诉相同的错误消息.

android kotlin retrofit2 rx-java2

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

从Java中的KML文件中提取坐标

我正在尝试用Java解析Kml文件.因为我需要获取地标的坐标,在java中生成一个poligon并使用它.

但我的问题是,我正在使用JAK这个库解析它,我无法提取我想要的信息.(我在官方页面中读到了"帮助",但我没有找到任何帮助解决我的问题)

我正在尝试这样做:

final Kml kml = Kml.unmarshal(new File("C:/Users/A556520/Documents/Proyectos/GeoFencing/res/labasa.kml"));
final Document document = (Document)kml.getFeature();       
List<Feature> listafeatures = document.getFeature();        
Run Code Online (Sandbox Code Playgroud)

但在这一点上我不知道如何提取坐标.

我试图解析的文件就是这个:la basa

java parsing kml coordinates jak

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

在AndroidKeystore中保存和检索KeyPair

我需要生成一个RSA 2018密钥对,然后将其保存并恢复(如果存在)。

此刻,我有:

SecureRandom random = new SecureRandom();
RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(keySize, RSAKeyGenParameterSpec.F4);
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "SC");
generator.initialize(spec, random);
return generator.generateKeyPair();
Run Code Online (Sandbox Code Playgroud)

效果很好,但是现在我尝试从Android Keystore中保存并获取它,但是我没有实现。我尝试过:

String alias = "TESTINGKEY";
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(null);
        if (!keyStore.containsAlias(alias)) {
            SecureRandom random = new SecureRandom();
            RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(keySize, RSAKeyGenParameterSpec.F4);
            KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "SC");
            generator.initialize(spec, random);
            return generator.generateKeyPair();
        } else {
            Key key = keyStore.getKey(alias, null);
            if (key instanceof PrivateKey) {
                Certificate cert = keyStore.getCertificate(alias);
                return new KeyPair(cert.getPublicKey(), (PrivateKey) key);
            } …
Run Code Online (Sandbox Code Playgroud)

android rsa android-keystore

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

当错误设置为 null 时 TextInputLayout 留下空白

我的用户界面有一点问题。

我用来com.google.android.material.textfield.TextInputLayout进行登录,并以简单的方式设置错误。

情况:

我有空TextInputLayout,没有错误可显示。

在此输入图像描述

然后当用户开始写入时,我设置TextInputLayout.error = "Error Messge". 因为这里一切都是正确的。

在此输入图像描述

但是当用户清理 时TextInputLayout,我清理了将其设置为 null 的错误:TextInputLayout.error = null

在此输入图像描述

这就是问题所在。清除错误后,显示错误的空间不会消失。它留下了我不需要的空白。

有什么办法可以去除吗?我看不到任何方法来“清除”错误并删除此空间。

PS:算法我尝试设置为“空白”而不是 null --> TextInputLayout.error = "",但不起作用。

user-interface android kotlin

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

ViewBinding 未在自定义视图中显示视图

我正在尝试在添加到项目中的新模块中使用 ViewBinding,该模块将包含项目中的所有 CustomView。

目前,该模块是唯一实现视图绑定的模块。主模块(应用程序)使用 kotlin 合成。

最初我有这两个自定义视图:

Pre - ViewBinding --> 这是有效的。我可以在附加的片段中看到它)

自定义视图 1:

import kotlinx.android.synthetic.main.layout_horizontal_filter.view.*

class HorizontalFiltersView @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {

    private val adapter: HorizontalFilterAdapter
    private val decoration: HorizontalFilterDecorator

    init {
        LayoutInflater.from(context).inflate(R.layout.layout_horizontal_filter, this, true)
        this.adapter = HorizontalFilterAdapter(context)
        this.decoration = HorizontalFilterDecorator(context, 16)

        recycler.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
        recycler.adapter = this.adapter
        recycler.addItemDecoration(this.decoration)
        recycler.setHasFixedSize(true)
    }

    fun setFilters(filtersList: MutableList<HorizontalFilter>) {
        this.adapter.refresh(filtersList)
    }

}
Run Code Online (Sandbox Code Playgroud)

自定义视图2:

import kotlinx.android.synthetic.main.item_horizontal_filter.view.*
class HorizontalFilterItem …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view kotlin android-viewbinding

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

如何在 git (bitucket/sourcetree) 中重命名和移动分支

我们有一个名为 的分支ABC-Awsome_Branch,它“保存”在 中feature/3.0.0,所以它看起来像:feature/3.0.0/ABC-Awsome_Branch

但是分支是用错误的名称创建的,甚至不在正确的文件夹中。所以正确的路径/名称必须是这样的:feature/2.5.0/DEF-Awsome_Branch. 现在这个分支包含一些提交等...

是否可以“移动”并将分支重命名为正确的名称和路径?

我们使用 Bitbucket 和 sourcetree。

git

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