我有一个使用此权限的安全应用程序(App Locker):
android.permission.GET_TASKS
Run Code Online (Sandbox Code Playgroud)
在android Lollipop中,这个权限已被弃用,我希望我的应用程序在+21 API中运行.
谁能指导我怎么样?
Thnx :)
我想在Android Studio v1.0.0 rc2中将此库导入我的项目:
https://github.com/navasmdc/MaterialDesignLibrary
但有一个问题.当我将此库添加为模块时,会出现此错误:
错误:依赖项MyApplication.libraries:MaterialDesign:项目应用程序未指定解析为APK归档文件,不支持作为编译依赖项.文件:C:\ ADTBundle\StudioWorkspace\MyApplication\libraries\MaterialDesign\build\outputs\apk\MaterialDesign-release-unsigned.apk
什么是解决这个问题的分步指南?或者这个库的gradle依赖是什么?
我有一个扩展功能,用于为我的活动打开一个意图:
fun Activity.openIntent(action: String?, type: String?, uri: Uri?) {
Intent()
.apply {
action?.let { this.action = it }
uri?.let { this.data = it }
type?.let { this.type = it }
}
.also { intent ->
packageManager?.let {
if (intent.resolveActivity(it) != null)
startActivity(intent)
else
showToast(R.string.application_not_found)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的targetSdkVersion
是30。它给了我一个警告intent.resolveActivity(it)
:
调用此方法时,请考虑向清单添加查询声明。
那么我应该怎么做才能解决这个警告呢?
我正在开发一个具有干净架构原则的应用程序。我有一个domain
模块,它是一个Java/Kotlin
模块,它没有 android 依赖项,还有一个domainImpl
模块,它是一个模块,Android
并且依赖于和module. 这是模块内部的示例:local
remote
domain
Repository
domain
interface MovieRepository {
fun getMovie(id: Long): Flow<Movie>
}
Run Code Online (Sandbox Code Playgroud)
下面的代码是它在domainImpl
模块内部的实现:
class MovieRepositoryImpl(
private val movieApi: MovieApi
) : MovieRepository {
override fun getMovie(id: Long): Flow<Movie> = flow {
emit(movieApi.getMovie(id))
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下一切正常。但现在我正在尝试添加Android Paging 3
我的分页。所以我必须向MovieRepository
接口添加一个方法,例如:
fun getMovies(): Flow<PagingData<Movie>>
Run Code Online (Sandbox Code Playgroud)
但在此之前,我必须将分页库添加到我的domain
模块中,但不幸的是它是一个Android
库,我找不到它的核心依赖项。那么我能做什么呢?domain
因此我是否必须将模块更改为 android 模块?或者还有其他解决方法吗?
android kotlin clean-architecture android-jetpack android-paging
我试图实现Android Paging library
与ViewModel
和Kotlin Coroutines
我有一个ViewModel
实现CoroutineScope
. 这取决于Repository
:
class MovieListViewModel(
private val movieRepository: MovieRepository
) : ViewModel(), CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.IO
private lateinit var _movies: LiveData<PagedList<MovieBrief>>
val movies: LiveData<PagedList<MovieBrief>>
get() = _movies
init {
launch {
_movies = LivePagedListBuilder(movieRepository.getMovies(), DATABASE_PER_PAGE)
.setBoundaryCallback(movieRepository.movieBoundaryCallback)
.build()
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Repository
. 我注入BoundaryCallback
与Kodein
Dependecy注射器。
class MovieRepositoryImpl(
private val movieDao: MovieDao, …
Run Code Online (Sandbox Code Playgroud) android kotlin android-viewmodel kotlinx.coroutines android-paging
我正在设计库中使用 android 的新 BottomSheet。问题是我在片段中使用它,导致它出现在屏幕顶部而不是出现在底部。
这是我的活动 xml:
<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="ir.aidinsoft.quicktaxi.MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/tlbr_acMain"
android:elevation="5dp"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.CoordinatorLayout
android:id="@+id/crdl_acMain"
android:layout_below="@+id/tlbr_acMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nscv_acMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This Layout Is Replacement Layout For Fragment -->
<RelativeLayout
android:id="@+id/frml_acMain"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的 xml 片段:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ir.aidinsoft.quicktaxi.MyFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<io.codetail.widget.RevealFrameLayout
android:id="@+id/rvfl_frTaxi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible">
<fragment
android:id="@+id/frag_frTaxi_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</io.codetail.widget.RevealFrameLayout>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/facb_frTaxi_request"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- My Bottom …
Run Code Online (Sandbox Code Playgroud) android android-fragments android-support-library android-design-library bottom-sheet
我在 android 中使用 DataBinding 并且我有一个自定义视图:CarouselView
我为此编写了一个绑定适配器:
@BindingAdapter("onClick")
fun setOnClick(carouselView: CarouselView, onClick: (position: Int) -> Unit) {
carouselView.setImageClickListener { position ->
onClick.run(position)
}
}
Run Code Online (Sandbox Code Playgroud)
在 xml 中:
<com.synnapps.carouselview.CarouselView
android:id="@+id/carouselView"
...
app:onClick="@{(p) -> vm.onAdsClicked(p)}"/>
Run Code Online (Sandbox Code Playgroud)
但它不编译。所以我在 Stackoverflow 中看到了这个答案。但我的问题是我不能使用 Runnable 而不是 kotlin hoc 函数,因为我需要传递一个参数来运行。
我该如何解决?
android higher-order-functions kotlin android-databinding android-binding-adapter
我正在开发一个android应用程序。我在根项目中有一个“ dependencies.gradle”文件:
ext {
// Android
kotlinVersion = '1.2.51'
gradleVersion = '3.1.3'
}
Run Code Online (Sandbox Code Playgroud)
问题是我可以在App的build.gradle文件中使用此属性,但不能在root的build.gradle文件中使用,这给了我这个错误:
Could not get unknown property 'kotlinVersion' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Run Code Online (Sandbox Code Playgroud)
这是我的“ Root Build Gradle”:
apply from: 'dependencies.gradle'
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
这是我的“ App Build Gradle”:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig …
Run Code Online (Sandbox Code Playgroud) 我有一个中间件,用于检查请求中的特定标头参数并基于该参数发回响应。
但是我遇到的问题是我不希望这个中间件总是在我的控制器中的一个函数上运行。如果函数中的条件为真,我希望中间件运行(例如:存储函数)。
我怎样才能做到这一点?
我正在尝试BottomNavigationView
使用此库将其添加到布局中:
implementation 'com.google.android.material:material:1.0.0'
Run Code Online (Sandbox Code Playgroud)
这是我的布局:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".home.HomeActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:itemBackground="?colorPrimary"
app:itemIconTint="@drawable/bottom_navigation_selector"
app:itemTextColor="@drawable/bottom_navigation_selector"
app:layout_insetEdge="bottom"
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
app:menu="@menu/bottom_navigation" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_model"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:fabSize="normal"
app:layout_anchor="@id/bottom_navigation"
app:layout_anchorGravity="end"
app:srcCompat="@drawable/ic_add_white_24dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
它在模拟器上运行,但是当我想在真实设备上启动应用程序时,出现以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rightechco.rayanpairpanel/com.rightechco.rayanpairpanel.home.HomeActivity}: android.view.InflateException: Binary XML file line #23: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2489)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2551)
at android.app.ActivityThread.access$1000(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1432)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194) …
Run Code Online (Sandbox Code Playgroud) 我最近看到谷歌有一个很棒的数据分页库。
在这个 Google IO 中:
Android Jetpack:使用 RecyclerView 和 Paging 管理无限列表(Google I/O '18)
他们解释了如何Data + Network DataSource
从数据库中创建和获取数据Single Source of Truth
,当数据库没有数据时,它会通过 .NET 从网络请求更多数据BoundaryCallback
。
因此,假设我在服务器上有一个电影列表。客户端(Android 用户)可以按受欢迎程度、标题、发布日期等对它们进行排序。
因此,如果用户第一次按标题对电影进行排序,一切都会很好,因为数据库中没有数据,并且将从服务器请求数据以按标题对它们进行排序并将其发送回来。但是,如果用户尝试按受欢迎程度对它们进行排序怎么办?由于数据库中存在大量电影(例如 50 部电影),它会按受欢迎程度对少量电影进行排序,然后尝试从服务器获取数据,这不是一个好的体验。
我无法为每种排序类型制作表格,因为这不是一个好的做法。那么我该如何克服这个问题呢?
非常感谢
sorting android android-architecture-components android-paging
android ×10
kotlin ×4
gradle ×2
android-11 ×1
android-architecture-components ×1
bottom-sheet ×1
conditional ×1
deprecated ×1
laravel ×1
laravel-5 ×1
middleware ×1
permissions ×1
php ×1
sorting ×1