小编Coo*_*ind的帖子

为什么设备管理器打不开?

我正在从事 Flutter 项目。更新 Android Studio 的版本后,当我单击设备管理器打开我的设备时,它不显示。我不知道我该怎么办?

第一张图片是 gif 图像来解释我的意思。

在此输入图像描述

我放置第二张图片来显示当前版本(Bumblebee)。

在此输入图像描述

android android-studio flutter

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

Intent.resolveActivity 在 API 30 中返回 null

查看intent.resolveActivity != null 但启动 Intent 会引发 ActivityNotFound 异常,我在打开浏览器或具有深度链接的应用程序时写道:

private fun openUrl(url: String) {
    val intent = Intent().apply {
        action = Intent.ACTION_VIEW
        data = Uri.parse(url)
//        setDataAndType(Uri.parse(url), "text/html")
//        component = ComponentName("com.android.browser", "com.android.browser.BrowserActivity")
//        flags = Intent.FLAG_ACTIVITY_CLEAR_TOP + Intent.FLAG_GRANT_READ_URI_PERMISSION
    }
    val activityInfo = intent.resolveActivityInfo(packageManager, intent.flags)
    if (activityInfo?.exported == true) {
        startActivity(intent)
    } else {
        Toast.makeText(
            this,
            "No application can handle the link",
            Toast.LENGTH_SHORT
        ).show()
    }
}
Run Code Online (Sandbox Code Playgroud)

它不起作用。在 API 30 模拟器中找不到浏览器,而一个常见的解决方案有效:

