Questions tagged «android»

Android是Google的移动操作系统,用于对数字设备(智能手机,平板电脑,汽车,电视,Wear,Glass和IoT)进行编程或开发。对于与Android相关的主题,请使用特定于Android的标签,例如android-intent,android-activity,android-adapter等。对于与开发或编程无关但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。

7
页面必须填满整个ViewPager2(使用match_parent)
我有一个项目布局,在其中显示图像,产品名称和产品图像。我必须使用约束布局以1:1.5的比例显示图像。但是,当我加载小图像时,下面的文本不显示。 以下是我的XML项目代码:- <?xml version="1.0" encoding="utf-8"?> <layout 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"> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/coordinatorLayoutCartRoot" android:layout_width="match_parent" android:layout_height="match_parent"> <com.jackandphantom.circularimageview.RoundedImage android:id="@+id/imageViewSlider" android:layout_width="match_parent" android:layout_height="0dp" android:scaleType="centerCrop" app:layout_constraintBottom_toTopOf="@id/tvTitle" app:layout_constraintDimensionRatio="WH,1:1.4" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:rounded_radius="0" tools:src="@tools:sample/avatars" /> <TextView android:id="@+id/tvTitle" android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="center" android:padding="4dp" android:text="Fitted crew neck sweater" android:textColor="@color/colorBlack" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/imageViewSlider" /> <TextView android:id="@+id/tvPrice" android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="center" android:padding="4dp" android:text="$34.00" android:textColor="@color/colorBlack" android:textStyle="bold" …


3
Android RecognitionListener:onResults被调用两次
我有一个使用Kotlin编写的使用RecognitionListener的项目。语音到文本功能始终是成功的,从未出现任何问题。 从上周开始,它的onResult函数开始被调用两次。该项目未做任何更改。我测试了该项目的旧版本(从几个月前开始),这些版本都存在相同的问题。 有三种不同的情况: 小文本(1到8个单词)和SpeechRecognizer自动停止-> onResult()调用了两次; 大文本(9个单词或更多)和SpeechRecognizer自动停止->正常行为(onResult()调用一次); 手动调用任何文本大小和SpeechRecognizer stopListening()函数(从代码)->正常行为。 这是VoiceRecognition语音转文字类代码: class VoiceRecognition(private val activity: Activity, language: String = "pt_BR") : RecognitionListener { private val AudioLogTag = "AudioInput" var voiceRecognitionIntentHandler: VoiceRecognitionIntentHandler? = null var voiceRecognitionOnResultListener: VoiceRecognitionOnResultListener? = null //Must have this var voiceRecognitionLayoutChanger: VoiceRecognitionLayoutChanger? = null var isListening = false private val …

1
在某些装有Android 10的设备上,使用MediaRecorder.AudioSource.VOICE_COMMUNICATION录制的音频为空
我正在使用以下代码在应用程序中录制语音消息的音频。 MediaRecorder audioRecorder = new MediaRecorder(); audioRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC); audioRecorder.setOutputFile(audioRecordingFile); audioRecorder.prepare(); audioRecorder.start(); 使用MediaRecorder.AudioSource.VOICE_COMMUNICATION而不是MediaRecorder.AudioSource.MIC)在录制经过预处理的纯音频方面非常有帮助。 但是,最近我发现在一些最近更新到Android 10的设备上报告了一些录制文件为空的问题。应该注意的是,并非所有Android 10设备都存在这些问题,只有少数设备(例如诺基亚6.1和小米A2。 没有错误或异常,只有空的音频输出文件。 如果我使用MediaRecorder.AudioSource.MIC),则不会出现此问题。 我发现以下与Android 10和VOICE_COMMUNICATION 有关的信息。Android 10发行版包含以下与VOICE_COMMUNICATION进行捕获的要求。 基于此,我使用以下代码检查了AcousticEchoCanceler,AutomaticGainControl和NoiseSuppressor的可用性。 AcousticEchoCanceler.isAvailable() AutomaticGainControl.isAvailable() NoiseSuppressor.isAvailable() 并在带有Android 10的Mi A2和OnePlus 6上找到了相同的结果。这两种设备均显示AcousticEchoCanceler和NoiseSuppressor为可用,而AutomaticGainControl为不可用。 由于并非所有Android设备上都存在此问题,因此我不想再使用MediaRecorder.AudioSource.MIC)。同时,没有错误,异常或区分因素告诉我何时退回到MediaRecorder.AudioSource.MIC)上。 更新: 在Mi A2上关闭Google Assistant时,此问题已解决。这可能是指针:https : //developer.android.com/guide/topics/media/sharing-audio-input 任何有关此的帮助表示赞赏。

