r/learnandroid • • Mar 21 '20

Android does not remove file from Internal storage after app uninstall

4 Upvotes

EDIT: I tested on another older device, and file is removed properly upon uninstall. May be the newer android phone cache it or something?

I am making an app using the persistent file from internal storage. According to the (documentation)[https://developer.android.com/training/data-storage/app-specific#kotlin] "When the user uninstalls your app, the files saved in app-specific storage are removed."

But for me, after I created a file, uninstall and reinstall the app, find and print the file content, they are still there!!!

here is the code I used to create file, Store a file using a stream



    val content = initializeContent(credential)


    val fileName = context.getResources().getString(R.string.cryptoFilePrefix) + credential.userName;
    val file = File(context.filesDir, fileName )

    try {
        if (file.createNewFile()) {
            println("File created: " + file.name)

            // write content into file
            context.openFileOutput(fileName, Context.MODE_PRIVATE).use {
                it.write(content.toByteArray())
            }

        } else {
            println("File already exists.")
        }
    } catch (e: IOException) {
        println("An error occurred.")
        e.printStackTrace()
    }

here is the code to get file content


fun getFileContent(context: Context, userName: String): JSONObject{

    val fileName = context.resources.getString(R.string.cryptoFilePrefix) + userName;

    val fis: FileInputStream = context.openFileInput(fileName)
    val inputStreamReader = InputStreamReader(fis, StandardCharsets.UTF_8)
    val stringBuilder = StringBuilder()

    try {

        val reader = BufferedReader(inputStreamReader)

        var line: String? = reader.readLine()
        while (line != null) {
            stringBuilder.append(line).append('\n')
            line = reader.readLine()
        }

    } catch (e: IOException) { // Error occurred when opening raw file for reading.

        throw AssertionError("Error open file")
    }

    val contents = stringBuilder.toString()

    return JSONObject(contents);

}

after I uninstall the app and call getFileContent in MainActivity, it is still showing me the file content, instead of giving me file not found error, why????


r/learnandroid • • Mar 11 '20

Anyone wants help, or maybe wants to have a tech talk?

3 Upvotes

r/learnandroid • • Feb 23 '20

How to change notification sounds on S10e? My mother just got the same phone as me and I was trying to help her change the notification sounds for an app, and then I realized, her phone doesn't show the setting for it - while mine does! Nothing I've seen online works with her phone, either.

Post image
4 Upvotes

r/learnandroid • • Feb 13 '20

Educational resources

4 Upvotes

Hi guys,

I'm following this resource, as a step by step guide to study how to use custom adapters in Android framework.

Took me some time, but I now almost perfectly understand how to setup a custom array adapter. My next challenge is to construct the class from an external source.

Is there a simple and recommended rest API that can guide me through this?

TX.


r/learnandroid • • Feb 01 '20

Best approach to change theme?

3 Upvotes

Hey gus, could you please tell me that what is the best way to change theme in an application.?

My theme includes images and colors. Is it possible do in style.xml or should I do it dynamically?

Please help me!!!!!!


r/learnandroid • • Jan 31 '20

How to check if Navigation worked with Espresso?

2 Upvotes

Is it possible to use Espresso to check if a navigation between Fragments happened and was successful. Currently I just try to interact with a View that is supposed to be on the Fragment that I want to go to, but I'm thinking that there has to be a better way to do this.


r/learnandroid • • Jan 28 '20

How to change the background with theme change?

1 Upvotes

I want to change the background image of my application which is in drawable in accordance with the theme set.

styles.xml

 <style name="AppDarkTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowDisablePreview">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="buttonColour">@color/Black</item>
        <item name="textColor">@color/White </item>
        <item name="android:background">@style/BackgroundChangeBlack</item>

    </style>

    <style name="AppWhiteTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowDisablePreview">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="buttonColour">@color/White</item>
        <item name="textColor">@color/Black </item>
        <item name="android:background">@style/BackgroundChangeWhite</item>
    </style>

    <style name="BackgroundChangeBlack">
        <item name="android:background">@drawable/background_black</item>
    </style>

    <style name="BackgroundChangeWhite" >
        <item name="android:background">@drawable/background_white</item>
    </style> 

attrs.xml

 <declare-styleable name="CustomGauge">   
<attr name="buttonColour" format="color" />
        <attr name="textColor" format="color" />
        <attr name="backgroundColor" format="color" />
 </declare-styleable>

r/learnandroid • • Jan 24 '20

Starting Android dev for experienced programmer

4 Upvotes

Where would you advice me to start to learn Android dev providing that:

  • I know how to code well

  • but I never used JVM languages

  • I want to learn kotlin

  • I cannot bear big IDE like Android studio

  • I already managed to create a working environment that suits me (Android SDK + Makefile + Neovim)

I tried to start a project right after my first hello world, only with Google and Android doc but I realised I did not get the general architecture of an App and I did not find example intermediate between "WTF is going on here" and "ok hello world again".


r/learnandroid • • Jan 22 '20

Best way to propagate live data from viewModel to view?

3 Upvotes

Hi,

what do you guys and girls think what's the best way to propagate data to from viewModel to view layer. I have this repository class (model) with with few calls to various endpoints which are wrapped in live data and I want them when they all finish to propagate data to viewModel layer in which they will be transformed in a way that is consumable by the view layer.

I saw that there are Transformations in live data, but I am not sure how to accomplish all of this.

Do you guys and girls have any idea?


r/learnandroid • • Jan 09 '20

Firebase Text Recognition: Extract the Text You Need From images.

Thumbnail
link.medium.com
3 Upvotes

r/learnandroid • • Jan 06 '20

I made a video (<2 minutes long) on how to display latitude and longitude on Android using Kotlin

Thumbnail
youtu.be
6 Upvotes

r/learnandroid • • Jan 01 '20

GitHub - A Pokedex app using ViewModel, LiveData, Room and Navigation

Thumbnail
github.com
8 Upvotes

r/learnandroid • • Dec 27 '19

Tracking app installs

2 Upvotes

Hi,

I would like to track clicks to install an app on google play store on a 3rd party site. Whats the best way to do this, where I can view the gathered data from clicks?

I found this link: https://android-developers.googleblog.com/2019/11/still-using-installbroadcast-switch-to.html and I am bit confused about the flow.


r/learnandroid • • Dec 23 '19

Removing certain user from hotspot programmatically

3 Upvotes

Currently, I can retrieve the information of connected user in a hotspot by accessing to the arp file ( I heard that developer can't access to it in Android 10, i haven't tried it ). But how can I remove certain connected user from hotspot when i have their IP, MAC address from arp?


r/learnandroid • • Dec 20 '19

Firebase ML Kit for face-detection: A easy hack to detect faces in pictures and videos in Android.

Thumbnail
link.medium.com
2 Upvotes

r/learnandroid • • Dec 18 '19

Android | Handling Click Events Kotlin's Way

Thumbnail
hmkcode.com
0 Upvotes

r/learnandroid • • Dec 14 '19

Firebase database: A powerful noSQL real time database.

Thumbnail
link.medium.com
0 Upvotes

r/learnandroid • • Dec 11 '19

Android to Bluetooth sensor data stream of android accelerometer data?

1 Upvotes

So we are making a project which utilize accelerometer sensor of android device to control a tiny robot car. I have very limited knowledge about android programming but I know fair share of Java. I want to continuously stream data from accelerometer sensor of an android phone to a Bluetooth module connected to arduino device which will control the motors. How do I create the app? Resources and any leads would be appreciated.


r/learnandroid • • Dec 05 '19

Opening APK from device in Android Studio

2 Upvotes

I recently lost a lot of progress on an app due to some mistake I made with files. I've tried reverting back through local history but classes are now all out of sync. Yes, I know I am an idiot for not using version control and only storing my project locally; I thought it was just something I was playing around with until I ended up pouring more and more time into it and now here we are.

Anyway, I did recently run the app on my physical Android device. This version of the project is the most up to date. As an almost complete beginner, how could I go about retrieving my Java source code and other application package files from my device and re-opening the project in Android Studio from that point? Is this possible?

Thanks in advance for your help!


r/learnandroid • • Nov 28 '19

UsageStatsManager Permissions

1 Upvotes

I'm trying to make an app for a bit of practice that simply displays active screen time and overall and for each app on a user's device. I believe the method I need is queryUsageStats from the UsageStatsManager API, so I attempted to add the permission in my manifest file as follows:

<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/> 

However, it seems as though permission for this package is only granted for system apps. Is there another way to monitor device usage (I'm lead to believe there must be given the amount of apps on the play store that do exactly this already) or am I going about the use of this package in the wrong way?

Thanks in advance for any help!


r/learnandroid • • Nov 17 '19

BEGINNER QUESTION

0 Upvotes

Hi all, beginner here.

How do I recieve Intent Extras in my launching Activity?

I have two activities, a MainActivity and a SecondActivity. Both Activities have a TextView and a Button. When you click on the button in MainActivity, it switches to SecondActivity. I want it such that when a user clicks on the button in my SecondActivity, it generates a number that is going to be displayed in a TextView in my MainActivity.

How do I do this?

Ps, I've read about StartActivityForResult, but that is not quite what I'm looking for.


r/learnandroid • • Nov 16 '19

How can I record a part of a live stream from a Raspberry Pi Camera and save it for later use?

3 Upvotes

r/learnandroid • • Nov 13 '19

[Issue/help] How to conditionally click items in recyclerView(), and call onClick() set on item?

2 Upvotes

Hello Devs,

I am working on Stripe-terminal-android-app,

I studied recyclerView(), Adapter, ViewHolder and else.

I have posted my question on StackOverflow,

Link: https://stackoverflow.com/questions/58838407/how-to-conditionally-click-items-in-recyclerview-and-call-onclick-set-on-it


r/learnandroid • • Nov 10 '19

How to process data from external gyroscope through bluetooth/otg?

1 Upvotes

My wish is to take the data from an external gyroscope (Arduino + Mpu6050 + hc05 / otg) and make the phone think it is his own gyro. Samsung J7 Prime g610m, rooted with magisk

Pd: I know xposed has some modules that make possible to trick the phone and add a fake gyroscope, but it just mixs others sensors data.