Tag: 安卓

如何引用Anko DSL中的其他视图?

我在我的Android项目中使用Anko,但我不知道如何引用我在DSL中创建的子视图,当引用的视图不在我参考它的同一级别。 以下代码工作: alert { customView { val input = textInputLayout { editText { hint = "Name" textColor =resources.getColor(R.color.highlight) } } positiveButton("OK") { "${input.editText.text}" } } }.show() 但下面的代码不起作用: alert { customView { val vertical = verticalLayout { textView { text = "Edit device name" textColor = resources.getColor(R.color.highlight) textSize = 24F } val input = textInputLayout { […]

获取权限拒绝例外

我在我的应用程序中有一个活动,允许用户从设备中逐一选择几个文件,我正在使用这样的意图: Intent intent = new Intent(); intent.setType("*/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, getString(R.string.select_attachments_activity_chooser_label)), SELECT_PICTURE); 这工作得很好,我得到的Uri的文件选择,他们看起来像这样: content://com.android.providers.media.documents/document/image%3A42555 那么,如果该文件是一个图像,我解码它: InputStream streamForDecodeBitmap = MyApp.getContext().getContentResolver().openInputStream(uri); Bitmap bitmap = BitmapFactory.decodeStream(streamForDecodeBitmap, null, options); 当用户点击一个按钮时,我通过intent将Uris列表传递给另一个活动,并且在这个活动中,在一个AsyncTask中,我使用base64对文件进行编码以便通过网络发送: InputStream is = MyApp.getContext().getContentResolver().openInputStream(uri); byte[] inputData = getBytes(is); is.close(); return Base64.encodeToString(inputData, Base64.DEFAULT); 问题是,当我打开inputStream,有时它的工作,但大部分时间我得到这个异常: E/AndroidRuntime(22270): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{42858fe0 22270:co.uk.manifesto.freeagentapp/u0a246} (pid=22270, uid=10246) requires android.permission.MANAGE_DOCUMENTS or […]

我怎样才能代表与Android室的多对多关系?

我怎样才能代表与房间的多对多关系? 例如我有“客人”和“保留”。 预订可以有许多客人和一位客人可以成为许多预订的一部分。 这是我的实体定义: @Entity data class Reservation( @PrimaryKey val id: Long, val table: String, val guests: List<Guest> ) @Entity data class Guest( @PrimaryKey val id: Long, val name: String, val email: String ) 在查看文档时,我遇到了@Relation 。 我发现它真的很混乱。 根据这个我想创建一个POJO并在那里添加关系。 所以,以我的例子,我做了以下 data class ReservationForGuest( @Embedded val reservation: Reservation, @Relation( parentColumn = "reservation.id", entityColumn = "id", entity = […]

错误:com.app.android.dagger.component.AppComponent(unscoped)可能不引用作用域绑定:

嗨我在我的android应用程序中使用dagger2。 我有提供ConnectivityManager AppModule和AppComponent。 AppModule.kt @Module class AppModule(private val application: Application) { @Provides @Singleton fun providesApplication(): Application = application @Provides @Singleton fun providesConnectivityManager(): ConnectivityManager = application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager } AppComponent.kt @Component(modules = arrayOf(AppModule::class)) interface AppComponent { fun inject(app: ApprApplication) } 在我的应用程序类中,我正在注入ConnectivityManager但是当我正在进行日志记录时,它的值为null。 class AppApplication : Application(), AnkoLogger { private val appComponent: AppComponent by lazy { DaggerAppComponent.builder().appModule(AppModule(this)).build() } […]

动画淡入淡出

使用这个代码,我只是淡入淡出,我寻找关于添加淡出。 我添加另一个名为“淡出”的XML,但我不能将其集成到我的代码中。 ImageView imageView= (ImageView)findViewById(R.id.imageView); Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein); imageView.startAnimation(fadeInAnimation ); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { imageView.startAnimation(fadeInAnimation); XML <?xml version="1.0" encoding="UTF-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="Your Duration(in milisecond)" android:repeatCount="infinite"/> </set>

使用Anko访问活动的视图

我知道我可以使用Anko的id属性来识别视图: class MainActivityUI : AnkoComponent<MainActivity> { override fun createView(ui: AnkoContext<MainActivity>) = with(ui) { frameLayout { textView { id = R.id.text } } } } 然后使用find()函数(或使用Kotlin Android扩展)在Activity获取它: class MainActivity : AppCompatActivity() { private val textView by lazy { find<TextView>(R.id.text) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MainActivityUI().setContentView(this) textView.text = "Hello World" } } 但我觉得我失去了一些东西; README中唯一提到find函数或Kotlin Android扩展的地方在标题为支持现有代码的部分: […]

FirebaseDatabase根引用在事务中为空

我正在尝试执行Firebase事务,以便更改我的Firebase数据库中两个位置的值,但交易处理的MutableData为空。 是否禁止在数据库根上运行事务? 我是否必须运行多个链接的交易才能完成此操作? val ref = FirebaseDatabase .getInstance() .getReference("/") ref.runTransaction(object : Transaction.Handler { override fun doTransaction(currentData: MutableData): Transaction.Result { println( currentData) // { key = <none>, value = null } if (currentData.value == null){ return Transaction.success(currentData) } currentData.child("users/{userID}/someVal/").setValue(X) currentData.child("items/{itemID}/someVal/").setValue(Y) return Transaction.success(currentData) } })

如果有更新,我们是否需要下载完整的Android Studio?

您好我有Android Studio 3.0 Beta 7,我想更新到新版本的Android Studio 3.1金丝雀。 它显示了这个对话框。 下载按钮带我到这个页面https://developer.android.com/studio/preview/index.html?utm_source=android-studio并建议下载完整的IDE。 不应该下载更新的补丁? 或者这只对我而言

如何将主键作为Room Persistence lib的自动增量

我正在创建一个Entity(Room Persistence lib)类的食物,在这里我想把foodId作为自动增量。 @Entity class Food(var foodName: String, var foodDesc: String, var protein: Double, var carbs: Double, var fat: Double) { @PrimaryKey var foodId: Int = 0 var calories: Double = 0.toDouble() } 我如何设置foodId自动增量字段?

复制Googlemap上的APK protobuf.meta文件复制商业用途

我按照这里的指示来实现Googlemap for business(选项2:将SDK导入为库模块): https://developers.google.com/maps/premium/android-get-started当我尝试运行应用程序,它返回给我这个错误: * What went wrong: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK protobuf.meta File1: /Users/name/.android/build-cache/f333e5a1ed5f958c1e7d100de7935a31efd81cd6/output/jars/classes.jar File2: /Users/name/Documents/name/project-name/googlemapssdkm4b_lib/build/intermediates/bundles/default/classes.jar 这是我的gradle文件: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: 'test-environment.gradle' apply plugin: 'io.fabric' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' repositories { maven { url 'https://maven.fabric.io/public' } maven { url […]