3
Google的MediaNotificationService中有大量RemoteServiceExceptions
在过去的大约24小时内,我们发现Google的内部发生了数千次崩溃MediaNotificationService: Fatal Exception: android.app.RemoteServiceException Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{f9a4deb u0 <our package name>/com.google.android.gms.cast.framework.media.MediaNotificationService} android.app.ActivityThread$H.handleMessage (ActivityThread.java:1855) android.os.Handler.dispatchMessage (Handler.java:106) android.os.Looper.loop (Looper.java:214) android.app.ActivityThread.main (ActivityThread.java:6986) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1445) 创建自己的前台服务时,我也遇到过类似的问题,但是由于这在演员库中,我们无法对其进行控制。 Chromecast接收器由第三方处理。我们正在使用: api "com.google.android.gms:play-services-cast:17.0.0" api "com.google.android.gms:play-services-cast-framework:17.0.0" 潜在线索: 它正在OnePlus,华为,三星,谷歌上发生,似乎每个制造商(和操作系统级别)的数量都与其市场份额相关。 崩溃发生在不同设备的不同线路上(例如,上面是Galaxy S9,S8崩溃是在1872行),因此不在Crashlytics上分组。在我看来,这是操作系统/ Google Play服务级别的问题。 崩溃同时发生在应用程序的所有活动版本中。 坠机事故数月以来一直没有发生,但在周末突然飙升,并且没有放缓的迹象。

