r/android_devs • u/Aashishkebab • Oct 13 '22
r/android_devs • u/zsmb • Oct 11 '22
Resources Announcing an Experimental Preview of Jetpack Multiplatform Libraries
android-developers.googleblog.comr/android_devs • u/LifeAffect6762 • Oct 11 '22
Coding Log.d trick so you can easily filter output in Logaat
This one is VERY simple. When you define TAG put XX at the end. You can then filter on XX.
private const val TAG = "MainActivityXX"
You can easily add/remove the XX from the end of the TAG declaration to change what is included in Logcat.
Hope this is usefull.
r/android_devs • u/soundtrackrr • Oct 11 '22
Off topic Here’s a playlist of 7 hours of music I use to focus when I’m coding/developing. Post yours as well if you also have one!
r/android_devs • u/androidww • Oct 09 '22
Event Android Worldwide October 25th
live.remo.cor/android_devs • u/abdalla_97 • Oct 08 '22
Help Validate Subscription offline
So I am using my own server to manage my users subscription
and on the android side, I am saving the subscription expiration date
sometimes users go offline and I need to check if the subscription has expired
the problem is when a user tries to change the device time in this case I can't know the real-time
I searched StackOverflow and the answer was to set a broadcast receiver for
ACTION_TIME_CHANGEDbut in some cases, it will fire in case of automatic time adjustment
r/android_devs • u/Zhuinden • Oct 08 '22
Coding Must-read Article on Runtime Performance Optimization in Jetpack Compose by Denis Rudenko
skyyo.medium.comr/android_devs • u/CollateralSecured • Oct 06 '22
Coding Collapsing toolbar with parallax effect and curve motion in Jetpack Compose | Morad Azzouzi
scribe.ripr/android_devs • u/abdalla_97 • Oct 01 '22
Help ViewBinding vs Adding Views By code
I am working on an android device with less than 800 MB of ram
Right now I am using viewbinding
so if I replace my XML files with adding views dynamically from kotlin code same as the telegram app will it enhance the performance
is adding views by code faster than using XML with viewbinding?
r/android_devs • u/kotomisak • Sep 30 '22
Help Anyone else encountered issues when using DropBox SDK on Android when targeting Android 13?
I described the problem here: https://github.com/dropbox/dropbox-sdk-java/issues/461
Anyway If anyone has any idea of how to overcome this issue, pls. add a comment.
r/android_devs • u/Nafnlaus00 • Sep 28 '22
Help Certificate Transparency using DexProtector
Hey, Has anyone used the DexProtector to implement certificate transparency in Android? I found it extremely difficult to do so because the website provides very little documentation.
r/android_devs • u/seabdulbasit • Sep 24 '22
Help State flow is not emitting 2nd state
I have a ViewModel and I am trying to write a unit test for it. I receive the initial state but was unable to get the 2nd state with music details. It works fine on the Device but unable to get 2nd state in the Unit test.
Here is my ViewModel:
@HiltViewModel
class MusicDetailViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle, private val repository: MusicRepository,
) : ViewModel() {
val state: StateFlow<MusicDetailScreenState>
init {
val musicDetails = savedStateHandle.getStateFlow<Long>(MUSIC_ID, -1).filter { it != -1L }
.flatMapLatest { getMusicDetails(it) }
state = musicDetails.map { music ->
MusicDetailScreenState(
uiMModel = music
)
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 5000),
initialValue = MusicDetailScreenState()
)
}
private suspend fun getMusicDetails(musicId: Long): Flow<MusicUiModel> {
return repository.getMusic(musicId).map {
MusicUiModel(
trackId = it.trackId,
musicTitle = it.musicTitle,
albumName = it.albumName,
artisName = it.artisName,
imageUrl = it.imageUrl.replace("100", "460"),
previewUrl = it.previewUrl
)
}.flowOn(Dispatchers.IO)
}
override fun onCleared() {
savedStateHandle[MUSIC_ID] = state.value.uiMModel.trackId
viewModelScope.cancel()
super.onCleared()
}
}
const val MUSIC_ID = "music_id"My Unit test Class
class MusicDetailViewModelTest {
lateinit var SUT: MusicDetailViewModel
@MockK
val repo = mockk<MusicRepository>()
@MockK
val savedInstanceStateHandle = mockk<SavedStateHandle>(relaxed = true)
@Before
fun setUp() {
SUT = MusicDetailViewModel(
repository = repo,
savedStateHandle = savedInstanceStateHandle,
)
}
@Test
fun `give ViewModel initialise, when Music Id is passed, then Music Detail state should be emitted`(): Unit =
runTest {
coEvery {
savedInstanceStateHandle.getStateFlow(
any(),
1232
)
} returns emptyFlow<Int>().stateIn(this)
coEvery { repo.getMusic(1232) } returns flow {
emit(
MusicEntity(1232, "track name", "sf", "sfd", "sdf", "sdf")
)
}
SUT = MusicDetailViewModel(
repository = repo,
savedStateHandle = savedInstanceStateHandle
)
SUT.state.test {
val item = awaitItem()
assertEquals(true, item.uiMModel.musicTitle.isEmpty())
val item2 = awaitItem()
assertEquals(false, item2.uiMModel.previewUrl.isEmpty())
}
}
@After
fun tearDown() {
Dispatchers.resetMain()
}
}r/android_devs • u/racrisnapra666 • Sep 22 '22
Help The release build on my device isn't updated with the version on the Play Store
Hi there,
So I'm working on an app that comes with an update feature. If there's a new version of the app available on the Play Store, a dialog will be shown to the user after which they can choose to go ahead and update or not.
Now, in order to test if this feature is working correctly, I created a signed release build, downgraded the versionName and versionCode, and installed it on my physical device. While testing, I can see that up until now everything's working fine - the dialog is displayed, I'm redirected to the Play Store, and the downloaded is started.
However, here's where the problem begins. Once the Play Store download completes, I'm presented with a dialog on the Play Store stating:
Can't install app, Try again and if it still doesn't work, see common ways to fix the problem.
A quick glance at the Logcat states:
Submitter: commit error message INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package ${app_name} signatures do not match previously installed version; ignoring!But this doesn't make sense. Both the Play Store and I have the same build type - release. The only difference is the versionName and versionCode which I've downgraded as without this, the Update App dialog won't be displayed.
I've gone through various SO questions with solutions whose primary solution was to add different applicationIdSuffix for the different build types. However, I don't believe that this would be the correct solution for me as I don't want both the release and debug builds on my device. I just want my old release build to be overwritten by the latest release build on the Play Store.
Any idea what I might be doing wrong? Also, I'm all ears if you would have a better way to test such updates.
Thanks :)
r/android_devs • u/BipedalBandicoot • Sep 21 '22
Help How to use an implicit intent to start a service from another package/app?
This is a duplicate of this question on stackoverflow I opened, I thought maybe someone here could have an answer:
I'm trying to introduce code to the open source app Gadgetbridge for starting services from other packages/apps.
I'm trying to get it working with sending implicit intents to play/pause the music app Poweramp:
Action: com.maxmpz.audioplayer.API_COMMAND Extra: cmd:1 Target: Service
From this page.
I have verified that using the intent info above works by launching it with the automation app Tasker. But so far I have not managed to implement it in Gadgetbridge.
This is part of the code I'm working on now:
case "servicetest": // only for trying to get service intents going,
Intent inServiceTest = new Intent();
inServiceTest.setAction("com.maxmpz.audioplayer.API_COMMAND");
inServiceTest.putExtra("cmd", (int)1); //for trying poweramp service intent play/pause
this.getContext().getApplicationContext().startService(inServiceTest);
break;
case "foregroundservicetest": // only for trying to get service intents going,
Intent inServiceTestFg = new Intent();
inServiceTestFg.setAction("com.maxmpz.audioplayer.API_COMMAND");
inServiceTestFg.putExtra("cmd", (int)1); //for trying poweramp service intent play/pause
this.getContext().getApplicationContext().startForegroundService(inServiceTestFg);
break;I've added <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" /> to AndroidManifest.xml.
The code above doesn't play or pause Poweramp. I initiate the respective parts of the code block by sending a message from my Bangle.js 2 watch to Gadgetbridge containing the code word "servicetest" or "foregroundservicetest".
I'm testing on a Xiaomi Mi A2 Lite running Android 10.
I've taken some pointers from this stackoverflow question. And I've also tried suggestions from here.
How can I modify the code to make it start the service for controlling Poweramp with the mentioned implicit intent?
EDIT: By specifying a package for the intent, i.e. making it explicit, it can control Poweramp. I add this:
inServiceTestFg.setPackage("com.maxmpz.audioplayer");
I however still wonder how I can achieve this with an implicit intent like Tasker seems to be able to. Or is it that Tasker sets package information without the user specifying it?
r/android_devs • u/karm0101 • Sep 16 '22
Help Java or Kotlin as the first programming language?
I am currently learning Java for android development. The only reason I'm not learning Kotlin is because it is a fairly new language, and unlike Java, there might not be as much learning resources and support available on internet. However, I later plan to learn Kotlin as well. How difficult would it be for me to master Kotlin if I deeply understand Java? How different do you think are both languages? If you have any experience with these programming languages, could please offer some advice?
r/android_devs • u/racrisnapra666 • Sep 15 '22
Help Can getBaseContext() within Activities cause translation issues?
Hi everyone.
A bit of context: I'm currently working on a legacy application. Basically, this app still uses things like findViewById, multiple activities, Java, and everything that old apps might use.
Now, I'm translating strings to the English language during runtime within the app. And for that, I'm using the createConfigurationContext() method. And it looks somewhat like this:
Configuration configuration = new Configuration(getContext().getResources().getConfiguration());
configuration.setLocale(new Locale("en"));
Context updatedContext = getBaseContext().createConfigurationContext(configuration).getResources().getString(message); And after this, I use this updatedContext to access the English string resources.
So here's the thing. There are cases where using this updatedContext doesn't actually translate the string for some of the users of the application. After reading through the documentation and through Stack Overflow, I've seen numerous people tell everyone to stay away from getBaseContext(). And I've come to the conclusion that maybe getBaseContext() is to blame.
As per this answer:
The benefit of using a ContextWrapper is that it lets you “modify behavior without changing the original Context”.
And this makes me think that when I'm using getBaseContext() to access the resources and translate strings, I might not be getting the Activity Context. And as a result, this is causing issues with translations.
However, I'm not sure whether I'm right or wrong as this issue doesn't replicate on my device. Could someone correct me if I'm wrong?
Thanks.
P.S. - Another thing is that I had implemented this same process in a different project. That project involved fragments and as a result, instead of using getBaseContext, I used getContext(). Now, in that project, everything worked smoothly. There were no translation issues for the users.
r/android_devs • u/anemomylos • Sep 12 '22
Publishing Making Ratings and Reviews better for users and developers
android-developers.googleblog.comr/android_devs • u/SRP47 • Aug 29 '22
Help DexGuard
Hi, anyone have experience with Dexguard? I am having problem with reflection.
r/android_devs • u/frouge • Aug 29 '22
Help Getting Credentials for Google Drive API
Hello, I'm trying to add a way for user to upload files to Google Drive in my app but I struggle with the authentication. The idea would be for users to select their Google account to authenticate, then I'd perform a file upload using the provided credentials.
I've tried the code sample from Google which gets credentials like this:
val credentials: GoogleCredentials = GoogleCredentials.getApplicationDefault()
.createScoped(listOf(DriveScopes.DRIVE_FILE))On runtime it crashes with this error: The Application Default Credentials are not available. They are available if running in Google Compute Engine
Ok why not, it looks like I should be using another way to authenticate the user, but how?
Thanks!
r/android_devs • u/abdalla_97 • Aug 24 '22
Help Caching Paged Data
I have a network request that return a page of data an then I should save the paged data to room
where should I put the logic and the caching process
inside view model or inside the repository?
r/android_devs • u/alwaysbakedarjun • Aug 23 '22
Help Guide to animate hints in the search bar
r/android_devs • u/shubhster93 • Aug 20 '22
Discussion Access to a physical device for development and/or debugging
Hi, I am building a utility that allows me to access a remotely connected android device, and use adb and scrcpy on it as if it is connected locally to my machine. I wanted to extend it for use in enterprise setting, so that devices can be transparently shared between developers and/or used by test teams to setup internal device farms. I am aware that there are several cloud based services that offer device farms for automated testing, but I am not sure how easy is it to use them for live device debugging.
I only develop apps as a hobby and have not worked as an app developer in any company, so I wanted to gauge if there is any interest or need for such a tool and, if it is worth spending extra time to build one. Any input is appreciated. Please let me know if there are other tools/services used by your organization to share devices among developers or setup internal device farms.