is_pending update is crashing for samsung device in Android 11 - android

I'm facing a weird crash in the Samsung device only.
See the stacktrace below,
Fatal Exception: com.pilabs.musicplayer.tageditor.TagEditFailedException: Tag edit failed : Changing volume from /storage/3964-3431/Music/Bujji-MassTamilan.io.mp3 to /storage/emulated/0/Music/.pending-1608532169-Bujji-MassTamilan.io.mp3 not allowed
at com.pilabs.musicplayer.tageditor.PiTagEditor.handleException(PiTagEditor.java:643)
at com.pilabs.musicplayer.tageditor.PiTagEditor.editTrackTagInfoImpl(PiTagEditor.java:217)
at com.pilabs.musicplayer.tageditor.PiTagEditor.access$setUiCallback$p(PiTagEditor.java:37)
at com.pilabs.musicplayer.tageditor.PiTagEditor$editTrackTagInfo$1.invokeSuspend(PiTagEditor.java:79)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:238)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$createdWorkers(CoroutineScheduler.java:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:742)
Where TagEditFailedException is my own Written Exception. Actual exception being,
java.lang.IllegalArgumentException: Changing volume from /storage/3964-3431/Music/Bujji-MassTamilan.io.mp3 to /storage/emulated/0/Music/.pending-1608532169-Bujji-MassTamilan.io.mp3 not allowed
More than anything, look for
Changing volume from /storage/3964-3431/Music/Bujji-MassTamilan.io.mp3 to /storage/emulated/0/Music/.pending-1608532169-Bujji-MassTamilan.io.mp3 not allowed
I debugged the code and found that the app is crashing when updating IS_PENDING before updating other metadata.
private fun updateNameChangesInAndroidDb(application: Application, editTrackTagInfo: EditTrackTagInfo) {
val uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
editTrackTagInfo.trackId.toLong())
val contentValues = ContentValues()
if (hasQ()) {
contentValues.put(MediaStore.Audio.Media.IS_PENDING, 1)
application.contentResolver.update(uri, contentValues, null, null)
}
contentValues.clear()
if (hasQ())
contentValues.put(MediaStore.Audio.Media.IS_PENDING, 0)
with(editTrackTagInfo) {
title?.let { it -> contentValues.put(MediaStore.Audio.Media.TITLE, it) }
album?.let { it -> contentValues.put(MediaStore.Audio.Media.ALBUM, it) }
artist?.let { it -> contentValues.put(MediaStore.Audio.Media.ARTIST, it) }
}
val rowsUpdated = application.contentResolver.update(uri, contentValues,
null, null)
app crashes at
application.contentResolver.update(uri, contentValues, null, null)
while updating IS_PENDING to 1 in
if (hasQ()) {
contentValues.put(MediaStore.Audio.Media.IS_PENDING, 1)
application.contentResolver.update(uri, contentValues, null, null)
}
I don't understand why updating is_pending would change the volume from SD_Card to internal storage (/storage/emulated/0...).
App crashes only on Android 11 devices. That too on Samsung device only. That too when the track I'm trying to edit is from SD-CARD.
I have tried with Android 11 pixel devices and it works fine.
The track which I'm trying to edit is in SdCard at location
/storage/3964-3431/Music/Bujji-MassTamilan.mp3
I don't understand why while updating IS_PENDING to 1 in samsung android 11 device, root location of media is changing to internal storage
/storage/emulated/0/Music/...
Summary - App crashes only in Android 11 Samsung device when media-file is from SD-Card.

Related

How can I insert a ringtone in MediaStore when wrapping apk with Mobile Iron?