1
剪贴板API调用抛出NotAllowedError而不调用onPermissionRequest()
这赏金已经结束。这个问题的答案有资格获得+50声望奖励。赏金宽限期在13小时内结束。 cyqsimon希望引起更多对此问题的关注。 我有一个带有按钮的简单页面,当按下按钮时,该页面使用Async Clipboard API写入剪贴板。 <body> <button type="button" onclick="testClipboard();"> Test Clipboard </button> </body> function testClipboard() { navigator.clipboard.writeText("Clipboard API Test").then( v => alert("Success"), e => alert("Fail\n" + e)); } 这适用于Chrome和Firefox,台式机和移动设备。但是,在Android Webview上,它引发以下错误: NotAllowError: Write permission denied. 我认为我需要重写WebChromeClient.onPermissionRequest()以授予许可,但是奇怪的onPermissionRequest()是似乎没有被调用,并且仍然抛出相同的错误。 public class WebChromeController extends WebChromeClient { @Override public void onPermissionRequest(PermissionRequest request) { Log.d("myTag", "Permission request"); …

2
如何使用Dagger 2在ViewPager中注入相同片段的ViewModel
我正在尝试将Dagger 2添加到我的项目中。我能够为片段注入ViewModels(AndroidX体系结构组件)。 我有一个ViewPager,它具有2个相同片段的实例(每个选项卡只有一个小的更改),并且在每个选项卡中,我正在观察一个LiveData以获取有关数据更改的更新(从API)。 问题在于,当api响应出现并更新时LiveData,当前可见片段中的相同数据将发送给所有选项卡中的观察者。(我认为这可能是因为的范围ViewModel)。 这就是我观察数据的方式: override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) activityViewModel.expenseList.observe(this, Observer { swipeToRefreshLayout.isRefreshing = false viewAdapter.setData(it) }) .... } 我正在使用此类提供ViewModel: class ViewModelProviderFactory @Inject constructor(creators: MutableMap<Class<out ViewModel?>?, Provider<ViewModel?>?>?) : ViewModelProvider.Factory { private val creators: MutableMap<Class<out ViewModel?>?, Provider<ViewModel?>?>? = creators override fun <T : ViewModel?> create(modelClass: Class<T>): T { var …

3
保持滚动位置仅在不靠近消息div底部时有效
我正在尝试模仿其他移动聊天应用程序,在这些应用程序中,当您选择send-message文本框并打开虚拟键盘时,最底部的消息仍在显示中。似乎没有办法用CSS来做到这一点,所以JavaScript resize(显然是找出何时打开和关闭键盘的唯一方法)是事件和手动滚动以进行救援。 有人提供了这个解决方案,我发现了这个解决方案,两者似乎都可以工作。 除了一种情况。出于某种原因,如果您位于MOBILE_KEYBOARD_HEIGHT消息div底部(在我的情况下为250像素)以内,则当您关闭移动键盘时,会发生一些奇怪的情况。使用前一种解决方案,它会滚动到底部。使用后一种解决方案时,它会MOBILE_KEYBOARD_HEIGHT从底部向上滚动像素。 如果滚动到该高度以上,则上面提供的两个解决方案都可以正常工作。只有当您接近底部时,他们才会遇到这个小问题。 我以为可能只是我的程序导致了一些奇怪的流浪代码,但不,我什至重现了一个小提琴,它确实有这个问题。我很抱歉使调试变得如此困难,但是如果您在手机上访问https://jsfiddle.net/t596hy8d/6/show(显示后缀提供全屏模式),您应该可以看到同样的行为。 如果您向上滚动足够,打开和关闭键盘将保持该位置。但是,如果将键盘关闭在MOBILE_KEYBOARD_HEIGHT底部像素以内,则会发现它滚动到底部。 是什么原因造成的? 这里的代码复制: window.onload = function(e){ document.querySelector(".messages").scrollTop = 10000; bottomScroller(document.querySelector(".messages")); } function bottomScroller(scroller) { let scrollBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight; scroller.addEventListener('scroll', () => { scrollBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight; }); window.addEventListener('resize', () => { scroller.scrollTop = scroller.scrollHeight - scrollBottom - …

3
React Native的Android App Bundle:您上传的APK或Android App Bundle的某些文件的签名信息无效或缺失
我正在尝试首次将应用发布到Google Play商店。我已选择使用Google Play签名。我知道我正在使用正确的密钥对Android App Bundle进行签名,因为当我使用其他密钥进行上传时,控制台会告诉我使用具有特定SHA1标识符的其他密钥进行上传。但是,当我使用正确的密钥上传时,出现以下错误: 您上传的APK或Android应用程序捆绑包的某些文件包含无效或缺少签名信息。 我正在使用Android Studio构建应用程序,如下所示:生成>生成签名包/ APK> Android应用程序包>选择我的密钥库并输入密码>版本>完成 该应用程序是使用独立的Expo / ExpoKit构建的React Native应用程序。上载到Apple App Store正常,我在Play Store中只有问题。我想念什么? 更新1:我现在已从Google Play完全删除了该应用,并创建了一个新应用。难道不选择在谷歌播放签署这个时间和上传签名的APK。还是一样的错误。 更新2:尝试使用全新的密钥库和密钥。还是一样。 如果这在某种程度上很重要,那么这里是项目设置的概述: 这是android/app/build.gradle: buildscript { repositories { google() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'io.fabric.tools:gradle:1.26.1' } } apply plugin: 'com.android.application' apply plugin: 'io.fabric' apply plugin: 'devicefarm' repositories { …

2
E / eglCodecCommon:GoldfishAddressSpaceHostMemoryAllocator:device_type = 5,ret = -1的ioctl_ping失败
每次我在AndroidStudio上测试我的APP时,都会收到此错误消息。 我的APP正常运行,但是我对该错误的含义有些困惑/好奇。 即使当我用google搜索时,GoldfishAddressSpaceHostMemoryAllocator我也会找到4个不相关的结果(它们将其命名为Class,但并未尝试对其进行修复)。 此错误消息是什么意思?

2
在Multi-Sim设备中检测来电的目标SimCard
我读了很多文章并尝试了许多解决方案,但是所有文章的共同点是它们都已过时,至少我找不到能在较新版本的Android上运行的解决方案。 发布1,结果: intent.getExtras().getInt("simId", -1)总是返回-1 发布2,结果:intent.getExtras().getInt("slot", -1)总是返回-1 发表3,结果: String[] array = new String[]{ "extra_asus_dial_use_dualsim", "com.android.phone.extra.slot", "slot", "simslot", "sim_slot", "subscription", "Subscription", "phone", "com.android.phone.DialingMode", "simSlot", "slot_id", "simId", "simnum", "phone_type", "slotId", "slotIdx" }; for (String item : array) { Log.i(TAG, "Sim Card - " + item + " -----> " + intent.getExtras().getInt(item)); } 日志: …

2
Kotlin Flow与LiveData
在上一个Google I / O中,Jose Alcerreca和Yigit Boyar 告诉我们,我们不再应该使用LiveData来获取数据。现在,我们应该将暂停功能用于一次抓取,并使用Kotlin的Flow创建数据流。我同意协程对于单次获取或其他CRUD操作(例如插入等)非常有用。但是,在需要数据流的情况下,我不了解Flow给我带来什么好处。在我看来,LiveData也在这样做。 流示例: 视图模型 val items = repository.fetchItems().asLiveData() 资料库 fun fetchItems() = itemDao.getItems() 道 @Query("SELECT * FROM item") fun getItems(): Flow<List<Item>> LiveData示例: 视图模型 val items = repository.fetchItems() 资料库 fun fetchItems() = itemDao.getItems() 道 @Query("SELECT * FROM item") fun getItems(): LiveData<List<Item>> 我还希望看到一些使用协程和Flow与Room或Retrofit协同工作的项目示例。我只找到了一个Google的ToDo示例,其中协程用于一次获取,然后在更改时手动重新获取数据。

4
使用touchListener和clickListener处于突出显示状态的左侧按钮
执行以下操作后,我的按钮保持在突出显示状态时出现问题: public class MainActivity extends AppCompatActivity { @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AppCompatButton button = (AppCompatButton) findViewById(R.id.mybutton); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d("Test", "calling onClick"); } }); button.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: …

3
ViewBinding-如何获取包含布局的绑定?
在使用ViewBinding时,我遇到了一些未记录的案例。 第一:如何获取包含的通用视图布局零件的绑定,主绑定仅查看主布局中的项目? 第二:如何获取包含的合并类型布局零件的绑定,再次主绑定仅查看主布局中的项目?

1
带有EditText的运动布局会破坏动画
我创建了一个简单的MotionLayout,它几乎与协调器布局相似(动画略有不同)。 这里是这样的: 打开键盘后,在内容区域中使用(几个)EditText视图将中断MotionLayout动画。动画现在有延迟,状态错误,UI开始冻结。任何想法如何解决这个问题? 以gif格式链接到错误 使用的版本: com.google.android.material:material:1.2.0-alpha01 androidx.constraintlayout:constraintlayout:2.0.0-beta3 我也可以在一个小示例应用程序中重现该行为 示例layout.xml: <androidx.constraintlayout.motion.widget.MotionLayout 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" app:layoutDescription="@xml/animation" tools:showPaths="true"> <androidx.appcompat.widget.Toolbar android:id="@+id/customtoolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <com.google.android.material.textview.MaterialTextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="32dp" android:layout_marginBottom="48dp" android:text="title" app:layout_constraintBottom_toTopOf="@+id/formLayout" app:layout_constraintStart_toStartOf="parent" /> <ImageView android:id="@+id/image" android:layout_width="200dp" android:background="#ff00ff" android:layout_height="200dp" android:scaleType="centerCrop" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/ic_home_black_24dp" /> <androidx.core.widget.NestedScrollView android:id="@+id/formLayout" android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.