Select image iphone simulator using phonegap camera api - javascript

I'm new to Xcode and iPhone apps. I want to select an image from iPhone (camera or library) and send to php via ajax.
I'm using the phonegap framework, Xcode iPhone SDK version 3.1.x. On clicking button it calls function with parameter 0 or 1, but it does not initialize camera or display the library.
I used the code in this link
it shows this error in debug console:
2010-03-25 23:36:02.337 PhoneGap[7433:207] Camera.getPicture: Camera not available.
simulator dsnt have camera, but photos(from library) also not wokring!
what might be the error?
I think when using navigator.camera.getPicture first check for camera and if not break and shows error ~?

For using photo library in iphone simulator. You have to conforms to the delegate UINavigationControllerDelegate, UIImagePickerControllerDelegate and alloc pickerview and set delegate on it and then check
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[self presentModalViewController:imagePickerView animated:YES];
}

I don't know how are you using that framework. But UIImagePickerController is the class I use to choose photos from the iPhone library or the device's camera. And all you need to do is set it to display the library:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//set your delegate and other properties...
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
or
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
You should check it out.
Cheers

Related

how to access the device camera from webview of android application

I have an android app with a WebView, it is written in Java Script and Angular JS code to access the Camera , I just load the URL in web view and had given camera access permission and read and write external storage permission, still it is not able to access the camera , I had browsed for this problem ,but didn't find the exact solution.
I just want to open the camera , when user click on take photo on his profile page which was written in java script code , don't know when this will happen because I have base URL only which was loaded in web view.
How to let the user open the camera in this application? And also it should support from Kitkat onward, Can any one help me to figure out this?
Use openChooser method when implement UIClient
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.addCategory(Intent.ACTION_CAMERA_BUTTON);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i,"File Chooser"), 111);
}

Using Phonegap CLI - Barcode scanner not working

I developing an app for iOS and Android using PhoneGap 3.4.0 from the command line interface, and want to make use of the BarcodeScanner plugin. The problem is that the scanner does not actually do anything when called by my app. The camera does not come up. By using console.log with Safari developer tools, I can tell that the scan function does exist and is getting called... it just isn't doing anything.
I installed the scanner plugin like this:
phonegap plugin add https://github.com/wildabeast/BarcodeScanner
In the index.html, included the javascripts like this:
<script src="phonegap.js"></script>
<script src="barcodescanner.js"></script>
In config.xml, added this:
<gap:plugin name="com.phonegap.plugins.barcodescanner" />
When I set scanner variable like this it logs that there is a BarcodeScanner, and it does have a function scan, but then when I call the function scan nothing happens. (the camera does not open).
var scanner = cordova.plugins.barcodeScanner;
console.log(scanner) // => BarcodeScanner
This is how I'm calling the scan function:
scanner.scan( function (result) {
... my code here...
} );
Any ideas? I'd really appreciate any help or pointers in how to get the barcodeScanner to work with PhoneGap.
I´m having the exact same problem.
After I updated my App to support arm64 (iPad Air), I ran into this issue.
A work-a-round:
Push the hardware On/Off button.
Turn on the device again.
Try starting the barcodeScanner.
This worked for me - but the App will not leave my desk before the issue has been fixed properly.
The issue now exists on all of my devices (iPad Mini, iPhone 4S, iPad Air).
The problem was that the version from wildabeast was not compatible with PhoneGap >= 3.2.0.
Use this branch instead: https://github.com/phonegap-build/BarcodeScanner
Install with
phonegap local plugin add https://github.com/phonegap-build/BarcodeScanner
To get it to work, I had to create a brand new app, copy the www folder over, and then install the plugin.

phonegap geo uri association