We're using Mobile Iron to wrap our app.
I'm facing problems while inserting a ringtone in the MediaStore.
I've read many questions but none are up-to-date: Indeed, MediaStorage.Audio.Media.DATA is deprecated since Android 10 (Q). Moreover, it seems that, searching for a solution, in "Post" Android Q, the content Uri has to be accessed another way.
So I have to separate code for "Pre" and "Post" Android Q.
Here is my code:
val collection = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
} else {
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
}
val values = ContentValues()
values.put(MediaStore.Audio.Media.TITLE, ringtoneName)
values.put(MediaStore.Audio.Media.DISPLAY_NAME, "ringtone.wav"))
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/x-wav")
values.put(MediaStore.Audio.Media.IS_RINGTONE, true)
values.put(MediaStore.Audio.Media.IS_MUSIC, false)
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false)
values.put(MediaStore.Audio.Media.IS_ALARM, false)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
Log.e("Ringtone", "Android 9 : Extracting file in external Storage")
extractRingtone(context)
var file: File? = null
try {
file = File(context.getExternalFilesDir(Environment.DIRECTORY_RINGTONES)!!.canonicalFile, "ringtone.wav")
} catch (e: IOException) {
e.printStackTrace()
}
values.put(MediaStore.Audio.Media.SIZE, file?.length())
values.put(MediaStore.Audio.Media.DATA, file?.absolutePath)
}
else
{
val inputStream = context.resources.openRawResource(R.raw.ringtone)
val size = inputStream.available()
values.put(MediaStore.Audio.Media.SIZE, size)
inputStream.close()
values.put(MediaStore.Audio.Media.IS_PENDING, true)
}
var newUri: Uri? = null
try {
newUri = resolver.insert(collection, values)
}
catch (exception: Exception)
{
Log.e("Ringtone", "Exception while inserting data", exception)
}
Then, in "Post" Android Q, I try to insert the ringtone in the content provider using resolver.openOutputStream(newUri), and then, update the ringtone with MediaStore.Audio.Media.IS_PENDING set to ````false``` but newUri is always null and Exception is never thrown.
The code works correctly when the app isn't wrapped.
Any idea?
Edit: Added MediaStore.Audio.Media.IS_PENDING value in ContentValues, but it didn't do the trick.
Edit 2: Updated question as we now the problem isn't the code but the wrapping of the app using Mobile Iron.
As pointed by #blackapps , the code works correctly, indeed. The thing I didn't mention is that the app is "wrapped" using Mobile Iron. When not wrapped, the code works normally and I don't get the error.
Thanks to him, I came to the conclusion that the wrapping of the app causes my problem, as it makes the app sandboxed and apparently denies the write of any file in the phone.
Anyway, this is not a problem with Android nor Kotlin, but with Mobile Iron.
So I updated my question, its tags and its title.

Android build problem when I clear app data?

I made a mini mobile game on Unity3d. It has many scenes (each level in the game is a scene). the levels start from scene number 1 but there is a scene number 0 which contains an empty that has a script attached to it "Level0".
public class Level0 : MonoBehaviour
{
public int levelIndex;
public IEnumerator delayCoroutine()
{
yield return new WaitForSeconds(1f);
SceneManager.LoadSceneAsync(levelIndex);
}
void Awake()
{
levelIndex = SaveLoadManager.loadCurrentLevelIndex();
StartCoroutine(delayCoroutine());
}
}
the role of this script is to call a static function from "SaveLoadManager" which returns the next level index (scene index in the build settings).
public static int loadCurrentLevelIndex()
{
if (File.Exists(Application.persistentDataPath + "/data.txt"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream stream = new FileStream(Application.persistentDataPath + "/data.txt", FileMode.Open);
PlayerDataSerializable data = bf.Deserialize(stream) as PlayerDataSerializable;
stream.Close();
return data.realCurrentLevel;
}
else
{
return 1;
}
}
so the method gets the level index from the data file but if the file is not found it just returns "1".
Now the problem is that when I build the game to my OPPO A73 with Android 10 and enter the app settings and choose"clear data" and reopen the game, then it crashes at level0. however when I do the same thing with Nokia 3 (Android 9) or Xiaomi Redmi Note 10 (Android 11) the game works fine and loads the first level as expected.
I monitored the errors via Logcat in Android Studio but I didn't get any error from Unity.
Is the problem with my OPPO device? because I got this error in Logcat:
E/DispScene: [/data/oppo/multimedia/oppo_display_perf_list.xml]:open
config fail
Or with Android 10?

SMS manager not working on specific devices

I'm developing an application in which i can send specific messages to specific number.
the messages are already pre-defined for example "SYSSTAT", and number is also pre-define when user start application he/she enter receiver device number.
But i'm getting error as SMSManager returns RESULT_ERROR_GENERIC_FAILURE, i had tested on various OS like start from Marshmallow to Pie but i'm getting error only on Marshmallow devices.
I had already give each permission manually too, but unfortunately not work on marshmallow devices only i had checked on Redmi 4A, Note 7 pro, Note 7, Nokia 6.1, etc...
Kindly help me.
It's due to simInfo.subscriptionId
here is sample code hwo i manage it.
val activeList = subscriptionManager.activeSubscriptionInfoList
if (activeList != null && activeList.isNotEmpty()) {
isMultipleSubscriptions = activeList.size > 1
val simInfo1 = activeList[0] as SubscriptionInfo
val simInfo2 = activeList[1] as SubscriptionInfo
if (simInfo1.displayName != null && simInfo1.displayName != "") {
companies.add(simInfo1.displayName.toString())
companySubscriptionId.add(simInfo1.subscriptionId)
}
if (simInfo2.displayName != null && simInfo2.displayName != "") {
companies.add(simInfo2.displayName.toString())
companySubscriptionId.add(simInfo2.subscriptionId)
}
}
And send SMS using selected subscription id
SmsManager.getSmsManagerForSubscriptionId(aSubscriptionId)
.sendTextMessage(
phoneNumber,
null,
aMsg,
sentPI,
deliveredPI
)

Why the insertion of SMS with the content resolver sometimes return a uri with 0?

The following code works on some tablets and don't on others with Android 7 (API 25) and 8 (API 27), Samsung and Huawai.
The problem is when inserting a new SMS in the database with the content resolver, it always returns a uri with a 0 ("content://sms/sent/0") instead of a uri with the sms id ("content://sms/sent/104", then "content://sms/sent/105").
private val resolver = context.contentResolver
fun saveSending(text: String, destAddress: String, threadId: Int = 0): Uri? {
val uri = resolver.insert(Telephony.Sms.Sent.CONTENT_URI, ContentValues().apply {
put(Telephony.Sms.BODY, text)
put(Telephony.Sms.DATE, MainClock.clock.millis())
put(Telephony.Sms.ADDRESS, destAddress)
put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_OUTBOX)
put(Telephony.Sms.THREAD_ID, threadId)
put(Telephony.Sms.READ, true)
put(Telephony.Sms.SEEN, true)
})
return uri
}
When querying after the SMS ("resolver.query"), it contains well its id
in the Telephony.Sms._ID column.
Is it a known Android bug ? Any workaround ?
Found it !
It was just that my app wasn't the app by default to send messages.
Thanks anyway

Android 4.4.2 crash during picking image

During developing application in Xamarin Android we encountered strange error. The pick image/video (whether its from camera or documents UI) application sometimes crashes with no error. Scenario is that we open application, make steps to the activity, where the images are chosen, and then open the camera or document UI by standard way:
public void ChooseMediaAfterTypeChose (bool photo, bool camera) {
try {
string title = "";
int id;
Intent iIntent;
if (camera) {
if (photo) {
iIntent = new Intent("android.media.action.IMAGE_CAPTURE");
id = Const.AND_pickImageID_camera;
App._file = new File (App._dir, "myPhoto.jpg");
iIntent.PutExtra (Android.Provider.MediaStore.ExtraOutput, Uri.FromFile (App._file));
} else {
iIntent = new Intent("android.media.action.VIDEO_CAPTURE");
id = Const.AND_pickVideoID_camera;
App._file = new File (App._dir, "myVideo.mp4");
iIntent.PutExtra (Android.Provider.MediaStore.ExtraOutput, Uri.FromFile (App._file));
}
} else {
iIntent = new Intent ();
iIntent.SetAction (Intent.ActionGetContent);
if (photo) {
iIntent.SetType ("image/jpg");
title = Static.mainData.currentTexts.ChoosePhoto;
id = Const.AND_pickImageID_galery;
} else {
iIntent.SetType ("video/mp4");
title = Static.mainData.currentTexts.ChooseVideo;
id = Const.AND_pickVideoID_galery;
}
}
if (camera) {
StartActivityForResult (iIntent, id);
} else {
StartActivityForResult (Intent.CreateChooser (iIntent, title), id);
}
} catch (Exception ex) {
ShowError (Static.mainData.currentTexts.MediaError);
W.L(ex.Message);
}
}
The chosen application crashes during image/video picking (E.g. during browsing images in gallery wthout picking any). When that happens we never get to any method in our code.
What we have:
When user don't pick photos, the application runs without any memory crash
Sometimes the picking proceedes without error.
We think that the issue is mainly on Android 4.4.2 (It happend to us only on devices with this android - on other android version devices we didn't encounter it)
What we tried:
We put all permissions to manifest (read/write external storage, hardware.camera etc.)
We delete almost all memory stored content to save up memory
All Activities are unload from memory when they leave the screen
Logcat says that every process connected (Application and the active application) just died with no trace to any error
Our question is if anyone stumbled to similar issue and how to handle it. The second question is if there is any way to find out whats happening.
EDIT:
App._dir code added.
App._dir = new Java.IO.File (
Environment.GetExternalStoragePublicDirectory (
Environment.DirectoryPictures), "Camera");
if (!App._dir.Exists ())
{
App._dir.Mkdirs( );
}

Categories

Resources