Can’t create file
Need to add android:requestLegacyExternalStorage=”true”
https://developer.android.com/training/data-storage/use-cases#opt-out-scoped-storage
<application
...
android:requestLegacyExternalStorage="true">
Can’t get hardware serial number
App crashes when calling Build.getSerial()
best-practices-android-identifiers https://developer.android.com/reference/android/os/Build#getSerial()
changes-to-device-identifiers-in.html
The user 10180 does not meet the requirements to access device identifiers.
Use ANDROID_ID for Android 10, 11; Build.getSerial() for lower Android
private String getAndroidId() {
return Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ANDROID_ID);
}
Can’t download file using DownloadManager
Error when dowloading file using setDestinationInExternalPublicDir
Not one of standard directories: /packagename/files
setDestinationInExternalPublicDir
String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test/files"; // /storage/emulated/0/test/files
if (Build.VERSION.SDK_INT >= 29) {
// Android 10, 11
Uri dstUri = Uri.parse("file://" + storagePath + File.separator + targetFilename);
dm.enqueue(request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle("File Downloading...")
.setDescription("File Download")
.setDestinationUri(dstUri));
} else {
dm.enqueue(request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle("File Downloading...")
.setDescription("File Download")
.setDestinationInExternalPublicDir("/test/files", targetFilename));
}
Camera stops saving image
Before (Xamarin)
takePictureIntent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(imageFile));
After (Xamarin)
var context = MainActivity.Instance.ApplicationContext; var imageUri = AndroidX.Core.Content.FileProvider.GetUriForFile(context, context.PackageName + ".provider", imageFile); takePictureIntent.PutExtra(MediaStore.ExtraOutput, imageUri);
Leave a Reply