I need to load an mp3 on iOS from the www folder next to my HTML. I'm using phonegap and my code is basically the same as the example from : http://docs.phonegap.com/en/2.0.0/cordova_media_media.md.html
Its working on iOS and android when I use an mp3 from the web but if I try to load one from the www then I am getting a window saying I can't use the ressource (on ios).
I added this in my config.xml :
<feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/file" />
<feature name="http://api.phonegap.com/1.0/media" />
<gap:plugin name="org.apache.cordova.media" />
I am testing with the phonegap app for ios (http://app.phonegap.com/) from my phonegap server on windows and debuging with wienre. The rest of the app is working just the sound doesn't start.
I tried several different path :
"mySound.mp3"
"file://mySound.mp3"
"file:///mySound.mp3"
I also tried changing to an older phonegap version with no more luck.
Looking at the doc (same page as before) i should be able to just use the name of my file :
order of file search: When only a file name or simple path is
provided, iOS searches in the www directory for the file, then in the
application's documents/tmp directory:
var myMedia = new Media("audio/beer.mp3") myMedia.play() // first
looks for file in www/audio/beer.mp3 then in
/documents/tmp/audio/beer.mp3
I spent hours looking on internet and testing and i can't get that sound to start :/
Help would be much appreciated!
From what I know, iOS works with .wav file type. Maybe you should change your file type from .mp3 to .wav. Add the following to your config.xml
<plugin name="Media" value="CDVSound" />
iOS plays mp3 files. He only records in wav.
Related
I'm trying to create an app with phonegap and I want to include a sharing button. I couldn't make it so I created a new empty project from phonegap. I just have the sample page displayed and nothing else, when I try it on my phone. Now i want to simply add a basic sharing button.
Following the instructions here : https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
I went to my project folder and just installed the plugin with the phonegap command.
Then in my index.html I simply added this :
<button onclick="window.plugins.socialsharing.share('Message only')">message only</button>
But when I click it, nothing happens.
I also tried the other given buttons and solutions but none works. Any ideas? I'm struggling with this for 2 days!
Thank you in advance for your answers :)
Have you followed this setup.
https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin#manually
Add the following xml to all the config.xml files you can find
For IOS:
<feature name="SocialSharing"><param name="ios-package" value="SocialSharing" /></feature>
For Android
<feature name="SocialSharing"><param name="android-package" value="nl.xservices.plugins.SocialSharing" /></feature>
For Windows Phone
<feature name="SocialSharing"><param name="wp-package" value="SocialSharing"/></feature>
For sharing remote images (or other files) on Android, the file needs to be stored locally first, so add this permission to AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
For iOS, you'll need to add the Social.framework and MessageUI.framework to your project.
Click your project, Build Phases, Link Binary With Libraries, search for and add Social.framework and MessageUI.framework.2.
Grab a copy of SocialSharing.js, add it to your project and reference it in index.html:
<script type="text/javascript" src="js/SocialSharing.js"></script>
Download the source files for iOS and/or Android and copy them to your project.iOS: Copy SocialSharing.h and SocialSharing.m to platforms/ios//Plugins
Android: Copy SocialSharing.java to platforms/android/src/nl/xservices/plugins (create the folders)Window Phone: Copy SocialSharing.cs to platforms/wp8/Plugins/nl.x-services.plugins.socialsharing (create the folders)
I have created a jquery form which has a script to generate an xml file. I want to save this generated file to an SD card on my Android tablet.
I just for the life of me can't figure out the script needed to save it.
I have this script on the .js used to create the XML
$('#ResultXml').val(newXml);
$('#SaveLink')
.attr('href', 'data:text/xml;base64,' + btoa(newXml))
.attr('download', 'SiteVisit.xml');
$('#generated').show();
}
and a "SaveLink" button on my form that calls the script. This works on my desktop computer but does nothing on the android that the form is designed to deploy on.
I have added the permissions
<preference name="android.permission" value="WRITE_EXTERNAL_STORAGE" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />
<gap:plugin name="org.apache.cordova.file" version="1.0.1" />
to my config file (I am using PhoneGap Build)
Any help with this would be more than appreciated
Using PhoneGap you can use the cordova plugin file:
https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md
If you don't want to use phonegap, you can create an interface between your activity and your webview:
http://developer.android.com/guide/webapps/webview.html
I'm having trouble using the phonegap file API. In my application I'm using the following piece of code to save images from the LocalStorage to the android device.
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
// If the folder does not exist create it
fileSys.root.getDirectory( myFolderApp, {
create:true, exclusive: false
},
function(directory) {
entry.moveTo(directory, newFileName, successMove, resOnError);
},
resOnError);
}
the variable myFolderApp contains the foldername that needs to be created. The problem is that even tough the android tablet has got an SD card inserted, the applicaton keeps creating the directory (and later saving the data) to the internal storage instead of the external SD card.
localFileSystem.PERSISTENT Should switch to sd card when one is available right?
When I log the directory.toURL() it's saying "cdvfile/localhost/persistent/mydirectory"
The native android camera application is saving it's images to the SD card which means the SD card is working properly.
I'm quite lost at this point. After hours of googeling I know the cordova file plugin has recently been updated, and therefore sometimes requires a different approach but I'm still stuck and can't seem to find a solution.
Hope someone can help me.
Thanks in advance,
Marco
Try changing in config.xml
<preference name="AndroidPersistentFileLocation" value="Internal" />
to
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
See the following discussion:
https://groups.google.com/forum/#!msg/phonegap/5UeZOBAz_DM/YlaGFJVCpv4J
We need to modify the AndroidManifest.xml file, however we will not do it manually. This is not a good practice as everytime you build your project, your changes will be lost.
Instead we are going to use the cordova-custom-config plugin, which allow you to modify the AndroidManifest.xml file from your config.xml file without problems. To install the plugin execute the following command in your command line :
cordova plugin add cordova-custom-config
# Or phonegap
phonegap plugin add cordova-custom-config
Fortunately, to enable this feature you need add only a property to the AndroidManifest.xml file. Using cordova-custom-config plugin, which allow you to use custom config blocks in your config.xml file of your cordova app, you need to add the following line in the config.xml file inside the tag :
<platform name="android">
<!-- Modify the android-manifest block and add the new property android:installLocation with value auto !-->
<preference name="android-manifest/#android:installLocation" value="auto" />
</platform>
Read more about step by step here.
Read more about the plugin here in the official repository here.
I am making an Android app using HTML5 on Netbeans IDE. I am using the Cordova framweork to build. Until now, everything is OK except, I cannot make the splashscreen works.
I consulted the Phonegap documentations but in vain. Here what I did below:
The splashscreen plugin is already added in the Cordova plugins
section on Netbeans IDE.
I put the PNG images in the platforms/android/res/drawable/* folders.
I checked the parameters of the splashscreen in the XML Config file
which is located in res/xml/config.xml. It seems the parameters
are OK just like on the documentation.
I included the configurations in the XML Config file which is located in the WWW folder.
And finally, I copied and pasted the JavaScript codes in my
index.html file in the Head section just like on the documentation as
shown below:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.splashscreen.show();
}
Here are the two Phonegap documentations links:
http://docs.phonegap.com/en/3.3.0/cordova_splashscreen_splashscreen.md.html
http://docs.phonegap.com/en/3.3.0/config_ref_images.md.html#Icons%20and%20Splash%20Screens
So, where is the mistake? Thank!
you need to set this -
<preference name="SplashScreen" value="splash" />
<preference name="SplashScreenDelay" value="10000" />
in config.xml
I recently upgraded my app from Phonegap 1.6 to 2.2.
I've refactored everything (ex Plugin --> CordovaPlugin) and I'm also using the new config.xml.
The app compiles and builds, however I constantly am getting an error in logcat and an error dialog box. The dialog says [ERROR] Error initializing Cordova: Class not found.
The logcat error is:
Line 6048 : Error initializing Network Connection: Class not found
What could I be missing?
The issue happens on multiple devices.
Update
I've already changed the config.xml for the network status plugin from Network Status to NetworkStatus. It reads: <plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/>
I had this problem and made it go away by adding the following to the config.xml:
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/>
And adding this to the Manifest file:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I originally took them out because I "knew" that my app wouldn't be using any communications. I had forgotten about the emulator "communicating" with the ADK.
I'll take these 2 lines out when I convert the project over to "production" so that the app is ready for Google Play.
I had this problem using phonegap 3.x and the problem turned out to be that phonegap hadn't properly installed the plugins, or they just messed up along the way. Basically when you install the plugins and build for a platform it takes the javascript files from plugins/org.apache.cordova.core.specific-plugin/www and puts them in platforms/android/assets/www/plugins/org.apache.cordova.core.specific-plugin/www and then it takes the Java files (or objective C for iOS) and puts them in platforms/android/src/org/apache/cordova/specificplugin
And all of this is specified by plugins/org.apache.cordova.core.specific-plugin/plugin.xml. If you look in a plugins.xml you should see something like:
<source-file src="src/android/NetworkManager.java" target-dir="src/org/apache/cordova/networkinformation" />
So this tells you that in platforms/android/src/org/apache/cordova/networkinformation, there should be NetworkManager.java. And right that file can be copied from plugins/org.apache.cordova.core.network-information/src/android/NetworkManager.java
Now all of this is supposed to happen automatically without having to touch the platforms folder. But if it messes up you can fix it by copying the correct java files into the correct folders.
The following line in config.xml works for cordova 6.2 with android
<plugin name="cordova-plugin-network-information" value="org.apache.cordova.networkinformation"/>
The name should be the same as in what your plugin contains. You can find it in the your project folder at the following path plugins/name-of-the-plugin/package.json.
The value should be the package name for the plugin which can be found in the native implementation file.