private fun openUrl(url: String) {
    val intent …
Run Code Online (Sandbox Code Playgroud)

android android-manifest android-intent activitynotfoundexception android-11

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

ListAdapter不会更新reyclerview中的项目

我正在使用新的支持库ListAdapter.这是我的适配器代码

class ArtistsAdapter : ListAdapter<Artist, ArtistsAdapter.ViewHolder>(ArtistsDiff()) {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(parent.inflate(R.layout.item_artist))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(getItem(position))
    }

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        fun bind(artist: Artist) {
            itemView.artistDetails.text = artist.artistAlbums
                    .plus(" Albums")
                    .plus(" \u2022 ")
                    .plus(artist.artistTracks)
                    .plus(" Tracks")
            itemView.artistName.text = artist.artistCover
            itemView.artistCoverImage.loadURL(artist.artistCover)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在更新适配器

musicViewModel.getAllArtists().observe(this, Observer {
            it?.let {
                artistAdapter.submitList(it)
            }
        })
Run Code Online (Sandbox Code Playgroud)

我的差异类

class ArtistsDiff : DiffUtil.ItemCallback<Artist>() {
    override fun areItemsTheSame(oldItem: Artist?, newItem: Artist?): Boolean { …
Run Code Online (Sandbox Code Playgroud)

android listadapter kotlin

46
推荐指数
10
解决办法
9914
查看次数

AndroidX 安全 EncryptedSharedPreferences v1.1.0 /w API 21 问题

我决定使用来自 AndroidX 安全库的新 EncryptedSharedPreferences。由于该应用程序支持 API 21 及更高版本,我决定试用这个新的 v1.1.0-alpha02 版本,因为它支持 API 21+

因此,我成功实现了 API 23+,但对于不支持 Android KeyStore 的旧版本,我无法正确实现,并且没有确切的说明应该如何创建主密钥以使其以某种方式工作.

初始化 SharedPrefs 的代码:

EncryptedSharedPreferences.create(
        "prefs_name",
        createMasterKey(),
        App.appContext,
        EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
        EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
    )
Run Code Online (Sandbox Code Playgroud)

使用此功能创建主密钥

   private fun createMasterKey(): String {
        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
        } else {
            val alias = "my_alias"
            val start: Calendar = GregorianCalendar()
            val end: Calendar = GregorianCalendar()
            end.add(Calendar.YEAR, 30)

            val spec = KeyPairGeneratorSpec.Builder(App.appContext)
                .setAlias(alias)
                .setSubject(X500Principal("CN=$alias"))
                .setSerialNumber(BigInteger.valueOf(abs(alias.hashCode()).toLong()))
                .setStartDate(start.time).setEndDate(end.time)
                .build()

            val kpGenerator: KeyPairGenerator = KeyPairGenerator.getInstance(
                "RSA",
                "AndroidKeyStore"
            )
            kpGenerator.initialize(spec)
            val kp: KeyPair …
Run Code Online (Sandbox Code Playgroud)

security android androidx encrypted-shared-preference

21
推荐指数
4
解决办法
4471
查看次数

何时使用ContextCompat类

我想知道何时ContextCompact在应用程序中使用类.基本上它用于何时使用它?我读过开发者网站,它说ContextCompact是"帮助访问Context中的功能".但这条线意味着什么?

android

17
推荐指数
2
解决办法
8021
查看次数

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

setColorFilter在API29上已弃用

我使用以下行更改VectorDrawable的颜色:

mydrawable.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP)

尽管现在已不推荐使用,但效果很好。该文档建议我使用:

mydrawable.getBackground().setColorFilter(new BlendModeColorFilter(color, PorterDuff.Mode.SRC_ATOP))

虽然,BlendModeColorFilter仅在API29上可用。在检查了不赞成使用的方法的源之后,我意识到它调用了:

new PorterDuffColorFilter()

因此,我继续使用:

mydrawable.getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP))

着色工作。这是不推荐使用的方法的正确替代方法,还是我必须在API29上使用BlendModeColorFilter?

谢谢。

android

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

'setConfigSettings(FirebaseRemoteConfigSettings!):单位已弃用

将Firebase库升级到

implementation "com.google.firebase:firebase-messaging:18.0.0"
implementation 'com.google.firebase:firebase-config:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
Run Code Online (Sandbox Code Playgroud)

并同步Gradle,我得到警告:

'setConfigSettings(FirebaseRemoteConfigSettings!): Unit' is deprecated. Deprecated in Java
'setDeveloperModeEnabled(Boolean): FirebaseRemoteConfigSettings.Builder!' is deprecated. Deprecated in Java
Run Code Online (Sandbox Code Playgroud)

在这些行中:

//Setting Developer Mode enabled to fast retrieve the values
firebaseRemoteConfig.setConfigSettings(
    FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(BuildConfig.DEBUG)
        .build())
Run Code Online (Sandbox Code Playgroud)

android firebase-remote-config

12
推荐指数
2
解决办法
1997
查看次数

使用 groupid com.android.support 和 androidx.* 的依赖无法组合但找到了 IdeMavenCoordinates

我想升级 Google 图书馆:

build.gradle(应用程序):

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin_version}"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
    // Here an error appears.
    implementation "com.android.support:appcompat-v7:${supportLibraryVersion}"
    implementation "com.android.support:support-v4:${supportLibraryVersion}"
    implementation "com.android.support:design:${supportLibraryVersion}"
    implementation "com.android.support:support-vector-drawable:${supportLibraryVersion}"
    implementation "com.android.support:recyclerview-v7:${supportLibraryVersion}"
    implementation "com.android.support:appcompat-v7:${supportLibraryVersion}"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation "com.android.support:support-compat:${supportLibraryVersion}"

    // These libraries are updated.

    // Google Maps.
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'

    implementation "com.google.firebase:firebase-messaging:19.0.1"
    implementation "com.google.android.gms:play-services-base:17.0.0"

    // Firebase.
    implementation 'com.google.firebase:firebase-config:18.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.0'

    // Multidex.
    implementation 'com.android.support:multidex:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)

build.gradle(项目):

buildscript {
    ext.compile_sdk_version = 29
    ext.min_sdk_version = 16
    ext.target_sdk_version = 29
    ext.kotlin_version = '1.3.40'
    ext.supportLibraryVersion = …
Run Code Online (Sandbox Code Playgroud)

android androidx

12
推荐指数
0
解决办法
7747
查看次数

为什么Kotlin数据类在Gson的非可空字段中可以有空值?

在Kotlin你可以创建一个data class:

data class CountriesResponse(
    val count: Int,
    val countries: List<Country>,
    val error: String)
Run Code Online (Sandbox Code Playgroud)

然后您可以使用它来解析JSON,例如"{n:10}".在这种情况下,你将有一个对象val countries: CountriesResponse,从收到的Retrofit,FuelGson包含这些值:count = 0, countries = null, error = null.

Kotlin + Gson中 - 如何在数据类为null时获取emptyList,您可以看到另一个示例.

当您稍后尝试使用时countries,您将在此处获得异常val size = countries.countries.size::"kotlin.TypeCastException:null不能转换为非null类型kotlin.Int".如果您编写代码并?在访问这些字段时使用,Android Studio将突出显示?.并警告:Unnecessary safe call on a non-null receiver of type List<Country>.

那么,我们应该?在数据类中使用吗?为什么应用程序null在运行时设置为不可为空的变量?

android nullpointerexception gson kotlin

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