mardi 29 janvier 2019

In Kotlin, how to force the locale ?

Here is a project that has been converted from Java to Kotlin and that allows you to set the Locale at runtime in any Kotlin project :

https://github.com/reuniware/Kotlin-LocaleManager


jeudi 24 janvier 2019

Projet Kotlin utilisant Room, LiveData Observer et RecyclerView.

Voici un projet minimaliste utilisant AndroidX et permettant d'apprendre l'utilisation de la librairie de persistance des données ROOM, de voir comment utiliser les observateurs LiveData et comment utiliser le RecyclerView (qui affiche les données provenant d'une table simple).

Cliquez-ici pour accéder au projet sur GitHub (Room_LiveData_RecyclerView_Tutorial)


mercredi 23 janvier 2019

Android : Kotlin, Room et Observer LiveData, projets de base minimalistes

Si vous souhaitez apprendre Kotlin et Room, grâce à un projet très minimaliste mais fonctionnel, voici un projet sur GitHub qui peut vous guider dans votre apprentissage :

Projet AndroidRoomTutorial sur GitHub

Si vous souhaitez découvrir en plus la notion de LiveData et d'Observer, voici un projet aussi très minimaliste qui permet de mettre en place un simple Observer, toujours en langage Kotlin sous Android Studio :

Projet Android-RoomLiveDataTutorial sur GitHub


Android Studio, Kotlin and Room persistence library easy tutorial

I have coded a very basic project using Room persistence library in Kotlin language, in Android Studio.

You can access the source code (very easy to understand) by clicking here.

vendredi 18 janvier 2019

How to list installed packages on an Android device with "adb shell"

In order to list all Android packages (applications) that are installed on an Android device, launch the "adb shell" command from Windows, and when connected on the Android device, launch the "pm list packages" command.

An example of output is :

HWCMR09:/ $ pm list packages
package:com.huawei.hifolder
package:com.android.cts.priv.ctsshim
package:com.google.android.youtube
package:com.huawei.camera
package:com.huawei.android.tips
package:com.google.android.ext.services
package:com.huawei.synergy
package:com.huawei.android.launcher
package:com.android.mediacenter
package:com.android.providers.telephony
package:com.google.android.googlequicksearchbox
package:com.android.providers.calendar
package:com.huawei.hidisk
package:com.huawei.hiview
package:com.huawei.iaware
package:com.huawei.bluetooth
package:com.android.providers.media
package:com.touchtype.swiftkey
package:com.huawei.android.thememanager
package:com.huawei.android.chr
package:com.huawei.android.hsf
package:com.google.android.onetimeinitializer
package:com.google.android.ext.shared
package:com.huawei.kidsmode.kidspaint
package:com.huawei.autoinstallapkfrommcc
package:fr.reunisoft.oauth2_test
package:com.android.wallpapercropper
package:com.huawei.nearby
package:com.huawei.android.FloatTasks
package:com.huawei.desktop.systemui
package:org.simalliance.openmobileapi.service
package:com.huawei.recsys
package:com.android.documentsui
package:com.android.externalstorage
package:com.android.htmlviewer
package:com.android.companiondevicemanager
package:com.android.mms.service
package:com.huawei.android.totemweather
package:com.android.providers.downloads
package:com.huawei.gameassistant
package:com.huawei.trustcircle
package:com.ebay.carrier
package:com.huawei.phoneservice
package:com.huawei.desktop.explorer
package:com.huawei.screenrecorder
package:com.netflix.partner.activation
package:com.huawei.himovie.overseas
package:com.android.partnerbrowsercustomizations.tmobile
package:com.huawei.videoeditor
package:com.huawei.securitymgr
package:com.google.android.configupdater
package:com.android.soundrecorder
package:com.huawei.iconnect
package:com.android.defcontainer
package:com.huawei.hiviewtunnel
package:com.android.providers.downloads.ui
package:com.android.vending
package:com.android.pacprocessor
package:com.hisi.mapcon
package:androidhwext
package:com.android.frameworkhwext.honor
package:com.android.certinstaller
package:huawei.android.widget
package:com.android.carrierconfig
package:com.google.android.marvin.talkback
package:com.google.android.apps.work.oobconfig
package:android
package:com.huawei.imedia.sws
package:com.huawei.hwid
package:com.huawei.tips
package:com.android.contacts
package:com.huawei.systemserver
package:com.android.frameworkhwext.dark
package:com.android.egg
package:com.android.mms
package:com.android.mtp
package:com.android.stk
package:com.microsoft.rdc.android
package:com.android.backupconfirm
package:com.huawei.android.instantshare
package:com.huawei.indexsearch.observer
package:com.huawei.trustagent
package:com.android.statementservice
package:com.huawei.indexsearch
package:com.google.android.gm
package:com.google.android.apps.tachyon
package:com.huawei.android.internal.app
package:com.example.my.roomwordsample
package:com.huawei.hwasm
package:com.huawei.omacp
package:com.android.calendar
package:com.huawei.wifiprobqeservice
package:com.google.android.setupwizard
package:com.android.providers.settings
package:com.android.sharedstoragebackup
package:com.facebook.services
package:com.google.android.music
package:com.android.printspooler
package:com.android.frameworkres.overlay
package:com.android.dreams.basic
package:com.activity.screen.reuniwaretransfer
package:com.android.incallui
package:com.huawei.systemmanager
package:com.android.inputdevices
package:com.android.bips
package:com.android.supl
package:com.google.android.apps.docs
package:com.google.android.apps.maps
package:com.android.cellbroadcastreceiver
package:com.google.android.webview
package:com.huawei.HwMultiScreenShot
package:com.huawei.vassistant
package:com.android.server.telecom
package:com.google.android.syncadapters.contacts
package:com.example.android.notepad
package:com.android.keychain
package:com.android.keyguard
package:com.android.chrome
package:com.android.gallery3d
package:com.google.android.packageinstaller
package:com.huawei.watch.sync
package:com.google.android.gms
package:com.google.android.gsf
package:com.google.android.tts
package:com.huawei.hwstartupguide
package:com.android.calllogbackup
package:com.google.android.partnersetup
package:com.huawei.fido.uafclient
package:com.google.android.videos
package:com.android.proxyhandler
package:com.huawei.android.mirrorshare
package:com.huawei.contactscamcard
package:com.google.android.feedback
package:com.google.android.printservice.recommendation
package:com.google.android.apps.photos
package:com.google.android.syncadapters.calendar
package:com.android.managedprovisioning
package:com.swiftkey.swiftkeyconfigurator
package:com.huawei.android.totemweatherwidget
package:com.huawei.compass
package:com.android.dreams.phototable
package:com.android.providers.partnerbookmarks
package:com.huawei.android.hwaps
package:com.huawei.android.hwouc
package:com.huawei.android.wfdft
package:com.android.wallpaper.livepicker
package:com.huawei.mmitest
package:com.huawei.powergenie
package:com.facebook.system
package:com.google.android.backuptransport
package:com.android.storagemanager
package:com.android.bookmarkprovider
package:com.android.settings
package:com.android.calculator2
package:com.huawei.android.projectmenu
package:com.huawei.android.totemweatherapp
package:com.android.cts.ctsshim
package:com.huawei.sarcontrolservice
package:com.huawei.android.pushagent
package:com.android.vpndialogs
package:com.android.email
package:com.android.phone
package:com.android.shell
package:com.android.wallpaperbackup
package:com.android.providers.blockednumber
package:com.android.providers.userdictionary
package:com.huawei.wifieapsimplmn
package:com.android.emergency
package:com.huawei.scanner
package:com.android.location.fused
package:com.android.deskclock
package:com.android.systemui
package:com.android.exchange
package:com.android.bluetoothmidiservice
package:com.facebook.appmanager
package:com.huawei.hwdetectrepair
package:com.huawei.bd
package:com.android.bluetooth
package:com.android.providers.contacts
package:com.android.captiveportallogin


mardi 15 janvier 2019

Android Java : How to delete SMS




    public void deleteSMS(Context context, String message, String number) {
        try {
            Log.d("MsgService","Deleting SMS from inbox");
            Uri uriSms = Uri.parse("content://sms/inbox");
            Cursor c = context.getContentResolver().query(uriSms, new String[] { "_id", "thread_id", "address", "person", "date", "body" }, null, null, null);

            if (c != null && c.moveToFirst()) {
                do {
                    long id = c.getLong(0);
                    long threadId = c.getLong(1);
                    String address = c.getString(2);
                    String body = c.getString(5);

                    Log.d("MsgService", address + " /// " + body);

                    if (/*message.equals(body) && */address.equals(number)) {
                        Log.d("MsgService","Deleting SMS with id: " + threadId);
                        context.getContentResolver().delete( Uri.parse("content://sms/conversations/" + id), null, null);
                    }
                } while (c.moveToNext());
            }
        } catch (Exception e) {
            Log.d("MsgService","Could not delete SMS from inbox: " + e.getMessage());
        }
    }

How to resolve Android Studio Error "The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher."

In order to resolve this error message, you will have to upgrade the Gradle version in the "build.gradle" file.

I have had this error after updating Android Studio to the latest release and the Gradle plugin too.

I have then checked what is the latest version of Gradle on the following page : https://bintray.com/bintray/jcenter/org.jetbrains.kotlin%3Akotlin-gradle-plugin

And I found that the latest version is the 1.3.11

Then I opened the "build.gradle" file in my Android Studio project and I modified the line "ext.kotlin.version = '1.2.71'" to "ext.kotlin.version = '1.3.11'".

That did the trick !


jeudi 3 janvier 2019

C# HttpWebRequest extremely slow ? Here is the easy quick fix.

I have just found on StackOverflow that there is a very easy solution to boost the time of execution of an Http web request : Setting the proxy property of the HttpWebRequest object to null, as in he example that follows :

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"http://192.168.1.254:8080/api/SuperRestAPI");
            req.Proxy = null;
            req.Timeout = 5000;
            req.Method = "POST";
            req.ContentType = "text/json";
            using (var streamWriter = new StreamWriter(req.GetRequestStream()))
            {
                string json = JsonConvert.SerializeObject(loginRequest);
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }


Another far more elegant solution is setting the defaultProxy enabled parameter to false in the App.Config, as explained in the following Microsoft page :
https://docs.microsoft.com/fr-fr/dotnet/framework/configure-apps/file-schema/network/defaultproxy-element-network-settings