Author Topic: Wifi android device synching  (Read 202647 times)

railfan-eric28

  • Jr. Member
  • **
  • Posts: 105
Your best bet is to add your voice to the linked thread on Google's issue tracker.  If they're going insist on locking the permissions, it is not something that can be figured out. 
I went to setup Poweramp and selected the music folder in the same file explorer window as Musicbee WIFI and I selected it and it accepted it.   How is it that it works for Poweramp but not Musicbee Wifi? 
I'm using a Galaxy S21, Galaxy 9+, Galaxy S7, a Galaxy Tab S 8.4, Poweramp, and Musicbee.

frankz

  • Hero Member
  • *****
  • Posts: 3180
How am I supposed to know that?

My GUESS would be that PowerAmp is READING the music folder and MB is WRITING TO the music folder.  But why are you addressing this to me?  Seems to me you already got an answer from the guy who wrote the program.
Last Edit: December 02, 2021, 06:10:56 AM by frankz
A smile is happiness you'll find right under your nose.

railfan-eric28

  • Jr. Member
  • **
  • Posts: 105
How am I supposed to know that?

My GUESS would be that PowerAmp is READING the music folder and MB is WRITING TO the music folder.  But why are you addressing this to me?  Seems to me you already got an answer from the guy who wrote the program.
Sorry I was just wondering and didn't know if you knew.   ;) Just having conversation.   Your speculation makes sense.  Musicbee could be asking for read and write permissions.   Perhaps Steven has some insight on it.   ;)
I'm using a Galaxy S21, Galaxy 9+, Galaxy S7, a Galaxy Tab S 8.4, Poweramp, and Musicbee.

BoringName

  • Jr. Member
  • **
  • Posts: 56
For those having the SD card root error message on android 12 I may have got it working.

Disclaimer - I've never touched Android Studio before so I am totally winging it so everything is at your own risk. My partner was using iSyncr with iTunes but the developer sold it and the new owners have screwed it up and are charging $44 a month subscription (WTF!!). So I convinced them to move away from iTunes and now I've spent the last 2 days trying to get this working because there doesn't appear to be any other options to sync playcounts from android.... tried Media Monkey first as I used that 20 years ago but it's just rubbish now, multiple crashes and buggy UI behaviour turned me off very quickly. So here I am re-compiling an app, that's what it's come to. It make me think there is a big gap in the market right now.....

This might work on android 11 but I haven't tested that yet. I will go into another option below so if you're on 11 read the whole thing.

Install Android Studio (AS). Easy to do, there are plenty of guides on the net for this.
Download the code for musicbee wifi on github and extracted it to a folder.
Inside that folder delete .idea\vcs.xml - it causes an error when importing it into AS if you don't.
I opened the folder in AS. It will take a while to build gradle, whatever that means, just be patient.
It prompted me to upgrade gradle to version 7 or something like that. I opted to do that. Again you have to wait a little while.
Once it's loaded you will have a list of files on the left. Under Manifests, drag AndroidManifest.xml onto the right of the screen and it will display the contents.
Add the following line above line 5 in this file. It should be obvious where to put it.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

