Android Phonegap plugin and google analytics - android

I am using phonegap plugin and I could not get it to work. In the plugin, there is a plugin.xml and may I know how this file should be set up.
I have mine configured as below and it does not work.
<platform name="android">
<config-file target="res/xml/config.xml" parent="plugins">
<feature name="GAPlugin" >
<param name="android-package" value="com.adobe.plugins.GAPlugin"/>
</feature>
</config-file>
<source-file src="src/com/learnchn/pinyin/GAPlugin.java"
target-dir="src/com/learnchn/pinyin" />
<source-file src="libs/libGoogleAnalyticsV2.jar"
target-dir="libs" />
</platform>

plugin.xml is a file that is meant to be read and executed by tools such as the plugman to install a plugin to a platform. If you are not using such a tool then you may try to do the steps manually. Basically insert <feature> to res/xml/config.xml and copy src files on <source-file> to target-dir.
However I doubt that the plugin.xml you have posted is valid. The value for "android-package" parameter should point to the plugin implementation. The value "com.adobe.plugins.GAPlugin" would suggest that there would be a corresponding source file or a library with that class name added as part of the installation. However the only file that is added with a close name is "com/learnchn/pinyin/GAPlugin.java" which has a different package name.

At first you have to build your project with phonegap. Navigate to the location where you want to create your project and do the following:
phonegap create test com.example.test Test
cd test
phonegap local build android
Now you have a working android project in your "platforms/android/" directory which you can import in eclipse. Download the GAPlugin and unzip it. Then just use plugman to install the Google Analytics Plugin.
plugman install --platform android --project (Path to your phonegap android project) --plugin (path to the GAPlugin)
Now everything should be set and the plugin is installed. The next step would be initializing the plugin in your index.html to track every page visit. Add the GAPlugin.js
<script type="text/javascript" src="GAPlugin.js"></script>
You should add the following code after you received the "deviceready" event.
document.addEventListener("deviceready", onDeviceReady, false);
var gaPlugin;
function onDeviceReady() {
gaPlugin = window.plugins.gaPlugin;
gaPlugin.init(successHandler, errorHandler, "UA-********-*", 10);
// Put this function everywhere you want to track something
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, "index.html");
function successHandler() {}
function errorHandler() {}
function nativePluginResultHandler() {}
function nativePluginErrorHandler() {}
}
This approach worked for me. I'm using Phonegap 3.0 with the CLI.
Hope this fixes your problems ;)

If u want to add simple google Analytics setup then its quite easy just follow the below steps
1:- Add libGoogleAnalyticsV2.jar in libs folder 2:- Add analytics.xml file inside res->values, it binds the trackingid with the app,u can google for this file 3:-Add import com.google.analytics.tracking.android.easyTracker; in the activity file and use EasyTracker.getInstance().activityStart(this); in onCreate function.
Thats it, you are done with Google Analytics basic setup

Related

phonegap social sharing button issue android

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)

Phonegap: Splashscreen does not work

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

Phonegap 3 Plugin causing build error or plugin not initialized

