我正在尝试使用架构组件中的WorkManager.我已将compileSdkVersion和targetSdkVersion从27升级到28. gradle sync已成功完成.但是构建时错误不断涌现.由于'android.support:design',android.support库使用的是版本28.0.0-rc02.
我试图添加packagingOptions以排除'proguard/androidx-annotations.pro'.但它没有帮助.但是这次我得到了一个不同的错误信息:
Program type already present: com.google.common.util.concurrent.ListenableFuture
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚出了什么问题.
的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.apps.test"
minSdkVersion 16
targetSdkVersion 28
versionCode 5
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
signingConfigs {
release
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "bool", "enableFirebase", "true"
}
debug {
minifyEnabled false
resValue "bool", "enableFirebase", "false"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], …Run Code Online (Sandbox Code Playgroud) android kotlin android-architecture-components android-ktx android-workmanager
我点击导航栏中的项目底部导航栏我正在替换片段.我有3个片段A,B,C所以点击b项B片段加载,在B我调用3-4个API.所以,现在如果我转到C然后再次来到B,就会创建一个新的B Fragment实例,并再次调用这些API,如何保存片段实例状态,而不是在更改片段时再次调用API.这是我的代码.
mBottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
Fragment currentLoaded = fgMan.findFragmentById(R.id.container_body);
switch (id) {
case R.id.nearby_fragment:
if (!(currentLoaded instanceof SpotFeedMapFragment)) {
removeScroll();
mNearByFragment = fgMan.findFragmentByTag(NEARBY_FRAGMENT_TAG) != null ? fgMan.findFragmentByTag(NEARBY_FRAGMENT_TAG) : mNearByFragment;
fgMan.beginTransaction().setCustomAnimations(R.anim.abc_fade_in, R.anim.abc_fade_out);
fgMan.beginTransaction().replace(R.id.container_body, mNearByFragment, NEARBY_FRAGMENT_TAG).commit();
fgMan.executePendingTransactions();
getSupportActionBar().setTitle(getString(R.string.nearby_fragment));
}
break;
case R.id.route_fragment:
if (!(currentLoaded instanceof BusLocationsFragment)) {
if (!inParent) {
mRl.removeView(fixLayout);
p.addRule(RelativeLayout.BELOW, toolbar.getId());
scrollView.setLayoutParams(p);
scrollView.addView(fixLayout);
mRl.addView(scrollView);
inParent = true;
}
//mFragment = new BusLocationsFragment();
mBusLocFragment = fgMan.findFragmentByTag(BUS_LOC_FRAGMENT_TAG) != null ? fgMan.findFragmentByTag(BUS_LOC_FRAGMENT_TAG) …Run Code Online (Sandbox Code Playgroud) android navigationbar android-fragments bottomnavigationview
当我的应用程序位于前台时,我想监听是否有电话来电。
以前是这样的,但现在不推荐使用listen():
val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
tm.listen(object : PhoneStateListener() {
override fun onCallStateChanged(state: Int, phoneNumber: String?) {
super.onCallStateChanged(state, phoneNumber)
when (state) {
TelephonyManager.CALL_STATE_RINGING -> transcribingAudioConsumer.stopTranscription(null)
else -> {}
}
}
}, PhoneStateListener.LISTEN_CALL_STATE)
Run Code Online (Sandbox Code Playgroud)
我尝试过类似的方法,但找不到正确的方法来实现它。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
tm.registerTelephonyCallback({ it.run() }, MyPhoneStateListener())
}
Run Code Online (Sandbox Code Playgroud)
@RequiresApi(Build.VERSION_CODES.S)
class MyPhoneStateListener : TelephonyCallback(), TelephonyCallback.CallStateListener {
override fun onCallStateChanged(state: Int) {
when (state) {
TelephonyManager.CALL_STATE_RINGING -> {
Timber.e("omg RING")
}
TelephonyManager.CALL_STATE_OFFHOOK -> {
Timber.e("omg hook")
}
TelephonyManager.CALL_STATE_IDLE -> {
Timber.e("omg idle")
}
}
} …Run Code Online (Sandbox Code Playgroud) 当我运行 UI 测试时,它们工作得很好,并且我可以看到测试已通过日志传递。但 Android Studio 面板上的测试状态从未更新。
有人遇到过同样的问题吗?
测试结果作为日志:
Step2TableWithHeadersNextDirectionRow[SM-A505FN - 11] SUCCESS
....
2022-03-15T10:52:14.245+0100 [INFO] [com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask] [XmlResultReporter]: XML test result file generated at /Users/mySuperApp/app/build/outputs/androidTest-results/connected/flavors/superApp/TEST-SM-A505FN - 11-app-superApp.xml. Total tests 2, passed 2,
2022-03-15T10:52:14.247+0100 [QUIET] [system.out]
....
Run Code Online (Sandbox Code Playgroud)
Android Studio Bumblebee | 2021.1.1 Patch 2
Build #AI-211.7628.21.2111.8193401, built on February 17, 2022
Runtime version: 11.0.11+0-b60-7772763 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.2.1
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 10
Registry: external.system.auto.import.disabled=true, ide.images.show.chessboard=true
Non-Bundled Plugins: org.jetbrains.kotlin …Run Code Online (Sandbox Code Playgroud) android android-testing android-studio android-espresso android-studio-girafee
我在尝试向状态栏添加颜色时发现了影响相对布局高度的问题.
添加Flag会影响相对布局的计算rootView的高度.
private void changeStatusBarColor(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.red_e31837));
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个视图树观察器,可以帮助我跟踪rootView的高度.
private ViewTreeObserver.OnGlobalLayoutListener keyboardLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = wrapper.getRootView().getHeight() - wrapper.getHeight();
}
Run Code Online (Sandbox Code Playgroud)
int heightDiff等于1920,如果我使用,FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS但如果我不使用changeStatusBarColor(),int heightDiff等于1776(计算没有动作栏和状态栏我猜).但为什么添加此标志会改变计算?提前致谢!
当我将 gradle 版本增加到gradle-7.3.3from时gradle-7.2,我收到一个 gradle 同步错误,内容是Multiple entries with same key: main=[] and main=[].
当我将 ProductFlavors 名称更改为mainCore或其他名称时main,gradle 同步时不会出现错误。
我想知道如何继续使用mainproductFlavor。有任何想法吗?
.....
flavorDimensions "mode", "client"
productFlavors {
/////// Distribution Modes ///////
main {
dimension "mode"
versionName generateVersionName()
manifestPlaceholders = [
app_label: "@string/app_name",
appIcon: "@mipmap/ic_launcher",
appIconRound: "@mipmap/ic_launcher_round"
]
}
beta {
dimension "mode"
applicationIdSuffix ".beta"
manifestPlaceholders = [
app_label: "@string/app_name",
appIcon: "@mipmap/ic_launcher_beta",
appIconRound: "@mipmap/ic_launcher_beta_round"
]
} .....
Run Code Online (Sandbox Code Playgroud) 我有一个小部件应用程序,没有问题Android Lollipop或较低的操作系统.当我将nexus 5升级到Marshmallow(android 6.0)时,我意识到我的小部件在加载自定义行列表视图时遇到问题.Widget有一个动态textView和一个动态listView.textView工作得很好; 但是listView行项目没有希望.当我添加小部件时,行处于加载阶段.它与Lollipop或更低版本的设备完全相同,但不适用于Marshmallow.我相信棉花糖正在引发一个我无法找到它的问题.我希望有人告诉我我做错了什么并帮助我解决这个问题.我很感激所有的帮助.谢谢.
WidgetProvider.class:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
System.out.println("WidgetProvider.onUpdate()");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final boolean isMaviKart = MainUtils.getCardType(context).equals(Constants.CARD_TYPE_MAVI);
try {
//set widget id
ComponentName thisWidget = new ComponentName(context, WidgetProvider.class);
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
MainUtils.setWidgetID(prefs, allWidgetIds[allWidgetIds.length - 1]);
for (int i = 0; i < appWidgetIds.length; i++) {
Intent intentService = new Intent(context, WidgetService.class);
intentService.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
intentService.setData(Uri.parse(intentService.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget);
widget.setRemoteAdapter(appWidgetIds[i], R.id.list_view, intentService);
Intent clickIntent = new Intent(context, MainActivity.class);
PendingIntent …Run Code Online (Sandbox Code Playgroud) android android-widget appwidgetprovider android-appwidget android-6.0-marshmallow
我正在尝试观察View Collection 和上游流量已停止的结果。但当viewModel.testFlow应用程序在后台时仍在收集。为什么我看不到收集已停止?我观察到了什么错误吗?
视图模型:
val testFlow = flow<Int> {
for (i in 1..100) {
delay(1000)
Timber.e("testFlow: EMIT = $i")
emit(i)
}
}
Run Code Online (Sandbox Code Playgroud)
活动:
override fun onViewCreated() {
lifecycleScope.launch {
viewModel.testFlow
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
.collect {
Timber.d("testFlow: $it Collected")
}
}
}
override fun onActivityPaused(activity: Activity) {
super.onActivityPaused(activity)
Timber.e("testFlow: onActivityPaused")
}
Run Code Online (Sandbox Code Playgroud)
https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda
android kotlin kotlin-coroutines kotlin-flow kotlin-stateflow
https://www.dropbox.com/s/lykyutdlo6386il/nexus%205%202.png?dl=0
这张照片是由nexus 5拍摄的.正如您所看到的,屏幕顶部和底部之间的差距是不同的.侧边菜单关闭时会裁剪Android徽标.底部屏幕的一部分隐藏在本机导航栏下.
https://www.dropbox.com/s/wcwuat1bwoqa26v/correct1.png?dl=0
另一方面,这张照片是由galaxy s5 mini拍摄的.您可能会注意到屏幕顶部和底部之间的间隙是相同的.完全没有问题.
它与ResideMenu库相同,具有不同的设备和Android OS(棒棒糖和kitkat).我查看布局(residemenu.xml)以找出错误的内容; 但一切似乎都对我不对.我找不到任何解决这个问题的方法.有没有办法解决正确缩放主片段(从顶部和底部相同的边距)?请帮我.
链接到库:github.com/SpecialCyCi/AndroidResideMenu
编辑:
这个链接是我正在谈论它的解决方案的问题.
android android-fragments nexus-5 android-5.0-lollipop residemenu
我在显示剪切/复制/粘贴菜单时遇到问题。在AutoCompleteTextView中写入字符串后,在单词打开剪切/复制/粘贴菜单的第一个选择(LongClick)中。不幸的是,此菜单已从其原始位置移开。
有趣的是,当我单击左右选择指示符来更改单词的范围时,剪切/复制/粘贴菜单会渲染自身并纠正其位置。现在可以单击剪切/粘贴/复制操作按钮。
我试图更改所有内容以查找导致此问题的原因,但没有任何更改。我认为某些内容会在裁剪错误的位置触发android的默认剪切/复制/粘贴菜单。不幸的是我找不到它。
任何建议表示赞赏。谢谢。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:installLocation="auto">
<uses-permission android:name="com.example.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" …Run Code Online (Sandbox Code Playgroud) android autocompletetextview android-layout android-edittext android-search
android ×11
kotlin ×2
nexus-5 ×2
android-12 ×1
android-architecture-components ×1
android-ktx ×1
firebase ×1
gradle ×1
kotlin-flow ×1
residemenu ×1
telephony ×1