Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Vesi
Jan 12, 2005

pikachu looking at?

Sereri posted:

Has anyone here ever come across this:

I have a webview that does not accept data via loadDataWithBaseURL(). It just stays with empty html and body tags. I can get the html code in via loadData() just fine but that won't allow me to load files from the asset folder.
Interestingly it also works fine with loadDataWithBaseURL() on my phone with an updated system webview but won't work if I uninstall the updates. Still won't help with my non-updated emulator or system webviews.

I do it like this, it was done several years ago so I no longer remember why but it's been tested on hundreds of devices:

code:
        if(blankchat == null) {
            InputStream is = null;
            try {
                is = getActivity().getAssets().open("chat/blankchat.html");
                blankchat = convertStreamToString(is);

            }catch(IOException ex) {
                Ln.e(ex, "chat/blankchat.html");
            }finally{
                if(is != null) {
                    try {
                        is.close();
                    }catch(IOException ignored) {
                    }
                }
            }
        }

        webView.loadDataWithBaseURL("file:///android_asset/", blankchat, "text/html", "utf-8", null);
with

code:
    private static String blankchat;
    static String convertStreamToString(java.io.InputStream is) {
        java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
        return s.hasNext() ? s.next() : "";
    }

Adbot
ADBOT LOVES YOU

Vesi
Jan 12, 2005

pikachu looking at?
Kotlin is good, and the java/android sdk interoperability is really seamless. Feels like a better version of Swift

Vesi
Jan 12, 2005

pikachu looking at?
how about skipping java and using clock_gettime() with CLOCK_MONOTONIC?

linux is one of the easier platforms to get monotonic time with

Vesi
Jan 12, 2005

pikachu looking at?

Taffer posted:

I started using kotlin and it is amazing. You should all use kotlin.

Vesi
Jan 12, 2005

pikachu looking at?

VostokProgram posted:

Is there anywhere I can find documentation about Android's libc implementation? I've gathered that it's called bionic and found its git repository, but an actual searchable manual like glibc has would be pretty nice...

What do you need it for? It's not like you can develop against it or do you work for a device vendor?

Vesi
Jan 12, 2005

pikachu looking at?

Volmarias posted:

You're aware of the NDK, yes?

The NDK documentation (online and in the downloaded NDK itself) is as good as you're going to get, at least as far as guaranteed promises.

NDK uses its own libc, I recall in a recent blog post they told developers not to rely on any system libraries to prevent conflicts.

For OEM it's different of course, I'd just look at the source. It's mostly POSIX anyway with some platform-irrelevant stuff missing.

Vesi
Jan 12, 2005

pikachu looking at?

Scaramouche posted:

Based on some Googling, an XBF is apparently a binary of a XAML file, which I obviously don't have since I'm not the developer of the app. Is there a way for me to generate these XBF files in Chinese?

binary XML can always be decompiled back into plaintext, your first step would be to look for a xaml decompiler to see what the files look like

Vesi
Jan 12, 2005

pikachu looking at?

FAT32 SHAMER posted:

I'm trying to verify that my app is receiving UDP traffic from port 12001 to rule out the app being broken and see if the device sending the UDP signals (a vehicle) is actually sending them. What's the best way to do this? there seems to be a lot of sniffers on the play store but they seem to require connection to a VPN and they seem to be dodgy.

I need a solution that doesnt require a rooted device as well

these are two separate problems, you can test UDP receiving by sending data with for example netcat if you're in the same network
pre:
$ echo asd|nc -u <phone-ip> 12001
remember to ask the user to disable battery optimizations first:
https://developer.android.com/training/monitoring-device-state/doze-standby.html

also UDP seems like an awful idea in 2017, but maybe you don't have a choice?

Vesi
Jan 12, 2005

pikachu looking at?

Hughlander posted:

For a mobile device where the time the radio is on is directly correlated to battery life, why is UDP bad? I’ve personally had to do a lot of work around batching up network traffic to give double digit battery gains and if I could have used UDP for it, I would have in a heart beat.

UDP handles firewalls/NAT very inconsistently, and if you want to do anything serious with it you'll probably re-invent the TCP wheel badly. With TCP you already have full control over how often you send the connection keepalive packets (if you control the server that is) so there shouldn't be any battery saving either.

UDP is great for:
* If your bandwidth is so tiny you can't handle the ~40 bytes in response packets
* If your data is literally garbage and can afford to throw it into a black hole without ever knowing what happens to it
* DNS

Vesi fucked around with this message at 21:31 on Jul 11, 2017

Vesi
Jan 12, 2005

pikachu looking at?
make sure a "Save" button is actually necessary too, it's a bit of an old paradigm

Vesi
Jan 12, 2005

pikachu looking at?
The sunflower sample app is a good starting point for new apps I think, it has all the latest things being used as they're supposed to

https://github.com/googlesamples/android-sunflower

Vesi
Jan 12, 2005

pikachu looking at?

baka kaba posted:

Java code:
override fun onClick(v: View?) {
   val amountTv: EditText = view!!.findViewById(R.id.editTextAmount)
   val amount = amountTv.text.toString().toInt()
   val action = SpecifyAmountFragmentDirections.confirmationAction(amount)
   action.amount = amount
   v.findNavController().navigate(action)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    val tv: TextView = view.findViewById(R.id.textViewAmount)
    val amount = ConfirmationFragmentArgs.fromBundle(arguments).amount
    tv.text = amount.toString()
}
I might have tunnel vision from doing my own but this feels unwieldy compared to navigate(NavigationEvent(paramsForThisEventType)) and val event: NavigationEvent? = intent.parse(). I'm happy to rework it if it fits but it doesn't feel great

You have an unnecessary assignation there, you can just

Java code:
override fun onClick(v: View?) {
   val amountTv: EditText = view?.findViewById(R.id.editTextAmount) ?: return
   v.findNavController().navigate(SpecifyAmountFragmentDirections.confirmationAction(amountTv.text.toString().toInt()))
}

Vesi
Jan 12, 2005

pikachu looking at?

FAT32 SHAMER posted:

YES AND ITS DRIVING ME loving CRAZY WHEN WORKING WITH LINEAR LAYOUTS

I thought I was losing my mind

I don't know if this is related but I use Code->Reformat Code a lot and I noticed it was rearranging tags making it useless for linearlayout

I fixed it by setting Settings->Editor->Code Style->XML->Set from...->Predefined Style->Android

Vesi
Jan 12, 2005

pikachu looking at?

Shadow0 posted:

I'm trying to give my app an option to pick the language, but it's proving to be a lot more difficult than I thought.

code:
Activity context = getActivity();
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);

Configuration configuration = context.getResources().getConfiguration();
configuration.setLocale(locale);

//context.createConfigurationContext(configuration); // This does not seem to do anything

//context.getResources().updateConfiguration(configuration, context.getResources().getDisplayMetrics()); // This works, but is "depreciated"

context.recreate();
I'm also running into the issue that recreating the Activity breaks everything. The fragment doing the language setting is sitting in a ViewPager, and when the Activity gets remade, the ViewPager gets set to null, so when I change the page with a button, it crashes. It also does an annoying double blink thing while it's reloading, and only actually sets the language on the second time I set the language.

Is there a better way to do this?

Googling the problem gives me a lot of results how to change my phone settings. It's annoying sometimes that the language and the OS have the same name.

The android way is to just let the OS decide the language but I've done this for testing purposes (API 24+ only):

code:
/**
 * to change language in activity:
override fun attachBaseContext(newBase: Context?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && newBase != null) {
super.attachBaseContext(MyContextWrapper.wrap(newBase, Locale("fi")))
return
}
super.attachBaseContext(newBase)
}
 */

class MyContextWrapper(base: Context) : ContextWrapper(base) {
    companion object {
        @RequiresApi(Build.VERSION_CODES.N)
        fun wrap(context: Context, newLocale: Locale): MyContextWrapper {
            context.resources.configuration.setLocale(newLocale)
            val localeList = LocaleList(newLocale)
            LocaleList.setDefault(localeList)
            context.resources.configuration.setLocales(localeList)
            val ret = context.createConfigurationContext(context.resources.configuration)
            return MyContextWrapper(ret)
        }
    }
}

Vesi
Jan 12, 2005

pikachu looking at?
I have a similar setup and it works with 4.1.0, maybe if you don't have variants with different versionnames you can just have it under defaultconfig like I have:

