/r/androiddev

Photograph via snooOG

News for Android developers with the who, what, where, when and how of the Android community.

News / Articles / Talks / Tools / Open source!

About

News for Android app developers with the who, what, where, when, and how of the Android community. Probably mostly the how.

Here, you'll find:

  • News for Android developers
  • Thoughtful, informative articles
  • Insightful talks and presentations
  • Useful libraries
  • Handy tools
  • Open source applications for studying

Alternatives

This sub-reddit isn't about phones' and apps' general functionality, support, or system software development (ROMs). For news and questions about these topics try using other subs like

New Developer Resources

Build your first app

Starting Android career in 2022

Android Job Interview Questions and Answers

App Portfolio Ideas, Tiered List

Awesome Android UI

Material Design Icons

7000 Icons for Jetpack

Weekly Threads Calendar

Autoposted at approx 9AM EST / 2PM GMT

Links

Rules!

Wiki and FAQ!

Discord!

/r/androiddev

241,487 Subscribers

1

Question about UI

If you had an app with 10+ very similar "add post" screens, would you create separate screens for all of them even though main difference is different amount and types of textfields or would you use some kind of patern like builder and create 1 screen, with a bunch of if/when statements displaying required fields + routing them to proper viewmodel calls?

5 Comments
2024/10/17
23:01 UTC

4

RowKalendar: Scrollable horizontal calendar library for Compose Multiplatform 📅

Hey everyone 👋

I’ve been working on a Compose Multiplatform library called RowKalendar, which allows you to easily add a scrollable horizontal calendar component to both Android and iOS apps. It's designed to be simple, customizable, and user-friendly.

Currently, it supports Android and iOS, with desktop and browser support coming soon.

I’d really appreciate your feedback on potential improvements or new features 🙏
And if you find it helpful or interesting, please consider starring and sharing the repo 🌟

GitHub repository: RowKalendar

https://preview.redd.it/6i4n34a35evd1.png?width=1614&format=png&auto=webp&s=2d65dcd7e51f930cf6bfd14e8dd8fabc7bf12c3f

0 Comments
2024/10/17
22:07 UTC

1

Not sure why Proguard/R8 is removing certain code

We're adding R8 into our android app to remove some code from a specific dependency used by our app. Our proguard-rules file looks like below:

-dontobfuscate
-dontoptimize
-keep class !com.kaltura.tvplayer.offline.**, !com.kaltura.android.exoplayer2.scheduler.**, !com.kaltura.android.exoplayer2.offline.**, !com.kaltura.tvplayer.OfflineManager { *; }
-printusage usage.txt

After building our app and viewing the generated usage.txt file, we see that the code that we want removed from the dependency is removed. However, there is also other code that is removed and we're not sure why. That code is shown below:

kotlinx.coroutines.debug.AgentPremain$$InternalSyntheticLambda$1$677acd6fb4ca1651eb1c76ebe61d8c1a9f5aeadf35534bff63c38388e03cb9a0$0:
    public final void handle(sun.misc.Signal)
kotlinx.coroutines.debug.AgentPremain:
    public static synthetic void $r8$lambda$qtwhjy3HAlNEjQH7oAL6W8vp2zY(sun.misc.Signal)
com.google.android.material.checkbox.MaterialCheckBox$$InternalSyntheticLambda$1$a66ca6c6de65b4f256ca2f0a8ce6032afe507a77d8c42ef3015c9db612807b7a$0
com.google.android.material.checkbox.MaterialCheckBox:
    public static synthetic void $r8$lambda$hE-Ehj__sZakT88clijs-fYFgxg(com.google.android.material.checkbox.MaterialCheckBox)