I am developing a phonegap application using phonegap build (therefore ALL in pure js and html, no native languages).
In my page, i have some geo uri links (http://en.wikipedia.org/wiki/Geo_URI ) that are cliccable (they represent coordinates of markers in a map).
Now, if the mobile device has installed and associated with this type of files an app (usually a gps navigator or the like), they open and launch the associated application as they should.
My issue is that I don't want to show the clickable link (the button appears in the infowdindow of the marker) if the device has no app capable to open them.
In native android code, you have the query-intent command for this. Does anyone know how to verify this in pure phonegap js?
Ty!
D.
I have been asked for code: The only code that is relevant here is the following, which computes the html code to embed in the infowindow of the marker:
var computePathString=<a href='geo:"+area['marker']['position'].lat()+",
"+area['marker']['position'].lng()+"'>Route</a>;
Which translates to the following html:
<a href='geo:45.557,9.1523'>Route</a>
Which works great on click IFF the device has an associated app (usually a gps navigator), but else does nothing on click. I need to achieve something similar to the query intents of android:
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;
only, in native phonegap js.

Phonegap - Open Navigation Directions in Apple Maps App

I have two variables - Destination and Source - and, using Phonegap, I'm trying to use jQuery to open the external iPhone Apple Maps app with directions.
The code I'm using looks like this:
var url = 'http://maps.apple.com/?q=daddr='+destination+'&saddr='+source;
window.location = url;
Whenever I click the relevant button however, it opens a new view in-app with Google directions as a webview, and I cannot return to the original app.
How can link be opened instead with the iOS default map application?
Changing http://maps.apple.com/?q= to just maps: did the trick.
NB: make sure you write maps: and not map: as, while the latter will run the correct app, it will crash immediately after opening (thanks jprofitt)
Today I was able to open the native Apple Maps app with marker from a Cordova app using BOTH of the follow URL schemes:
maps://maps.apple.com/?q={latitude},{longitude}
AND
maps://?q={latitude},{longitude}
In a link:
<a href="maps://maps.apple.com?q={latitude},{longitude}">
<!-- OR -->
<a href="maps://?q={latitude},{longitude}">
From JavaScript:
window.location.href = "maps://maps.apple.com/?q="+lat+","+lng;
// OR
window.location.href = "maps://?q="+lat+","+lng;
The app is running on an iOS device, iOS version 8.1.2, and cordova-ios is version 3.7.0.
In my case, changing from http://maps.apple.com/?q= to only maps:?q= not solving the problem.
The working scheme that open native Apple Maps with marker is as follows:
maps://maps.apple.com/?q={latitude},{longitude}
full working code:
window.location.href = "maps://maps.apple.com/?q="+lat+","+lng;
Tested working with iOS7.1 simulator, might not works in later version. I don't have the opportunity to test. Sorry.
Supported Apple Maps parameters can be found here:
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
Credit goes to this SO link: Here
The code
I managed to get this working in 2018 on iOS 11.2 using the following format in iOS:
<a onclick="window.open('maps://?q=51.178847,-1.826160', '_system');">Open in Maps</a>
And this format on Android:
<a onclick="window.open('geo:0,0?q=51.178847,-1.826160', '_system');">Open in Maps</a>
Config permissions
Additionally, don't forget to add permissions to your config.xml file like so:
<allow-intent href="maps:*" />
In my project the geo: intention had existed from the beginning so it took my a while to figure out why this was working on Android and not iOS.

pdf viewer in phonegap Android

I'm looking for a pdf viewer for Android using Phonegap 2.0. I tried the childbrowser plugin which worked on iOS but not on Android. I tried this http://www.giovesoft.com/2011/08/download-and-open-pdf-with-phonegap.html but that didn't work either, I get error messages like PhoneGap is not defined at file and cannot call method "showPdf" of undefined.
you can use pdf.js :
pdf.js is an HTML5 technology experiment that explores building a
faithful and efficient Portable Document Format (PDF) renderer without
native code assistance.
https://github.com/mozilla/pdf.js
I answered a similar question already (see Open PDF with PhoneGap in Android) but will do the same here. Use the ChildBrowser plugin as suggested in conjunction with Google Docs like so:
onclick='window.plugins.childBrowser.showWebPage(encodeURI("http://docs.google.com/viewer?url=' + pdfLink + '"));
This works fine for me and I have tested it in Android 2.1 up to 4.1.
The childbrowser plugin which I tried with does not open the pdf in android phonegap. However, it works for iOS. Another solution to your plugin query could be to use the Open With plugin. There is one disadvantage that this plugin does not open the pdf in the app itself. You can use the downloader plugin to download files and then try out the childbrowser plugin to access this pdf, which I think should be the solution
In Android, you can view the pdfs using Android Intents. This will show you all the pdf viewers available in your phone. You can select any and view the pdf
Eg :
private void showPdfAndroid(String url) throws IOException {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(url);
String extension = url.substring(url.lastIndexOf(".")+1);
String type = "";
if (extension.toLowerCase().equals("pdf")) {
type = "application/pdf";
Log.d("application/pdf", "application/pdf");
}
intent.setDataAndType(Uri.fromFile(file), type);
cordova.getActivity().startActivity(intent);
Log.d("FileViewerPlugin", "View complete in" + url);
}
Child browser don't support pdf viewing in android . better you use Google docs viewer for it in android . here in another stack overflow question you will get complete answer

Categories