Xamarin.Android: Missing aapt.exe

When trying to deploy an application to simulator or device, Visual Studio gives the following error:

Cannot find `aapt.exe`. Please install the Android SDK Build-Tools package with the `C:\Program Files (x86)\Android\android-sdk\tools\android.bat` program.

To solve this problem you sould go to Visual Studio’s Tools then Android and select SDK Manager option.

Navigate to this option

It will give an error dialog, that the SDK tool files are corrupted. Click repair.

Click on Repair

The mentioned batch command in the error message is deprecated by the way.

Microsoft Windows [Version 10.0.19042.804]
(c) 2020 Microsoft Corporation. All rights reserved.

C:\Users\banditoth>cd C:\Program Files (x86)\Android\android-sdk\tools\

C:\Program Files (x86)\Android\android-sdk\tools>android.bat
**************************************************************************
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools\bin\sdkmanager.bat
and tools\bin\avdmanager.bat
**************************************************************************

Invalid or unsupported command ""

Supported commands are:
android list target
android list avd
android list device
android create avd
android move avd
android delete avd
android list sdk
android update sdk

C:\Program Files (x86)\Android\android-sdk\tools>

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin Android: Dismiss lock screen or show activity on lock screen

To gain an Activity to be showed on the lock screen, or bypass the phone’s lock screen (aka Keyguard) for important notification handling, for example an Incoming VOIP call, you need to do the following:

Set the permission for disabling keyguard. Add the following permission to the AndroidManifest.xml:

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

Add flags to the Activity’s Window in order to show the activity on the lock screen, or to bypass the lock screen.

this.Window.AddFlags(WindowManagerFlags.DismissKeyguard | WindowManagerFlags.ShowWhenLocked);

Dismiss the keyguard if needed. (CrossCurrentActivity plugin is used to get the current activity):

KeyguardManager keyguardManager = (KeyguardManager)CrossCurrentActivity.Current.Activity?.GetSystemService(Context.KeyguardService);
if (keyguardManager != null)
{	
	keyguardManager.RequestDismissKeyguard(CrossCurrentActivity.Current.Activity, null);
}

This content has 4 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Xamarin Android: Native image scaling, images are pixelated

If you use Android’s native image scaling, from ldpi, mdpi, hdpi, to xxxhdpi, and have all the image resource in the right directory of your Xamarin.Android project folder, and find the pictures displaying pixelated: Make sure, you are correctly set the Build action for each images to AndroidResource. When adding an existing item to the resources folder from Windows version of VisualStudio’s browse dialog, the Build action will be set to BundleResource, and won’t appear in the Resources.designer.cs file, so it will be unavailable to use from code. If the picture is displaying, but it is pixelated, you may check the higher DPI version image files, have the correct buid action

This content has 4 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Android: Application auto backup ki/be kapcsolása (Xamarin is)

Android 6.0 óta (API verzió v23) bevezették az Androidba, hogy az alkalmazás fájljairól biztonsági mentést készít az operációs rendszer a felhasználó Google drive-jára. A backupok mérete maximum 25MB lehet, és az Android a JobScheduler API-jával készülnek 24 órás időintervallumban. További információk itt: https://developer.android.com/guide/topics/data/autobackup

Az érintett fájlok:

  • Shared preferences files
  • Files in the directory returned by getFilesDir()
  • Files in the directory returned by getDatabasePath(String)
  • Files in directories created with getDir(String, int)
  • Files on external storage in the directory returned by getExternalFilesDir(String)

Mivel a Xamarin Essentials a SharedPreferencesbe teszi a Preferences statikus osztály által tárolt adatokat, ezért azok is mentésre kerülnek.

A be/ki kapcsoláshoz az AndroidManifest.xml-ben a következő propertyre van szükség az application tagben:

android:allowBackup="true"
This content has 4 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.