• Breaking News

    Tuesday, March 16, 2021

    Android Dev - Weekly Questions Thread - March 16, 2021

    Android Dev - Weekly Questions Thread - March 16, 2021


    Weekly Questions Thread - March 16, 2021

    Posted: 16 Mar 2021 07:00 AM PDT

    This thread is for simple questions that don't warrant their own thread (although we suggest checking the sidebar, the wiki, our Discord, or Stack Overflow before posting). Examples of questions:

    • How do I pass data between my Activities?
    • Does anyone have a link to the source for the AOSP messaging app?
    • Is it possible to programmatically change the color of the status bar without targeting API 21?

    Large code snippets don't read well on reddit and take up a lot of space, so please don't paste them in your comments. Consider linking Gists instead.

    Have a question about the subreddit or otherwise for /r/androiddev mods? We welcome your mod mail!

    Also, please don't link to Play Store pages or ask for feedback on this thread. Save those for the App Feedback threads we host on Saturdays.

    Looking for all the Questions threads? Want an easy way to locate this week's thread? Click this link!

    submitted by /u/AutoModerator
    [link] [comments]

    Great news for indie android devs - 15% revenue cut rather than 30%

    Posted: 16 Mar 2021 08:19 AM PDT

    Quick question: Is this something I should be worried about?

    Posted: 16 Mar 2021 05:21 AM PDT

    https://jcenter.bintray.com/ is down?

    Posted: 15 Mar 2021 07:03 PM PDT

    Or is it just testing before shutting down by 2022, what the effect will be? ;-)

    submitted by /u/ElyeProj
    [link] [comments]

    Android Studio Arctic Fox Canary 10 available

    Posted: 15 Mar 2021 11:04 AM PDT

    How to only show the functions that are defined in the class in Dokka Kotlin Kdoc?

    Posted: 16 Mar 2021 04:04 AM PDT

    Question How to only show the functions that are defined in the class?

    Screenshots

    Image: https://user-images.githubusercontent.com/67386890/111287922-0bb43b00-8687-11eb-999f-32f61c49adaa.png

    Installation - Operating system: Windows - Build tool: Gradle v6.8.2 - Dokka version: 1.4.20

    Additional context Please specify in my Android build.gradle file, what configuration should I add with examples. Having so many hundreds of functions that I did not defined makes the doc almost unuseable.

    The screenshot shown above is generated for the Class. As you can see, only nice function and onCreate doc should have been generated:

    ``` class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) nice("PIZZA") } /** * Deserve it pizza nice */ fun nice(poi: String){ Log.d("Nice", "nice: FUN $poi ") } 

    }

    ```

    Here is what I tried:

    ``` android {

    dokkaHtml.configure { dokkaSourceSets { named("main") { noAndroidSdkLink.set(false) skipEmptyPackages.set(true) } } } 

    } ```

    Thank you for helping!

    submitted by /u/cnzzzdev
    [link] [comments]

    ADB Episode 158: Jetpack Compose... C'est bêta!

    Posted: 15 Mar 2021 06:42 PM PDT

    What is the modern approach to create advanced PDF files?

    Posted: 16 Mar 2021 03:48 AM PDT

    Hi,

    I need to create pdf documents in a new app.

    These should include tables, images, highlights etc.

    When searching for ways to do this I only get very old answers, links to paid libraries or the official documentation for pdfdocument, which seems limited in its functionality (https://developer.android.com/reference/android/graphics/pdf/PdfDocument).

    Are there some good libraries or what is the best way to create attractive PDF files currently?

    submitted by /u/pencilxyz
    [link] [comments]

    Which are the best map API?

    Posted: 16 Mar 2021 07:23 AM PDT

    Hey guys, i'm planning to make a little app which needs to use some kind of map api and a way of drawing routes. I know i can do this with the Google Maps Api but i dont know if there exists any other alternative.

    submitted by /u/PegsTheEmitter
    [link] [comments]

    JetpackCompose: Migrate RecyclerAdapter Items to Composables

    Posted: 16 Mar 2021 06:37 AM PDT

    Hi guys,

    i have an app where nearly 95% of the screens is programmed in recyclerview items. that means i have ONE adapter with around 150 different view types. this adapter is used on every screen because every item can exist on every screen.

    now that Jetpack Compose is in beta i am trying to figure out a good strategy to migrate the app to this awesome ui library. The migration could not be done in one step because 150 or even more really complex view types could not be rewritten completly.

    I am looking for a way to stay at the current recyclerview implementation and do the new stuff in compose. Are there any ideas how to achieve this?

    Here is an example of the current implementation:

    class Adapter : RecyclerView.Adapter { val items: List<UiItem> fun createViewHolder(viewType: Int, ...) { when(viewType) { is UiItemNormal -> ItemNormalViewHolder(...) is UiItemCompose -> ??? } } fun bindViewHolder(holder: ViewHolder, position: Int, ...) { val item = items[position] when(item) { is UiItemNormal -> (holder as ItemNormalViewHolder).bind(item) is UiItemCompose -> ??? } } } 

    I think i could use a ViewHolder which contains a single ComposeView and inside the bind method i create the views like this:

    class UiItemComposeViewHolder(composeView: ComposeView) : ViewHolder(composeView) { fun bind(item: UiItemCompose) { composeView.setContent { item.toComposable() // returns a @Composable function } } } 

    What do you think about this approach. Do you think it is future proof when we want to migrate completly to compose at a later time?

    I am looking forward to your ideas :-)

    submitted by /u/Bodo1981
    [link] [comments]

    Any way to set navigation graph starting destination before entering it?

    Posted: 16 Mar 2021 06:25 AM PDT

    Basically I want to have a starting page on my app that will be the first page on the first time entering the app, and after that will be an optional page you can enter using a button.

    Trying to do so I have set up the preferences and such, but the problem I am having is that my I cannot change the starting destination of my navigation graph before using "setContentView" in my activity, but if I use "setContentView" it already enters normal starting destination. I tried to maybe navigate to the fragment instead of setting it as the starting destination, problem is that I couldn't find a way to remove the original fragment from the backstack. Weirdly enough I also tried setting the popUpTo value to a different class and it made no difference. Here is the code:

     setContentView(R.layout.activity_main) if (!sharedPrefs.getBoolean("hasChosenCategory", false)){ var navHostFragment = Navigation.findNavController(this, R.id.nav_host_fragment).graph val destination = R.id.categorySelectionViewController navHostFragment.startDestination = destination } 
    submitted by /u/dannyjayes1
    [link] [comments]

    Bug when generate SHA-1 keys.

    Posted: 16 Mar 2021 05:56 AM PDT

    Music Player

    Posted: 16 Mar 2021 04:51 AM PDT

    Hello fellow Devs,

    I am having an issue regarding my Music Player, I have created a Notification Manager Using PlayerNotificationManager and the notification is showing perfectly. For this I have used Music Services and the Notification Manager and Player is set in the Music Services itself. The problem that I am facing is now my Music Player MainActivity is showing a blank screen although the Music is playing through the notification and I can play, pause ,rewind ,forward and next,prev. How can I sync both the Notification and player?

    submitted by /u/usernamenot__found
    [link] [comments]

    My experience with Aptoide and Catappult

    Posted: 15 Mar 2021 08:56 AM PDT

    Hi everyone, I would like to share my experience with Catappult and Aptoide distribution.

    Everything started a few months back, some of my users asked me to create a version of my apps without any dependency on Google services, i looked a bit around and found Catappult to be ON PAPER a very good solution, on their home page they state:

    • The best revenue share 75% (this is false already, since App Gallery gives 100%)
    • Reach 430 millions users (through a lot of stores but mainly Aptoide)
    • In app payment based on appcoins crypto supporting paypal and other payment mechanisms

    I said wow, let's do it. They claim they can do "automatic integration", so i enlisted and waited. After a few weeks my app was actually distributed, they hijack the app in app payment mechanism and add their own SDK in place of in app payment. Unfortunately this didnt work with my app it was still pointing to Google so i added the SDK myself. Documentation is a bit bad but i managed to do it.

    And at this point things started not to be nice anymore. I uploaded manually my APK and after a week got it rejected. Contacted support, took a few days, after a few days was told that i had too many permissions, permissions where the same as the published one, so i couldnt fix it, tried again and this time my app was approved and published.

    All worked well for like 2 days then i saw no downloads again. I checked on Aptoide and found out that there are like 20 other versions of my app including unlegal copies. So i contacted support and answer from Catappult stuff was "sorry, this is how Aptoide works, everyone can create its own store and upload your app and if they do it then it will be shown before yours".

    Basically they told me they have no control of the store and they don't see any issues in having users distribute an app without author authorization. Wow. Nice.

    That was not it. I also have a few paid apps on the store. I just noticed today they took those apps and are distributing those as well for FREE on Aptoide. Lucky enough i have some control so those wont work.

    Anyway, long story short, stay away!

    submitted by /u/frankmonza
    [link] [comments]

    Jetpack Compose - Pendulum Effect && Android Dev Challenge — Week 3 — Bloom — A Full Development Overview

    Posted: 15 Mar 2021 08:55 AM PDT

    Freya - A Simpler, Imperative Form Validation Library

    Posted: 15 Mar 2021 11:12 AM PDT

    Control your Android device with the power of ADB - Detailed tutorial on a bunch of ADB commands (Useful for Android Developers) [Commands start at 07:45] (Use timestamp to skip ahead to specific ADB commands)

    Posted: 15 Mar 2021 08:08 AM PDT

    Google Play- App Access needed

    Posted: 15 Mar 2021 10:30 PM PDT

    How you guys respond to 'App Access- Provide instructions on how to access restricted parts of your app' on Play Store console? For my case- my app talks to hardware and even if I provide test credentials , it will not let them access all the screen unless they have real hardware system with them.

    submitted by /u/Mobi_craze
    [link] [comments]

    Any clue why View Model Live Data observers are being called multiple times?

    Posted: 15 Mar 2021 09:33 PM PDT

    I've got properties which grab stuff from a database in my view model:

     private val databaseDao = QuestionDatabase.getDatabase(context).questionDao() val allQuestions: LiveData<List<Question>> = databaseDao.getAllQuestions() 

    In my fragment, I create the shared view model, then put an observer on allQuestions:

     private val viewModel: MainViewModel by activityViewModels { MainViewModelFactory(requireActivity().application) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) viewModel.allQuestions.observe(viewLifecycleOwner) { viewModel.setTestQuestions(it) Log.i("ViewModel", "Loaded questions $it, setting test questions") } } 

    Here's where things get weird for me. When I rotate the device, I can see these observers being triggered again. The view model is not being created again, since I've put a log statement within init() in the view model. But for whatever reason, it looks like the view model is loading from the database again and is triggering the observers upon rotation.

    Is there something I'm missing here? Really I'd want the view model to only load the database once and have that shared amongst all the other fragments.

    submitted by /u/IntuitionaL
    [link] [comments]

    Help and advice needed on how to implement ARCore within a larger app. Unity vs Android Studio?

    Posted: 15 Mar 2021 09:21 PM PDT

    I'm an Android beginner and have only created very basic apps so far, nothing incorporating AR.

    I've noticed the advice is to use Unity when it comes to ARCore and I've viewed a couple tutorials on youtube. I'm still a little confused as to how AR functionality is implemented within the context of a larger app.

    Right now I have an app that I made in Kotlin, into which I'd like to add AR functionality. I want to create an Activity which allows the user to add some AR icons / models to the camera and then take a screenshot.

    How are most people adding AR functionality exactly, creating the scene in unity and then somehow adding it into their AS Project? The recent google code lab was not very helpful here, only mentioning Unity and also left out a number of steps to get properly setup which is a bummer as a beginner (https://codelabs.developers.google.com/codelabs/arcore-intro#12)

    Is there a decent tutorial somewhere on how to add some AR functionality to an app using Unity? Can it only or should it only be done in AS when your project is bigger than just one scene / self contained app that only implements your AR functionality?

    Sorry if my question sounds completely idiotic, I'm still a beginner

    submitted by /u/trapinline
    [link] [comments]

    Do you encounter any weird behaviour, if you tend to call getIntent().getExtras() before Activity.super.onCreate() ?

    Posted: 15 Mar 2021 08:43 PM PDT

    I was wondering, have you encounter any weird behaviour, if you tend to call getIntent().getExtras() before Activity.super.onCreate() ?

    Recently, we prefer to call getIntent().getExtras() before Activity.super.onCreate() . Reason is that, during Activity recreation, Fragment onCreate will be call in the middle of Activity.super.onCreate() execution.

    Hence, if Fragment's onCreate is expecting some data structure from Activity's bundle, we are force to perform data structure initialization before Activity.super.onCreate(), by accessing getIntent().getExtras()

    The technical detailed is posted java - Is it ever safe, to execute getIntent().getExtras() before Activity.super.onCreate() - Stack Overflow

    We do observe some minor cases, which the returned Bundle from getIntent().getExtras() is null.

    We keep puzzling for a while, as we are not sure whether the null is caused by our decision of placing getIntent().getExtras() before Activity.super.onCreate(), or it is caused by some uncontrolled reason.

    We would like to tackle this problem but it is very difficult without knowing the exact reason.

    I was wondering, have u ever encounter similar issue? Based on your experience, do you think is it safe to call getIntent().getExtras() before Activity.super.onCreate() . Google's document doesn't mention on this, even though almost all of their code example, they do not place any code before Activity.super.onCreate().

    Thanks.

    submitted by /u/yccheok
    [link] [comments]

    Is it ok to create "apps" And not "games" For Android using unity engine?

    Posted: 15 Mar 2021 11:26 AM PDT

    I know that the unity engine is used to create 2d and 3d games for Android. However I am not familiar with ways to create a regular app that is not a game to android. So that got me thinking, is it ok to create an app like simple timer or diary or whatever it is that is not a game using the unity engine? Or is it specifically used to create only games? If so what are good ways y'all can recommend to create apps for Android?

    submitted by /u/TheRedLord_1
    [link] [comments]

    IAPs: Storing purchase history inside a JWT rather than referencing a DB?

    Posted: 15 Mar 2021 06:44 PM PDT

    I've never worked with IAPs so this is new to me... I have a few questions but they come down to -

    "Is it possible to handle IAPs without being required to store user data myself?"

    The idea being that, if a verified Google playerID/client purchases a non-consumable product, can I perform a lookup against their purchase history using Google's own services rather than referencing my own database?

    My idea was to store all a users IAPs in a JWT which are made available upon verification. Would this work?

    I want to keep things as simple as possible while also maintaining some sort of scalability.

    submitted by /u/zante2033
    [link] [comments]

    No comments:

    Post a Comment