io.reactivex.rxjava3.internal.jdk8.ObservableFlatMapStream$FlatMapStreamObserver$$InternalSyntheticApiModelOutline$1$87977bb73faf46839e24319ed6c7f5e872a83d3099d0adb8f3afc970e63deb06$2
io.reactivex.rxjava3.internal.jdk8.ObservableFlatMapStream$FlatMapStreamObserver$$InternalSyntheticApiModelOutline$1$87977bb73faf46839e24319ed6c7f5e872a83d3099d0adb8f3afc970e63deb06$5
org.apache.commons.io.file.PathUtils$$InternalSyntheticApiModelOutline$1$778588db3304f74caa63c13b87cbf3c380b7de57d734f860afc58cfef4c8cf73$2
org.apache.commons.io.file.PathUtils$$InternalSyntheticApiModelOutline$1$778588db3304f74caa63c13b87cbf3c380b7de57d734f860afc58cfef4c8cf73$5
org.apache.commons.io.filefilter.EmptyFileFilter$$InternalSyntheticApiModelOutline$1$95abaa9ca0d4f21097e19aae95cd518500ff56bb37279c94168ab66f95dc3506$4
org.apache.commons.io.filefilter.EmptyFileFilter$$InternalSyntheticApiModelOutline$1$95abaa9ca0d4f21097e19aae95cd518500ff56bb37279c94168ab66f95dc3506$7

Even if we update the proguard-rules file to have a keep statement that encompasses all classes (like below), the usage.txt file still shows that the same code is being removed

-dontobfuscate
-dontoptimize
-keep class ** { *; }
-printusage usage.txt

We have tried a couple of different things to help with this issue.

First, as described above, we added a keep statement to keep all classes as a sanity check -keep class ** { *; } . We were surprised to find in our usage.txt file that the code was still being removed after adding this.

We also tried adding adding specific keep rules to make sure certain code was not removed (like below). These keep rules also had no impact on what code was being removed.

-keep class org.apache.commons.io.file.PathUtils** { *; }

-keep class com.google.android.material.** { *; }

Does anyone have any insight into why this code might be getting removed and what we could add to our proguard rules file to prevent it from being removed?

0 Comments
2024/10/17
20:47 UTC

5

The New Api Level of Google

Hello, very good, I have a problem with my App, it gave me an error that said "you need to update the API to 34" and that is why it is fine, I guess, what scares me is the message where it says "the target APIs that do not have one year old will not be able to be updated" does that mean I will have to wait a year?! I need to get it out as soon as possible, please help, thank you

4 Comments
2024/10/17
20:02 UTC

2

How do you scope dependencies to a multi-screen flow?

I'm curious about how others are approaching dependency scoping for flows that span multiple screens/fragments. These dependencies need to live as long as the flow is active and to be cleared once the flow is dismissed.

1. Using Dagger Subcomponents

For those using Dagger, how are you managing the subcomponent lifecycle?

A. Recreate Subcomponent onAttach()

Do you keep the subcomponent in the flow host fragment (container fragment) and recreate it onAttach(), similar to how Dagger-Android (RIP) manages subcomponents. The issue here is that the subcomponent gets recreated with each fragment recreation, including after configuration changes. This can lead to the following scenario:

  • Let's say ViewModel A initially receives an instance of a binding through the subcomponent.
  • After a configuration change, ViewModel A survives and keeps the existing instance of the binding.
  • However, if we then navigate to a screen with ViewModel B, it will be injected with a newly recreated subcomponent, resulting in a different binding instance.

This can lead to inconsistencies, as ViewModel A and ViewModel B end up with different instances, which is generally not what you want.

B. Manual Lifecycle Management

Another approach is to hold the subcomponent in a larger scope, such as at the application level, and then manually clear it when the flow is dismissed. For example, you might do something like this in onDestroy:

override fun onDestroy() {
    if (!requireActivity().isChangingConfigurations) {
        clearSubcomponent()
    }
    super.onDestroy()
}

This approach allows more control over the subcomponent lifecycle but requires you to manually handle when the subcomponent should be cleared, adding some complexity.

2. Using Navigation-Scoped ViewModel

Another option is to use a navigation-scoped ViewModel to manage dependencies. This simplifies things since it bypasses the complexities of dependency injection scoping, letting the ViewModel handle flow-level dependencies directly. However, it's not scalable: the ViewModel may need to expose data not directly related to UI just so other ViewModels can access it.

9 Comments
2024/10/17
18:38 UTC

1

Is there a way to filter Blueooth LE by class of device or appearence?