Let me start with some context. I have a Java file and a .jar library which contains an Android project with an Activity, its layout, and another jar library. I also have the javascript interface for my plugin, of course. In other words, this is what I have:
plugins/com.phonegap.example.activity.plugin/www/myplugin.js
plugins/com.phonegap.example.activity.plugin/src/android/MyPlugin.java
plugins/com.phonegap.example.activity.plugin/src/android/libs/myJar.jar
plugins/plugin.xml
My plugin is supposed to execute a method within my MyPlugin.java file which is supposed to then launch the Activity that is within the myJar.jar file.
The plugin.xml for this plugin reads:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="com.phonegap.example.activity.plugin"
version="0.1.0">
<name>MyPlugin</name>
<description>Launch an Android Activity from PhoneGap 3</description>
<author>Author</author>
<license>MIT</license>
<keywords>phonegap,activity</keywords>
<js-module src="www/myplugin.js" name="MyPlugin">
<clobbers target="window.MyPlugin" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="MyPlugin">
<param name="android-package" value="com.phonegap.example.activity.plugin"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<activity
android:name="com.phonegap.example.activity.ExampleActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.phonegap.example.action.EXAMPLE" />
</intent-filter>
</activity>
</config-file>
<source-file src="src/android/MyPlugin.java" target-dir="src/com/phonegap/example/activity" />
<source-file src="src/android/libs/myJar.jar" target-dir="libs" />
</platform>
</plugin>
I have installed Phonegap 3.3 and Cordova 3.4 using npm install, and I have Ruby 2.0.0 installed as well. I'm running all this on a Mac OS X.
Onto the problem:
I create a phonegap app to test this plugin (phonegap create TestApp)
I add the Android platform (cordova platform add android)
I run phonegap local plugin add /path/to/plugin/folder from within my newly created app
I run phonegap build android and the compile fails with the following error:
[error] An error occurred while building the android project. Error executing "ant debug -f "/path/to/TestApp/platforms/android/build.xml"":
BUILD FAIL
/path/to/ant/build.xml:720: The following error occurred while executing this line:
/path/to/ant/build.xml:734: Compile failed; see the compiler error output for details.
Total time: 4 seconds
I don't understand why this is happening at all. When I install the plugin it seems like it's been added successfully and it appears within the plugins/android.json file.
At one point, the project automagically decided to compile properly (I don't know what made it work). I tried to access the plugin I had added by adding a line that reads var p = window.MyPlugin within the www/js/index.js, right after the app.receivedEvent('deviceready'); in the onDeviceReady function. I used console.log(p); and it turned out to be undefined, as if my plugin had never been loaded/initialized in the first place.
I suppose this is a problem within my plugin definition, since the Java part has been tested on an Android native app and it was working properly. Where did I go wrong with my plugin? What can I do to troubleshoot it? Why wasn't it initialized? Any help/guidance is very well-appreciated.
======UPDATE=====
I followed Dawson's suggestion to use cordova build android -d and here's the output I received:
[javac] /path/to/TestApp/platforms/android/src/com/phonegap/example/MyPlugin.java:10:
error: package com.phonegap.example.activity does not exist
[javac] import com.phonegap.example.activity.ExampleActivity;
This com.phonegap.example.activity package is defined within the myJar.jar file, so it seems that MyPlugin.java can't find the myJar.jar file.
I think the plugin.xml should be correctly taking care of the including the jar file during plugin installation. This is how it's being added in the plugin.xml:
<source-file src="src/android/libs/myJar.jar" target-dir="libs" />
Any ideas of what may be wrong here?
It's solved thanks to Dawson.
I ran cordova build android -d and viewed its output. Noticed misplaced libraries (myPlugin.java couldn't find myJar.jar) so I just moved them to the proper place as Dawson suggested.
Thanks a lot!

Phonegap 3.3.0 inappbrowser' s events are not firing

I use phonegap to develop an app. This app works with some apis so, i have to use inappbrowser plugin. But after phonegap 2.9.x versions, the plugin's events are not firing. You can look at this problem on this forum https://groups.google.com/forum/#!topic/phonegap/e5_5unC2fYs
. Apache has an announcement about it.announcement But it is not a solve. Because, when i try to use phonegap with dreamweaver, i can choose phonegap 2.9 version in Dreamweaver Build service and Inappbrowser events work on Android 4.x devices. So, the problem is not about Android version. The problem is about Phonegap version. For some sdks(admob,...) i have to use eclipse. And i cant create a Phonegap 2.9 version app with command line. Do you have any idea about to choose version when creating app. Or change downgrade phonegap version.
Thanks for you answers.
I haven't tested it myself, but if you're using phonegap build, you can try to include plugins in this format:
<gap:plugin name="org.apache.cordova.inappbrowser" />
, as well as the documented:
<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser" />
</feature>
<feature name="InAppBrowser">
<param name="ios-package" value="CDVInAppBrowser" />
</feature>
see this page for plugin details
I had some trouble upgrading from 2.9.0 to 3.3.0, and it turns out I included my plugins in this format:
<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />
, which for some reason didn't work, when I used the format my plugins started working again.
Hope this helps.
It turns out that my issue was not that the events weren't firing, but that there was a bug in my callback code (a ReferenceError). Since this callback was the first callback to be run when the InAppBrowser received a "loadstart" event, all future callbacks did not run since the first callback raised an exception, making it seem like the InAppBrowser wasn't firing any callbacks at all.
The way I found this was actually by manually evaluating the callback in weinre.
cordova.require('cordova/exec').nativeCallback('InAppBrowser115751764',1,
{
"url" : "http:\/\/example.com\/path",
"type" : "loadstart"
}
,1)
I got the above snippet by reviewing the verbose PhoneGap exec logs. You should also be able to find the callback ID by inspecting the cordova.callbacks object.
Try install cordova:
sudo npm install -g cordova
install plugin inappbrowser:
cordova plugin add org.apache.cordova.inappbrowser
now run:
phonegap run android

Android Phonegap 2.2 Network Connection: Class Not Found

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.

Categories

Resources