On the left of the screen under the Java folder, drag WifiSyncBaseActivity to the right of the screen.
Change line 115 from this -
if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.N || Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) && !PermissionsHandler.isUserSelectedPermissionsPathValid(WifiSyncServiceSettings.accessPermissionsUri.get())) {

To this -
if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.N || Build.VERSION.SDK_INT >= 32) && !PermissionsHandler.isUserSelectedPermissionsPathValid(WifiSyncServiceSettings.accessPermissionsUri.get())) {

This change just stops it checking if it actually has permission to the folder you select. The code to check permissions has changed and I haven't got my head around how to implement this yet so I chose to skip the check. Obviously not the best option but like I said, I'm just winging it.

I don't know if this matters but I also set a different version number
Right click "app" in the left window and select Open Module Settings
I changed the version code to 75 (was 74) and Version number to 2.2 (was 2.1)

Now just build the APK.
From the menus at the top of the screen, selection Build->Build Bundle(s)/APK(s)->Build APK(s)
This will create the following APK in the original folder
app\build\outputs\apk\debug\app-debug.apk

Copy this file to your phone.
Use a file browser to find the file on your phone and run it. It will state something about not being from the Play Store and it's unsigned, just install anyway.
Once you open it you will get a dialog to allow it to manage all files on the phone, click allow.
Before you do anything else, go out of the app and go to permission settings on the phone.
On mine I had to go to settings->apps->special app access->All files Access (This was on a redmi note 10 pro running a custom A12 AOSP rom)
Even though I had given it permission earlier, I found MusicBee Wifi Sync was set to "Not Allowed" in this menu. I changed it to Allowed. I did find code on how to approve this from within the app but haven't got my head around doing that yet.
Go back into the musicbee app and you should be able to select a folder now without it popping up an error.

I was able to wifi sync new playlists and the music files appeared on the phone in my selected folder so it has write access. There was one error I noticed initially. If your selected folder doesn't have a subfolder called Playlists, the app will still sync but state it was with errors. When you check the error log it says it can't determine if "Playlists" is a child of the folder you selected. There is 2 ways to deal with this.
1. Ignore it and hit sync more, you will see it still wants to sync playlists, just select sync now and this time it will sync without error.
2. Create a folder called "Playlists" inside your selected folder before you do a sync.

But thinking about it now, this is probably only an issue I'm facing in testing because I keep deleting the files to retest, normal users would have done a wired sync first so the "Playlist" folder would get created during this process before you attempt a wifi sync.

I haven't tested 2 way sync with GoneMad yet because the unlocked version needs to be installed. I'm doing all this to get it working on my partners phone so once I get my hands on that I'll pay for the app on their phone and give it a go and update this post, at this stage I can't see why it wouldn't work.

I'm fairly sure this will work on Android 11 but if it doesn't you could also try the following.
In the AndroidManifest.xml file, change the following code -
android:allowBackup="true"
android:theme="@style/AppTheme">

To this -
android:allowBackup="true"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true">

This is the pull request change listed on github. Android 12 ignores the requestLegacyExternalStorage but for android 11 it allows storage access to work like it did in android 10.

The problem with the file permission changes for the creator of this app is google won't just allow any app to use the "MANAGE_EXTERNAL_STORAGE" permission. You have to justify it's usage. So if they made the changes I suggested and uploaded it to the play store, google will probably reject it. So we are stuck with installing the APK manually to bypass this problem.

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 32916
thanks BoringName.
This is directed to anyone, if you want to take full control of this plugin including publishing to the store then please contact me. I really dont want to maintain it anymore

BoringName

  • Jr. Member
  • **
  • Posts: 56
This is directed to anyone, if you want to take full control of this plugin including publishing to the store then please contact me. I really dont want to maintain it anymore

Flying by the seat of my pants at the moment. I just wanted to get it working. I'd consider it if I actually knew what I was doing.

It's currently targeting SDK 29 and needs to target SDK 30 for the app store to accept it. I'll probably see what I can do about making it compliant with SDK 30 without the hack jobs I've currently used. I went down a big rabbit hole reading about scoped storage yesterday. If I can do that I will see if I can figure out how to do a pull request on github. And that will end it for me until google breaks something else. I can usually figure out other peoples code, not great at writing it and zero experience with java.

I suppose I could put a link up to my compiled APK but didn't want to encourage people to install things linked by strangers on the internet.

I forgot my partners phone is Android 11. Everything installed and syncing perfectly with GoneMad, play counts and ratings are syncing back to the PC. Happy days. On my phone (android 12) sync works. I just can't test play counts and ratings syncing back from GoneMad because you need the unlocked version and I don't want to pay for it a second time. I don't use my phone for music.

Went from -
iTunes<--iSyncr-->Rocket Player
To -
MusicBee<--MusicBee Wifi Sync-->GoneMad

It's a vast improvement. I hate itunes and have been trying to convince my partner to replace it for years. Just playing around with MB over the last few days while fixing up this app and I really like it. Plus the sync is 100x better. I was always baffled by how unbelievably slow isyncr was but it worked (most of the time) so we put up with it. Same goes for GoneMad, Rocket Player would constantly be scanning for new music, it would take hours and kill the battery anytime new music was added. GoneMad seems to handle this a lot better although I probably won't know until all the music is on there.

She has about 50k songs. I've synced all her playlists and just doing a full music sync now. She likes ALL her music on the phone. Another improvement over iSyncr is I can see on MB it is up to 18%. iSyncr had no progress bar.

Haljeff

  • Newbie
  • *
  • Posts: 16
FYI: 2 way sync does work on android 12. you will have to set permissions in app settings to allow full acces to files

BoringName

  • Jr. Member
  • **
  • Posts: 56
FYI: 2 way sync does work on android 12. you will have to set permissions in app settings to allow full acces to files

The app doesn't ask for that permission so you can't set it. Maybe it's something you can do on a rooted device?

It only asks for permission to media files not all files.

In any case, the way the app checks to see if it has permission to the folder you select is incorrect for newer versions of android which is why it always pops up a message to select the root folder because it thinks it doesn't have permission even if it does.

My previous posts detail how you can modify the source code and compile your own APK for it to work on android 11+ devices.

Haljeff

  • Newbie
  • *
  • Posts: 16
settings>apps>musicbee wifi sync>permissions>tap files and media >allow management of all files

Shougun

  • Newbie
  • *
  • Posts: 6
settings>apps>musicbee wifi sync>permissions>tap files and media >allow management of all files

For me with a samsung android 12 the app will ask permission to use files, you give it, and if you do what you said the app will only have what appear to be standard files permission and there will be no section to add anything beyond what it has asked for and been given permission for already.

Without having a tweaked wifi sync app, for me at least, the app will refuse to work with GMMP stats.xml (it can create them via the intent thing, but just wont be able to read them). Weirdly it works with poweramp without the modifications.

Haljeff

  • Newbie
  • *
  • Posts: 16
You have to manually go through android settings and change allow only media files to allow all files.
This worked for me with modified wifi app
Settings
Apps
Musicbee wifi sync
Permissions
Files and settings

frankz

  • Hero Member
  • *****
  • Posts: 3180
For those having the SD card root error message on android 12 I may have got it working.
Thank you so much for this. Now I can get a new phone.
A smile is happiness you'll find right under your nose.

Nandra

  • Newbie
  • *
  • Posts: 3
Could I get a clarification on reverse synching? If I...
1. create a playlist in musicbee
2. modify the playlist on-device in goneMAD
3. sync again with reverse sync enabled for playlists
...should I expect the changes to the playlist to show up in musicbee? Or is it the intended behavior for the goneMAD playlist's changes to get erased?

Thanks for everything you've done on this, Steven!

voNQ4UU2NV8qw0Ij

  • Newbie
  • *
  • Posts: 1
thanks BoringName.
This is directed to anyone, if you want to take full control of this plugin including publishing to the store then please contact me. I really dont want to maintain it anymore
Is the Musicbee side of the connection documented anywhere? While I am not in a position to update the existing app, I would like to try to get the reverse syncing working as a learning project.

BoringName

  • Jr. Member
  • **
  • Posts: 56
I'll probably see what I can do about making it compliant with SDK 30 without the hack jobs I've currently used.

I've successfully compiled an APK targetting API level 30 and it appears to work on my Android 12 phone. It prompts for permission when required. I haven't tested it on Android 11 yet as it's hard to do through the emulator and I'm not going to risk messing with my partners phone in case it wants to resync the whole library again. For some reason the emulator just won't see my comp to connect to MusicBee, i'm using 10.0.2.2 which is supposed to work.... firewall is set.

I had an old phone running android 9 and it still works on that although it did freeze for a few seconds before loading up the permission prompt, I'll probably grab my friends phone tomorrow (android 11) and give that a test.

This is still using MANAGE_EXTERNAL_STORAGE, it's just a bit better with permissions than my previous effort and could be submitted to the play store. Good chance they will reject it though. I noticed GoneMad is using MANAGE_EXTERNAL_STORAGE also but that app was last updated before the API 30 cutoff on the Play Store.

I don't think scoped storage is as bad as I initially thought as I think you can add persistent permissions to folders so you don't have to bug the user every time you want to delete a file but it's still going to take a decent re-write of the code that is beyond me at this point.

Let me know if you want to do anything with the code, I have no idea how to do a pull request on github but I'll give it a shot if requested. Also my main goal was making it work and I'm sure what I've done isn't best practice, some of it might be outright bad...