Android Question Problems after using SDK Manager and updating Android SDK

Wolodymyr

Member
I try to upgrade my app to use Firebase messaging. After modifying manifest and enabling corresponding libraries i see, that firebase components is missing in Android SDK, so I launch SDK Manager and download all needed files for firebase. But strange things appears

I see "error: package android.support.annotation does not exist import android.support.annotation.NonNull;"
Before I use Erel block of Java code Get path from URI that use this annotations and it was work great. Now all my attempts to start compiling old working code has no effect. I try download new Android SDK commandlinetools-win-6858069_latest.zip and update b4a from 10.0 to 10.2, and SDK manager from 3.70 to 3.71 version, but no success
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This means that you haven't followed the instructions.

Delete the SDK and download it again: https://www.b4x.com/b4a.html
 
Upvote 0

Wolodymyr

Member
I must say thanks Erel for his great work

Delete the SDK and download it again
Do this several times - with old (commandlinetools-win-6609375_latest.zip) and new SDK's ZIP files
I think problem may be because google change folder structure in new version of Android SDK (commandlinetools-win-6858069_latest.zip)

What I see - "Tools" folder is changed to "cmdline-tools". After downloading/updating by SDK, some folder also dublicated with "-2" postfix. I never seen this before. Need to explore whats goin' on here
 
Upvote 0

Wolodymyr

Member
I remove Oracle JDK and change it to OpenJDK 11. Several times delete and install Android SDK as described in installation tutorial. Still no success. Try to change android.jar from 27 platform to 30, no result.
May try to downgrade from 10.2 to 10.0 version?

Problem belongs to this strings from inline JAVA code, thats works excellent before (from Get path from URI)
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
Screenshot:

Here it is error:
 
Last edited:
Upvote 0

Wolodymyr

Member
I use it for my previous question Play mp3 from SD card

I
1) Check and receive request for external sdcard rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
after request permission, select coressponding folder
2) After request permission, select coressponding folder by Storage.SelectDir(False)
3) When occur Storage_ExternalFolderAvailable event, use File.ReadString(File.DirInternal,Storage.PreviousUriFileName) to get URI with path to a requested my MP3 folder
4) Use GetPath function to extract Folder_path=FileUtils.RunMethod("getFullPathFromTreeUri", Array(uri,ctxt))
5) By using extracted Path, I list files from the folder and play it by MediaPlayer.Load(Folder_path,Mp3FileName)

I not found another possible way to play mp3's from external card
 
Upvote 0

Wolodymyr

Member
Because I simply don't know how. As i understand, i may use ""file://.." as input stream for MediaPlayerStream. But for creating this Path string I must some way extract filepath info from Storage.LIstFiles in Storage_ExternalFolderAvailable event.
I'm totally search forum for this question and don't find any answer
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your solution is problematic:
1. I haven't tested it with a sd card but I'm pretty sure that it will not work at all as you don't have permission to directly access its file system.
2. With the external storage, it requires the soon to be removed external storage access.
3. Your assumption that there will actually be a file behind the Uri is not correct. The user can choose Google Drive or any other source that is not mapped to the local file system.

Best option is to copy the file to File.DirInternal and play it from there.
 
Upvote 0

Wolodymyr

Member

I test my app before firebase integration and SDK problems both on phone and bluestacks emulator and it works fine. Here TTS Robot

Never think that simple MP3 playing will be so difficult. Disaster
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I test my app before firebase integration and SDK problems both on phone and bluestacks emulator and it works fine. Here TTS Robot
I guess that you either tested it on an old device or with a low targetSdkVersion.

Anyway, it is very simple to play a sound file, no matter where it stored:
B4X:
Sub Button1_Click
    Dim cc As ContentChooser
    cc.Initialize("cc")
    cc.Show("audio/*", "Choose audio file")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        Wait For (File.CopyAsync(Dir, FileName, File.DirInternal, "temp")) Complete (Success As Boolean)
        If Success Then
            mp.Stop
            mp.Load(File.DirInternal, "temp")
            mp.Play
        End If
    End If
End Sub
 
Upvote 0

Wolodymyr

Member
I guess that you either tested it on an old device or with a low targetSdkVersion.

It has targetSdkVersion=29 and I'm already downloaded it to google play (now it is required for google play minimum targetSdkVersion=29)

I tested app with Xiaomi A1 (Android 9.0) - playing mp3's from External SD card (using yours JAVA injection code and my code in post #9) working very well!!
 
Upvote 0

Wolodymyr

Member
Change JAVA injection to my temporal code - will replace work with sdcard logic in future

GetPath simple extractor:
Sub GetPath(uristring As String) As String
    Dim Const storage_const As String ="content://com.android.externalstorage.documents/tree"
    
    If uristring.Contains(storage_const) Then
        Dim tmp As String = uristring.SubString(storage_const.Length) 'видираємо рядок для декодування
        Dim su As StringUtils
        tmp = su.DecodeUrl(tmp,"UTF8")
        tmp = tmp.Replace(":","/")
        uristring="/storage" & tmp
        Log ("Extracted path is: "& uristring)
        Return uristring
    Else
        Return ""
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…