I'm currently developing an Adnroid BLE app for my masterthesis. The main task is to scan an area full of people and determine the amount of people in a distance of X meters around the scanning the device. I somehow need to filter the devices (otherwise there way to many and false results e.g. scanning a motorcycle that uses BLE), so far i tried multiple approaches:

  • Filter the scan record for manufacturer id
    • Most of the devices have 0x004C as their company id even they are not from Apple
  • Use ScanFilters for finding devices who publish their class of device/appearence
    • Got little to no results when scanning with this filter
  • Query the raw payload bytes (converted to hex) for appearence AD Type
    • No luck, same result as approach #1

Do i need to connect to every specific device in order to obtain this data?

Currently trying on a Lenovo Tab M10 / Galaxy S20 Ultra

Thank you for any help!

3 Comments
2024/10/17
17:04 UTC

1

Is there calendar tasks API for android? So far I can only find REST web api

Is there really no calendar tasks API for android? Sounds odd because there is calendar API for android but somehow it's only for events, and there is nothing for tasks, huh? Maybe I am looking at wrong places...

I could only find REST web API here: https://developers.google.com/tasks/overview

Are there any android (kotlin) examples or libraries? Thanks

2 Comments
2024/10/17
07:32 UTC

35

New to Android Development? Need some personal advice? This is the October newbie thread!

Android development can be a confusing world for newbies; I certainly remember my own days starting out. I was always, and I continue to be, thankful for the vast amount of wonderful content available online that helped me grow as an Android developer and software engineer. Because of the sheer amount of posts that ask similar "how should I get started" questions, the subreddit has a wiki page and canned response for just such a situation. However, sometimes it's good to gather new resources, and to answer questions with a more empathetic touch than a search engine.

As we seek to make this community a welcoming place for new developers and seasoned professionals alike, we are going to start a rotating selection of highlighted threads where users can discuss topics that normally would be covered under our general subreddit rules. (For example, in this case, newbie-level questions can generally be easily researched, or are architectural in nature which are extremely user-specific.)

So, with that said, welcome to the October newbie thread! Here, we will be allowing basic questions, seeking situation-specific advice, and tangential questions that are related but not directly Android development.

We will still be moderating this thread to some extent, especially in regards to answers. Please remember Rule #1, and be patient with basic or repeated questions. New resources will be collected whenever we retire this thread and incorporated into our existing "Getting Started" wiki.

55 Comments
2024/10/17
05:31 UTC

4

Are @Composable functions Composable elements themselves

New to compose, want to understand this, take the below code as an example

@ Composable

fun Counter() { 

val count = remember { mutableStateOf(0) }

SideEffect{

println("Counter is recomposing")

}

Column {

Button(onClick = { count.value++ }) {

println("Button content is recomposing")

Text("Count: ${count.value}")

}

}

}

is the Counter function annotated with composable a wrapper here? which converts to a composable element like Column or something? if not then where does the count reside?

7 Comments
2024/10/16
20:26 UTC

2

Store Voyager Screens for navigation

Initially, I was using the Jetpack Compose navigation library to manage navigation in my app (Things got really really messy, really really fast)

