我正在从事 Flutter 项目。更新 Android Studio 的版本后,当我单击设备管理器打开我的设备时,它不显示。我不知道我该怎么办?
第一张图片是 gif 图像来解释我的意思。
我放置第二张图片来显示当前版本(Bumblebee)。
查看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
我正在使用新的支持库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) 我决定使用来自 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) 我想知道何时ContextCompact
在应用程序中使用类.基本上它用于何时使用它?我读过开发者网站,它说ContextCompact
是"帮助访问Context中的功能".但这条线意味着什么?
android android-studio android-gradle-plugin android-studio-3.1
我使用以下行更改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?
谢谢。
将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) 我想升级 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) 在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
,Fuel
或Gson
包含这些值: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 ×10
androidx ×2
kotlin ×2
android-11 ×1
encrypted-shared-preference ×1
flutter ×1
gson ×1
listadapter ×1
security ×1