I need an input type=file web form element to open the file browser and return to the code with the selected file to be submitted. I accomplished this in a standard web form and tested in Android's regular browser, but when I wrap the app with Phonegap the button no longer works.
What is the workaround for this? It seems like a lot of people are passing around an example where the camera is used, but I don't need the camera, I need a file browser.
/* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
public class GGVAndroidWrapper extends DroidGap { private ValueCallback<Uri> mUploadMessage; private final static int FILECHOOSER_RESULTCODE = 1; private FileAttachmentChromeClient chromeClient;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
public class FileAttachmentChromeClient extends CordovaChromeClient {
public FileAttachmentChromeClient(CordovaInterface ctx, CordovaWebView app) { super(ctx, app);
}
// For Android > 3.x public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
// Here's where we take over for file uploads.
// Send intent to open file chooser mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*");
GGVAndroidWrapper.this.startActivityForResult(Intent.createChooser(i, "Choose type of attachment"), FILECHOOSER_RESULTCODE);
} On Wednesday, December 19, 2012 8:40:21 PM UTC-5, Mike Britton wrote:
> I need an input type=file web form element to open the file browser and > return to the code with the selected file to be submitted. I accomplished > this in a standard web form and tested in Android's regular browser, but > when I wrap the app with Phonegap the button no longer works.
> What is the workaround for this? It seems like a lot of people are > passing around an example where the camera is used, but I don't need the > camera, I need a file browser.
I've successfully been able to get the file chooser up to pick a file
and when I return the file path to the HTML side it seems to be set
correctly but when I asked for input.value in JavaScript I only get
the file name. Have you been able to get the full path in your HTML?
On Fri, Dec 21, 2012 at 3:32 PM, Mike Britton <mbritto...@gmail.com> wrote:
> I've managed to regain the ability to open the file chooser, and potentially
> do something with the file, in my main DroidGap activity. Now the problem
> is the button that launches the fileChooser only does it once! I can't
> reestablish the listener. This seems like a scope issue, but it's turning
> out to be such a pain in the ass I'm going with a native solution.
> /*
> Licensed to the Apache Software Foundation (ASF) under one
> or more contributor license agreements. See the NOTICE file
> distributed with this work for additional information
> regarding copyright ownership. The ASF licenses this file
> to you under the Apache License, Version 2.0 (the
> "License"); you may not use this file except in compliance
> with the License. You may obtain a copy of the License at
> Unless required by applicable law or agreed to in writing,
> software distributed under the License is distributed on an
> "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> KIND, either express or implied. See the License for the
> specific language governing permissions and limitations
> under the License.
> */
> // For Android > 3.x
> public void openFileChooser(ValueCallback<Uri> uploadMsg, String
> acceptType) {
> // Here's where we take over for file uploads.
> // Send intent to open file chooser
> mUploadMessage = uploadMsg;
> Intent i = new Intent(Intent.ACTION_GET_CONTENT);
> i.addCategory(Intent.CATEGORY_OPENABLE);
> i.setType("image/*");
> GGVAndroidWrapper.this.startActivityForResult(Intent.createChooser(i,
> "Choose type of attachment"), FILECHOOSER_RESULTCODE);
> }
> }
> }
> --
> -- You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phonegap@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
> For more info on PhoneGap or to download the code go to www.phonegap.com
> To compile in the cloud, check out build.phonegap.com
I'm not even there yet. My Phonegap WebView loads an external URL I've whitelisted. Using the above technique, I can get the chooser via an Intent, but I can't set focus back on my web form once the file has been chosen. Is this something you've achieved?
Thanks in advance if you can show me how you did this :)
On Friday, December 21, 2012 3:45:09 PM UTC-5, Simon wrote:
> Hey Mike,
> I've successfully been able to get the file chooser up to pick a file > and when I return the file path to the HTML side it seems to be set > correctly but when I asked for input.value in JavaScript I only get > the file name. Have you been able to get the full path in your HTML?
> On Fri, Dec 21, 2012 at 3:32 PM, Mike Britton <mbrit...@gmail.com<javascript:>> > wrote: > > I've managed to regain the ability to open the file chooser, and > potentially > > do something with the file, in my main DroidGap activity. Now the > problem > > is the button that launches the fileChooser only does it once! I can't > > reestablish the listener. This seems like a scope issue, but it's > turning > > out to be such a pain in the ass I'm going with a native solution.
> > /* > > Licensed to the Apache Software Foundation (ASF) under one > > or more contributor license agreements. See the NOTICE file > > distributed with this work for additional information > > regarding copyright ownership. The ASF licenses this file > > to you under the Apache License, Version 2.0 (the > > "License"); you may not use this file except in compliance > > with the License. You may obtain a copy of the License at
> > Unless required by applicable law or agreed to in writing, > > software distributed under the License is distributed on an > > "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > > KIND, either express or implied. See the License for the > > specific language governing permissions and limitations > > under the License. > > */
> > // For Android > 3.x > > public void openFileChooser(ValueCallback<Uri> uploadMsg, String > > acceptType) {
> > // Here's where we take over for file uploads.
> > // Send intent to open file chooser > > mUploadMessage = uploadMsg; > > Intent i = new Intent(Intent.ACTION_GET_CONTENT); > > i.addCategory(Intent.CATEGORY_OPENABLE); > > i.setType("image/*");
> > GGVAndroidWrapper.this.startActivityForResult(Intent.createChooser(i, > > "Choose type of attachment"), FILECHOOSER_RESULTCODE);
> > }
> > }
> > }
> > -- > > -- You received this message because you are subscribed to the Google > > Groups "phonegap" group. > > To post to this group, send email to phon...@googlegroups.com<javascript:> > > To unsubscribe from this group, send email to > > phonegap+u...@googlegroups.com <javascript:> > > For more options, visit this group at > > http://groups.google.com/group/phonegap?hl=en?hl=en
> > For more info on PhoneGap or to download the code go to www.phonegap.com
> > To compile in the cloud, check out build.phonegap.com
On Fri, Dec 21, 2012 at 5:26 PM, Mike Britton <mbritto...@gmail.com> wrote:
> Hi Simon.
> I'm not even there yet. My Phonegap WebView loads an external URL I've
> whitelisted. Using the above technique, I can get the chooser via an
> Intent, but I can't set focus back on my web form once the file has been
> chosen. Is this something you've achieved?
> Thanks in advance if you can show me how you did this :)
> On Friday, December 21, 2012 3:45:09 PM UTC-5, Simon wrote:
>> Hey Mike,
>> I've successfully been able to get the file chooser up to pick a file
>> and when I return the file path to the HTML side it seems to be set
>> correctly but when I asked for input.value in JavaScript I only get
>> the file name. Have you been able to get the full path in your HTML?
>> On Fri, Dec 21, 2012 at 3:32 PM, Mike Britton <mbrit...@gmail.com> wrote:
>> > I've managed to regain the ability to open the file chooser, and
>> > potentially
>> > do something with the file, in my main DroidGap activity. Now the
>> > problem
>> > is the button that launches the fileChooser only does it once! I can't
>> > reestablish the listener. This seems like a scope issue, but it's
>> > turning
>> > out to be such a pain in the ass I'm going with a native solution.
>> > /*
>> > Licensed to the Apache Software Foundation (ASF) under one
>> > or more contributor license agreements. See the NOTICE file
>> > distributed with this work for additional information
>> > regarding copyright ownership. The ASF licenses this file
>> > to you under the Apache License, Version 2.0 (the
>> > "License"); you may not use this file except in compliance
>> > with the License. You may obtain a copy of the License at
>> > Unless required by applicable law or agreed to in writing,
>> > software distributed under the License is distributed on an
>> > "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > KIND, either express or implied. See the License for the
>> > specific language governing permissions and limitations
>> > under the License.
>> > */
>> > // For Android > 3.x
>> > public void openFileChooser(ValueCallback<Uri> uploadMsg, String
>> > acceptType) {
>> > // Here's where we take over for file uploads.
>> > // Send intent to open file chooser
>> > mUploadMessage = uploadMsg;
>> > Intent i = new Intent(Intent.ACTION_GET_CONTENT);
>> > i.addCategory(Intent.CATEGORY_OPENABLE);
>> > i.setType("image/*");
>> > GGVAndroidWrapper.this.startActivityForResult(Intent.createChooser(i,
>> > "Choose type of attachment"), FILECHOOSER_RESULTCODE);
>> > }
>> > }
>> > }
>> > --
>> > -- You received this message because you are subscribed to the Google
>> > Groups "phonegap" group.
>> > To post to this group, send email to phon...@googlegroups.com
>> > To unsubscribe from this group, send email to
>> > phonegap+u...@googlegroups.com
>> > For more options, visit this group at
>> > http://groups.google.com/group/phonegap?hl=en?hl=en
>> > For more info on PhoneGap or to download the code go to www.phonegap.com
>> > To compile in the cloud, check out build.phonegap.com
> --
> -- You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phonegap@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
> For more info on PhoneGap or to download the code go to www.phonegap.com
> To compile in the cloud, check out build.phonegap.com
Don't know if this can help you since I've gone the native route for this, but I wriggled my way into getting the file path, extension and mime type in onActivityResult(). I could bang Google right now I'm so happy.
This is from a file chooser selection on all openable resources on the SD card. I'm passing the path with the start activity intent.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
I moved away from staying in Cordova, since my HTML is web-based and not compiled into the application. I'm not sure, but I don't think it's possible for a remote web application to do things like call Phonegap plugins. If I'm wrong, which I hope I am, at least I'll have this native piece.
Yeah, I'm in the same boat as you. In onActivityResult I have all the
information I need including the file path, mime type, etc. but when I
call
mUploadMessage.onReceiveValue(result);
in order to update the input tag in the HTML it does not get set
correctly. I need to look into what is happening there a bit more and
see if there is anyway I can update it manually.
On Sat, Dec 22, 2012 at 9:37 PM, Mike Britton <mbritto...@gmail.com> wrote:
> Don't know if this can help you since I've gone the native route for this,
> but I wriggled my way into getting the file path, extension and mime type in
> onActivityResult(). I could bang Google right now I'm so happy.
> This is from a file chooser selection on all openable resources on the SD
> card. I'm passing the path with the start activity intent.
> I moved away from staying in Cordova, since my HTML is web-based and not
> compiled into the application. I'm not sure, but I don't think it's
> possible for a remote web application to do things like call Phonegap
> plugins. If I'm wrong, which I hope I am, at least I'll have this native
> piece.
> --
> -- You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phonegap@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
> For more info on PhoneGap or to download the code go to www.phonegap.com
> To compile in the cloud, check out build.phonegap.com
public class FileAttachmentChromeClient extends CordovaChromeClient {
public FileAttachmentChromeClient(CordovaInterface ctx, CordovaWebView app) { super(ctx, app);
}
// For Android > 3.x public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
// Send intent to open file chooser mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*");
GGVAndroidWrapper.this.startActivityForResult( Intent.createChooser(i, "Choose type of attachment"), FILECHOOSER_RESULTCODE);
On Monday, December 24, 2012 9:55:46 AM UTC-5, Simon wrote:
> Yeah, I'm in the same boat as you. In onActivityResult I have all the > information I need including the file path, mime type, etc. but when I > call
> mUploadMessage.onReceiveValue(result);
> in order to update the input tag in the HTML it does not get set > correctly. I need to look into what is happening there a bit more and > see if there is anyway I can update it manually.
> On Sat, Dec 22, 2012 at 9:37 PM, Mike Britton <mbrit...@gmail.com<javascript:>> > wrote: > > Don't know if this can help you since I've gone the native route for > this, > > but I wriggled my way into getting the file path, extension and mime > type in > > onActivityResult(). I could bang Google right now I'm so happy.
> > This is from a file chooser selection on all openable resources on the > SD > > card. I'm passing the path with the start activity intent.
> > I moved away from staying in Cordova, since my HTML is web-based and not > > compiled into the application. I'm not sure, but I don't think it's > > possible for a remote web application to do things like call Phonegap > > plugins. If I'm wrong, which I hope I am, at least I'll have this > native > > piece.
> > -- > > -- You received this message because you are subscribed to the Google > > Groups "phonegap" group. > > To post to this group, send email to phon...@googlegroups.com<javascript:> > > To unsubscribe from this group, send email to > > phonegap+u...@googlegroups.com <javascript:> > > For more options, visit this group at > > http://groups.google.com/group/phonegap?hl=en?hl=en
> > For more info on PhoneGap or to download the code go to www.phonegap.com
> > To compile in the cloud, check out build.phonegap.com
If you look at the branch I posted you'll see I integrated it into
DroidGap/CordovaWebView/CordovaChromeClient. I'm able to get the value back
to the input tag but on 2.x it only gives me the file name while on 3.x+ it
gives me something like this:
On Mon, Dec 24, 2012 at 3:58 PM, Mike Britton <mbritto...@gmail.com> wrote:
> Further clarification: the solution above is for Android 3.x and above.
> It needs to be in DroidGap, IMO.
> --
> -- You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phonegap@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
> For more info on PhoneGap or to download the code go to www.phonegap.com
> To compile in the cloud, check out build.phonegap.com
On Thursday, December 20, 2012 7:10:21 AM UTC+5:30, Mike Britton wrote:
> I need an input type=file web form element to open the file browser and > return to the code with the selected file to be submitted. I accomplished > this in a standard web form and tested in Android's regular browser, but > when I wrap the app with Phonegap the button no longer works.
> What is the workaround for this? It seems like a lot of people are > passing around an example where the camera is used, but I don't need the > camera, I need a file browser.
On Tue, Dec 25, 2012 at 12:34 AM, Mike Britton <mbritto...@gmail.com> wrote:
> Using ICS, I'm seeing the file name only in the input tag. Default
> browser.
> --
> -- You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phonegap@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
> For more info on PhoneGap or to download the code go to www.phonegap.com
> To compile in the cloud, check out build.phonegap.com
> File to upload: <input type="file" name="upload">
> <input type="submit" value="Press to Upload..."> to upload the > file!
> </form>
> </body>
> </html>
> On Monday, December 24, 2012 9:55:46 AM UTC-5, Simon wrote:
>> Yeah, I'm in the same boat as you. In onActivityResult I have all the >> information I need including the file path, mime type, etc. but when I >> call
>> mUploadMessage.onReceiveValue(result);
>> in order to update the input tag in the HTML it does not get set >> correctly. I need to look into what is happening there a bit more and >> see if there is anyway I can update it manually.
>> On Sat, Dec 22, 2012 at 9:37 PM, Mike Britton <mbrit...@gmail.com> >> wrote: >> > Don't know if this can help you since I've gone the native route for >> this, >> > but I wriggled my way into getting the file path, extension and mime >> type in >> > onActivityResult(). I could bang Google right now I'm so happy.
>> > This is from a file chooser selection on all openable resources on the >> SD >> > card. I'm passing the path with the start activity intent.
>> > I moved away from staying in Cordova, since my HTML is web-based and >> not >> > compiled into the application. I'm not sure, but I don't think it's >> > possible for a remote web application to do things like call Phonegap >> > plugins. If I'm wrong, which I hope I am, at least I'll have this >> native >> > piece.
>> > -- >> > -- You received this message because you are subscribed to the Google >> > Groups "phonegap" group. >> > To post to this group, send email to phon...@googlegroups.com >> > To unsubscribe from this group, send email to >> > phonegap+u...@googlegroups.com >> > For more options, visit this group at >> > http://groups.google.com/group/phonegap?hl=en?hl=en
>> > For more info on PhoneGap or to download the code go to >> www.phonegap.com
>> > To compile in the cloud, check out build.phonegap.com