So I switched to Voyager . It seems really good with the parameters and the way It handles navigation and ScreenModel . But the thing is, I cannot do this:

    val listOfNavs = listOf(
        NavInfo(
            name = "Home",
            route = "home_route", // type String
       ), <etc> ...
    // and then, do this:
    listOfNavs.forEach {
        Button(onClick = { navCtrl.navigate(it.route) })
    } // this is the only simple part of compose navigation

Which was really useful in creating list of buttons or in ModalNavDrawer to make the buttons

So my question is how to make it such that I can do something like:

    val listOfNavs = listOf(
        NavInfo(
            name = "Home",
            screen = HomeScreen, // this does not work... (type: Screen)
       ), <etc> ...
    // and then somewhere do this:
    listOfNavs.forEach {
        Button(onClick = { navigator.push(it.screen) }) {
            Text (text = it.name)
        }
    } // and be done with this...
// But making a list of such Screen does not seem to be possible in voyager
//

How do I implement the above mentioned code in Voyager?

2 Comments
2024/10/16
19:42 UTC

9

How to secure google map api key

As far as i ve checked, the api key should be in android manifest which will be used by the MapView that we are using in the app. But the problem is if i decompile my app, i can see my api key in the manifest.

I even checked the apk (cloned the repo found in android documentation website itself which has the example on implementing maps in project), its the same.

How to secure it? I saw that we can use google console and we can restrict the use of api, but still the api should be set in manifest and still it can be decompiled and misused. How to solve this?

15 Comments
2024/10/16
15:12 UTC

8

Modernizing the Builder Pattern in Kotlin

0 Comments
2024/10/16
15:01 UTC

0

Android Studio drop the devices

Hi everyone!

I've been struggling with an issue for almost a week now. I have two devices connected to my computer: an A40 phone and an A9 tablet with USB debugging enabled. The phone keeps getting disconnected; sometimes it reconnects, and when it does, I have to approve the RSA key multiple times. Sometimes I have to tap approve 7-8 times before it accepts. After that, the device gets disconnected from Android Studio again within a few minutes. The tablet is slightly better, as it keeps disconnecting but reconnects automatically. What can be done to fix this?

8 Comments
2024/10/16
13:08 UTC

2

Running Linux C++ process in background (with foreground service)

I want to understand something.

I have a project I want to use in Android. The biggest problem is that this project uses classic unix approach of several processes comminicating with it (indilib)

MyProgram <- tcp -> indiserver --> pipe -> indi_driver_1
                               \-> pipe -> indi_driver_2

And so on. My program is already foregrdound service - since it does some imaging and computation all the time, but I need to fork/exec several processes - not JAVA just plain executables. I know I can run an executable and I do it - (just it runs tens of seconds most)

I've read there may be some limitations. Can somebody shed the light for me on it?

6 Comments
2024/10/16
12:12 UTC

4

DJI Mobile SDK V5 - Object detection

Hello, a classmate and I are trying to implement an object detection algorithm on a DJI Mini 3 using the MSDK v5 but are encountering issues. We have tried to modify the DafaultLayoutActivity.java in the official example https://github.com/dji-sdk/Mobile-SDK-Android-V5 to no success. What we are struggling with is how to incorporate a frame-listener to intercept the video stream from the drone. Does anyone have som advice or experience from this? Any help is gladly appreciated.

3 Comments
2024/10/16
10:20 UTC

5

How to support back button navigation on compose

I want to show the back icon button on most screens in my app, and saw this guide: https://developer.android.com/develop/ui/compose/components/app-bars-navigate.

I’m wondering if it’s normal to always include this callback in every composable that supports back navigation:

navigateBack: () -> Unit

is there a better way to handle back navigation across multiple composables?

I just started re-leaning Android development again for a fairly huge project I want to build and I can already envisage how messy my navigationRoot class is going to be as I need to support multiple composable navigation. Is there a good way to structure navigation for a large app?

6 Comments
2024/10/16
07:27 UTC

1

Is okay to publish a watch face platform on Play Store?

Hi, I'm wondering if it's okay to publish a watch face platform on the Play Store or it that would count as a third-party app store and get my account banned. The app would provide links to the watch faces' listings on Play Store, but eventually, it could directly download to the watch using APKs.

7 Comments
2024/10/16
00:29 UTC

2

Has Anyone Used Jetpack Compose in an Overlay Service?

I'm working on an Android app where I want to use Jetpack Compose in an overlay service,
I'm facing some issues getting it to work properly.

5 Comments
2024/10/15
19:23 UTC

1

I'm releasing an app on the Play Store. Is there a place where I can download official bezels for popular Android devices, e.g. Pixel 9?

For iOS there is this page. Does anyone know where I could find an Android equivalent?
https://developer.apple.com/design/resources/#product-bezels

2 Comments
2024/10/15
17:15 UTC

1

Is it fine to open 2 Google play console in 1 laptop

Hi there,
My gf and I both TS developers we started shipping Android apps, we are in same place using same wifi, I heard Google can take measures against this , or at least associate them, if one got a strike the other potentially can have issues.

Sometimes we use also our iMac to release some apps, I hope that Google did not take it as a spam.

Is this true? I could not find anything on that matter. Please help

5 Comments
2024/10/15
18:00 UTC

1

ImageButton set drawable src depending on app theme

Hi everyone, hope you're all doing great.

I'm building an app in which I have an ImageButton, and I want this ImageButton to change depending on the current theme in the app.
To get this result, I tried this:

The ImageButton src calls an xml file like this:

<ImageButton
    android:id="@+id/buttonLike"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="?attr/selectableItemBackgroundBorderless"
    android:contentDescription="@string/like"
    android:padding="2dp"
    android:scaleType="fitCenter"
    android:src="@drawable/like_button" />

Then, in the "like_button.xml" file, I use a custom attribute to get the drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/ic_liked" />
    <item android:drawable="?attr/likeIconDrawable" />
</selector>

The custom attribute is clearly declared in my attrs.xml file, like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <attr name="likeIconDrawable" format="reference" />
</resources>

Then, Finally, in each of my themes.xml (light and dark versions), I use the custom attribute to reference the corresponding images:
My themes.xml (light version)

<resources xmlns:tools="http://schemas.android.com/tools">
    
    <style name="Base.Theme.FluxBiz" parent="Theme.Material3.DayNight.NoActionBar">
        
        <item name="colorPrimary">@color/my_light_primary</item>
        <item name="colorPrimaryVariant">@color/my_light_primary_variant</item>
        <item name="colorOnPrimary">@color/my_light_on_primary</item>
        <item name="colorOutline">@color/my_light_border</item>
        <item name="likeIconDrawable">@drawable/ic_light_not_liked</item>
        <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
    </style>

    <style name="Theme.FluxBiz" parent="Base.Theme.FluxBiz" />
</resources>

My themes.xml (night / dark version)

<resources xmlns:tools="http://schemas.android.com/tools">
    
    <style name="Base.Theme.FluxBiz" parent="Theme.Material3.DayNight.NoActionBar">
        
        <item name="colorPrimary">@color/my_dark_primary</item>
        <item name="colorPrimaryVariant">@color/my_dark_primary_variant</item>
        <item name="colorOnPrimary">@color/my_dark_on_primary</item>
        <item name="colorOutline">@color/my_dark_border</item>
        <item name="likeIconDrawable">@drawable/ic_dark_not_liked</item>
        
    </style>
</resources>
Here's my problem: Inside my like_button.xml, when I try to use the custom attribute to find the images, my app crashes because it can't find the drawable correctly. I know the problem is related to the custom attribute, because when I use the normal file path inside my like_button.xml, it works fine.

Does anyone have any solution for this ? I tried searching online but couldn't find a solution for this exact context.
Thanks for reading.

5 Comments
2024/10/15
17:44 UTC

1

Reccommended Gesture/Animation combo for "Content Feed" like UX

Hello all,

Using Kotlin + Jetpack Compose, Material3

I want the User to be able to swipe left/right to dismiss a CustomCard composable, and then load the next CustomCard for them to view similar to how swiping on dating sites/video feeds work.

At first I was trying to manually control the animations and state with the .draggable and the .graphicsLayer modifiers but couldn't figure out how to trigger a state reset. I have since moved on to using the swipe gesture and the SwipeToDismissBox composable, but maybe I should actually be using a fling gesture? I don't know, I'm new to android and mobile gestures.

What is your preferred way to set something like this up? Thanks in advance.

1 Comment
2024/10/15
16:35 UTC

4

New apks no longer pass Play Protect (3rd party install)

For context, I have a codebase from a year ago. I have an apk made a year ago and one made today. The one from last year still installs without problems, new apk runs into "This app was built for an older version of Android and doesn't include the latest privacy protections "

Nothing changed in SDK versions or gradle versions. I mightve upgraded Android studio and that's all.

I generate signed apk via Android Studio interface. I used different apk analyzers that say the two apks are the same

What is different between the two apks? How is the old apk able to overcome the play protect pop-up?

16 Comments
2024/10/15
13:10 UTC

1

How to check for call forwarding status

I have an app where I need to check for call forwarding status. Because I need to dial the mmi code outside of the app I thought of monitoring the app for outgoing calls, but even through I had added to AndroidManifest.xml

```

<receiver

android:name=.Receiver

android:exported=true

android:enabled+true

/>

```

The Receiver class implementing BroadcastReceiver never gets called, neither with Intent.ACTION_NEW_OUTGOING_CALL nor with anything else.

Nor in the Android docs have I founded anything that may help me, not even in the telecom framework

2 Comments
2024/10/15
07:40 UTC

Back To Top