code:
    defaultConfig {
        ...
        resValue "string", "app_version", "${versionName}"
    }

Vesi
Jan 12, 2005

pikachu looking at?

Twerk from Home posted:

Is okhttp still the de-facto default http client option? Is there anything else out there?

I spent the day dealing with a nasty bug caused by people trying to work around old okhttp bugs like https://github.com/square/okhttp/issues/3146 and https://github.com/square/okhttp/issues/3974, and it only reproduced on Android 9. Of course, I have test devices on android 7, 8, 10, and 11 but not 9, so it was a PITA to debug. It's crazy to me that making http requests is this fraught at this point in Android's lifecycle.

I have a pretty high trust in jetbrains so if I started a new project I'd try https://ktor.io/docs/clients-index.html
you can plug in okhttp engine into it too

Vesi
Jan 12, 2005

pikachu looking at?

Tuxedo Gin posted:

Thank you so much for the reply. I'll do some more reading and research into PAD. It checks a lot of boxes, though it looks like I have to upload everything in a pack to the play store, which means if I change one of the packages, I'd have to submit the entire app for an update. Is there any way to pull assets from my own servers so I can control them and make changes on the fly and handle the download/storage/update within the app? Or is that not possible for security reasons?

trying to protect data from a hostile user who has root access, can edit bytecode and intercept network requests is pretty hopeless and wasted effort, just put data in Context.getExternalFilesDir(), smaller structured data into sqlite and have the app delete them when subscription is inactive

I remember in 2010 I had paid downloads be encrypted with public keys, I expected it would thwart a 12 year old hacker but not a 14 year old

Vesi fucked around with this message at 07:20 on Jan 26, 2021

Vesi
Jan 12, 2005

pikachu looking at?

Good Sphere posted:

How easy is it to develop for an older version of Android, like 8? I could make different SDK settings, but does that mean I need to write older code? Is Kotlin out of the picture?

kotlin should be fine since it's just turned into jvm bytecode

biggest problem is all more modern apis will rely on androidx which requires sdk 14/15, also tls version will probably be insecure

Vesi
Jan 12, 2005

pikachu looking at?

mobby_6kl posted:

Yeah that's what I thought but it seems to actually work ok as long as I'm also not drawing anything. By mothership I just meant the main activity, though I suppose motherhood works too :)

All of this is just trying to work around the limitations android places on apps in the simplest way possible but this seem like the way to do it:



The main activity, when running, draws the data to show what's being collected. The way to return data isn't clear yet as you can tell, but I'll look into AIDL. Strictly speaking this functionality isn't really necessary, it's mostly for debugging so this half-assed solution might do the job.

If they're in the same package you don't need to bother with any IPC stuff you can get the data from the service any way you want to, you can think of it like as a singleton. just try to start the service from the activity in onCreate and it'll either start it from scratch if it's not running or just do nothing if it's already running

In onServiceConnected you'll get the definitive instance of the service, but you can also access any of its static fields anytime in the activity

If you want to use the latest practices you'll write the data into a a StateFlow/SharedFlow from the service then listen to it from the activity

Vesi
Jan 12, 2005

pikachu looking at?

Anne Bonny posted:

According to https://firebase.google.com/docs/crashlytics/ndk-reports I need to "explicitly invoke the uploadCrashlyticsSymbolFileBUILD_VARIANT task after each build of your NDK library." for method names to appear in my stack traces....

code:
>./gradlew app:assembleBUILD_VARIANT\
           app:uploadCrashlyticsSymbolFileBUILD_VARIANT
But I don't understand the build process well enough to know how to do this . I know neither where to call this command or what to call it with.

I would appreciate any guidance.

there's gradlew and gradlew.bat in the project directory (same as the toplevel build.gradle)

you don't have any variants so you'd be running from the commandline:

gradlew assembleRelease uploadCrashlyticsSymbolFileRelease

or Debug instead of Release for debug build

Adbot
ADBOT LOVES YOU

Vesi
Jan 12, 2005

pikachu looking at?
I switched to jetpack compose recently specifically to get away from recyclerview,, if you're just learning then maybe it's better to stick to the latest paradigms?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply