android-10.0

PreferenceManager getDefaultSharedPreferences deprecated in Android Q

你说的曾经没有我的故事 提交于 2020-07-16 16:18:48
问题 PreferenceManager getDefaultSharedPreferences is deprecated in Android Q , how do I replace it? 回答1: You can use AndroidX support library version of PreferenceManager, i.e. androidx.preference.PreferenceManager and not android.preference.PreferenceManager . remember to add the following to your build.gradle. implementation 'androidx.preference:preference:1.1.1' 回答2: Package preference provides the androidx PreferenceManager: Java: implementation "androidx.preference:preference:1.1.1" Kotlin:

AndroidX : Parcelable encountered IOException writing serializable object only in Android version 10 devices

故事扮演 提交于 2020-07-08 11:51:41
问题 I got Parcelable encountered IOException writing serializable object and it caused by java.io.NotSerializableException: androidx.appcompat.widget.Toolbar error only in Android Version 10 devices. I've searched many results for getting solutions to this problem but every solution I got, was telling to define implement serializable in both inner class and sub inner class and I've done it, still, I got this error only in Android version 10 devices. If I will use transient this keyword to define

Android 10: fetch the gallery via MediaStore with location information

二次信任 提交于 2020-07-04 13:50:30
问题 Looking at the storage access changes introduced in Android 10 here, location informations are now redacted by default. Google asks us to call setRequireOriginal() on the "MediaStore" object with the media's uri as a parameter. This works when you fetch medias one by one, but what about when we query the ContentResolver for the whole gallery? See this sample: String[] projection = { MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.MEDIA_TYPE,

Media scanner for secondary storage on Android Q

狂风中的少年 提交于 2020-07-04 06:45:29
问题 With the newer Android Q many things changed, especially with scoped storage and gradual deprecation of file:/// URIs. The problem is the lack of documentation on how to handle media files correctly on Android Q devices. I have a media file (audio) management application and I could not find yet a reliable way to tell to the OS that I performed a change to a file so that it can update its MediaStore record. Option #1: MediaScannerService MediaScannerConnection.scanFile(context, new String[]{

Android 10: Able to upload a Uri directly but fails with “Permission denial” exception when re-attempted later

妖精的绣舞 提交于 2020-06-29 04:54:05
问题 Using a FilePicker I am able to have the user choose a file to upload, pass it to an IntentService, and upload it immediately via that intentService if device has network. But if there is no network, I need to save the Uri and attempt upload later once the devices gets network. This re-attempt is failing. It throws "Permission denial" exception when I try to start the service during the re-attempt. Please let me know what might be wrong. Appreciate your help. FILEPICKER -----------

Unexpected behavior when DocumentFile.fromTreeUri() is called on Uri of subdirectory DocumentFile object

不想你离开。 提交于 2020-06-29 03:42:09
问题 If I call DocumentFile.fromTreeUri() on main directory and I list its content, it returns all DocumentFile object related to folders and files contained in the directory as expected, but when I try to call DocumentFile.fromTreeUri() on the Uri of one of the DocumentFile folders inside it, rather than returning all DocumentFile objects related to folders and files contained in the subdirectory as expected, it actually returns exactly the same content of the call on its root Uri E.g. I have a

Android 10 request permission for ACTIVITY_RECOGNITION

六月ゝ 毕业季﹏ 提交于 2020-06-28 10:18:42
问题 I'm trying to comply with the Google requirements to request the permission ACTIVITY_RECOGNITION, for Android 10, but I don't seem to understand why there's no permission popup showing , like with the other permissions (ie, Location, storage,...) The code I have is: if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION) != PackageManager.PERMISSION_GRANTED) { Log.d("TAG", "PERMISSION 'ACTIVITY_RECOGNITION' NOT GRANTED"); ActivityCompat.requestPermissions(this,

Android 10 Activity onCreate Crash

▼魔方 西西 提交于 2020-06-23 03:36:27
问题 The splash activity of my app works well on all devices except on an Android 10 device that I have just recently updated. Here is my code: public class SplashScreen extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(FirebaseAuth.getInstance().getUid() != null) startActivity(new Intent(this, HomeActivity.class)); else startActivity(new Intent(this, LoginActivity.class)); finish(); } } I have also tried navigating

Foreground service is killed in Android 10

醉酒当歌 提交于 2020-06-17 13:13:05
问题 In Android 10, some manufacturer comes with the new feature in a battery optimization setting (see the picture). My foreground service getting killed by OS after some time when the screen is off. I have used the foreground service with notification. This code is working well when the screen is ON in all devices. I am facing this issue in OnePlus and realMe device, both having an android 10 OS. I want to know, Is there any way to solve this problem? Is there any way to know in my device is

Android Studio MediaStore, below SDK 29 save image in sd card fails

吃可爱长大的小学妹 提交于 2020-06-17 09:31:46
问题 I need to save image in sd_card's pictures directory below Android 10.I have implemented scoped storage & This code works in sdk 29 & above, because MediaStore.getExternalVolumeNames was added in sdk 29. Below sdk 29 how to get getContentUri of sd_card . val values = ContentValues().apply { put(MediaStore.Images.Media.DISPLAY_NAME, destinationFileName) put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg") put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + File