Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-7487 [Android] Broadcast file write #81

Closed
wants to merge 2 commits into from

Conversation

dpeacock
Copy link
Contributor

@dpeacock dpeacock commented Sep 5, 2014

This allows MTP USB shares to show the file immediately without reboot/manual refresh using 3rd party app.

This allows MTP USB shares to show the file immediately without reboot/manual refresh using 3rd party app.

//Get file
File file = new File(this.filesystemPathForURL(inputURL));
if (file != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this comparison for? I'm pretty sure that new can't ever return null. It also doesn't check for file existence; you'd want file.exists() for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I will update this.

@dpeacock
Copy link
Contributor Author

Added the fix to check for file exists instead of null check.

@clelland
Copy link
Contributor

clelland commented Oct 6, 2014

Merged! You can close this PR any time.

(I squashed the two commits together, and rebased against the current head, so github won't automatically close the issue :( )

@dpeacock dpeacock closed this Oct 20, 2014
@tvanesse
Copy link

Hey guys,

I'm still experiencing the same problem with 5.0.0 when the Android device is connected to a Raspberry Pi 3 running standard Raspbian. That is, the Raspberry can't see the file over MTP unless the Android device is rebooted or the file is manually renamed from the native Android file browser.

Do you know how I could get this to work with the Pi?

@tvanesse
Copy link

Wait. I think your fix only applies when you write to a file. The broadcast isn't triggered if you move or copy an existing file.

I'll try to update the code and, if that works, open a separate PR for that.

@dpeacock
Copy link
Contributor Author

@tvanesse you are correct, my fix was only for writing files as that's all I was using the plug-in for. It would make sense that if you were moving/copying the files the same function I implemented (broadcastNewFile) should be called.

@tvanesse
Copy link

@dpeacock Thanks for your quick response. Now I am not really familiar with cordova plugins development but I guess adding

broadcastNewFile(srcFs.toNativeUri(srcURL));

at the end of copyFile in LocalFileSystem.java should do the job (around line 280).

As I said, I'm not sure how I should set up my environment so that my application uses my locally modified plugin. I can modify the plugin directly in my Ionic project (yes, I'm using ionic) but I don't know how to force Cordova to re-compile the plugin.

Can you help me on this?

Cheers.

@dpeacock
Copy link
Contributor Author

@tvanesse For a move I'm not sure whether you would need to do it on both the dest and src file, you would have to try I guess or read up on the best practices. But you have the right idea of what's required.

The best way to test this would be to 'Fork' the plugin from github, you'll see the icon on the main page. You can then use your favourite Git tool (something like GitKraken for example) to download the source locally and work on it. From your cordova project remove the cordova-plugin-file. You can then either add the plugin specifying your local path, or if you have pushed the changes to your Git repo you can add the plugin using your repo's URL. Each time you make a change you can remove and re-add the plugin.

One other thing to note is in some older cordova versions I've had issues where sometimes removing and re-adding the plug-in wasn't working quite right. Doing a cordova platform remove android then re-adding it seemed to solve it. You shouldn't have to do this, but if you run into issues it might be worth trying.

Working from Git is best, because once you're satisfied with the changes you can then make a pull request to get your fixes moved into the main plug-in. I would suggest you create a bug on the Cordova Issue tracker for this so you can reference it in your pull request https://issues.apache.org/jira/projects/CB/issues

Hopefully that's enough to get you going. I know there were some good blog posts (much more detailed) about this as well that you could probably google if you get stuck.

@tvanesse
Copy link

tvanesse commented Mar 6, 2018

@dpeacock Thanks for your support, I successfully tested the patch locally and will open an issue on Jira as you suggest, then a PR on Github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants