mybebe us
Posts: 0
Joined: Fri Mar 14, 2014 8:42 pm

Using a 3rd party plugins

I'm tying to add a third party plugins,
https://github.com/Ankama/phonegap-sy...

I've checked the tutorial and I believe I understand the procedure.
Here is what I did"

  1. Added sysinfo.js in the folder plugins/com.ankamagames.plugins.sysinfo/www

  2. Added sysinfo.java in the folder /com/ankamagames/plugins/sysinfo

  3. Modifying cordova_plugin.js by Adding following code in
    "file": "plugins\\com.ankamagames.plugins.sysinfo\\www\\Sysinfo.js",
    "id": "com.ankamagames.plugins.sysinfo",
    "clobbers": [
    "Sysinfo"

  4. Modified config.xml by Adding following

    param name="android-package" value="com.ankamagames.plugins.sysinfo.Sysinfo"

    But I encountered some compile errors below:

    /SysInfoApp/src/com/ankamagames/plugins/sysinfo/Sysinfo.java:[3,25] error: package android.annotation does not exist /SysInfoApp/src/com/ankamagames/plugins/sysinfo/Sysinfo.java:[83,2] error: cannot find symbol class Sysinfo /SysInfoApp/src/com/ankamagames/plugins/sysinfo/Sysinfo.java:[85,50] error: cannot find symbol class VERSION_CODES /SysInfoApp/src/com/ankamagames/plugins/sysinfo/Sysinfo.java:[86,25] error: cannot find symbol

    My questions are:

  5. What's problem with my procedure?

  6. The location of the java file should be the "com/phonegap/plugins/sysinfo" instead of "/com/ankamagames/plugins/sysinfo"?

  7. Why cannot I access all the java files form the source view? Is this a bug?

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Using a 3rd party plugins

Hello,

[quote:]

  1. What's problem with my procedure?
    [/quote]
    What min. and target SDK version did you set on android binary tab?http://docs.appery.io/documentation/a...
    [quote:]

  2. The location of the java file should be the "com/phonegap/plugins/sysinfo" instead of "/com/ankamagames/plugins/sysinfo"?
    [/quote]
    It should be com/ankamagames/plugins/sysinfo
    [quote:]

  3. Why cannot I access all the java files form the source view? Is this a bug?
    [/quote]

    Yes, it is a bug. Should be fixed in the next releases.

    According this error
    pre
    code
    SysInfoApp/src/com/ankamagames/plugins/sysinfo/Sysinfo.java:[3,25] error: package android.annotation does not exist
    /code
    /pre
    Min SDK ver. should be Android 4.1 APIs.
    http://developer.android.com/referenc...

mybebe us
Posts: 0
Joined: Fri Mar 14, 2014 8:42 pm

Using a 3rd party plugins

Thank you for your answer.
I set the Min SDK ver to Android 4.1 but still have same error.

It seems that the compiler cannot import android package at all. Is there any setting to modify?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Using a 3rd party plugins

Hello!
Looks like yo have done everything correctly.
Please post entire code using < code tags.

mybebe us
Posts: 0
Joined: Fri Mar 14, 2014 8:42 pm

Using a 3rd party plugins

Added the following in codova_plugins.js
code
{
"file": "plugins\com&#46;ankamagames&#46;plugins&#46;sysinfo\www\SysInfo&#46;js",
"id": "com&#46;ankamagames&#46;plugins&#46;sysinfo",
"clobbers": [
"window&#46;Sysinfo"
]
}
/code

Added the following in config.xml
code
<feature name="Sysinfo" >
<param name="android-package" value="com&#46;ankamagames&#46;plugins&#46;sysinfo"/>
</feature>
/code

Here is Sysinfo.java
code
package com&#46;ankamagames&#46;plugins&#46;sysinfo;

import android&#46;annotation&#46;TargetApi;
import android&#46;app&#46;Activity;
import android&#46;app&#46;ActivityManager;
import android&#46;app&#46;ActivityManager&#46;MemoryInfo;
import android&#46;os&#46;Build;

import org&#46;apache&#46;cordova&#46;CallbackContext;
import org&#46;apache&#46;cordova&#46;CordovaPlugin;
import org&#46;json&#46;JSONArray;
import org&#46;json&#46;JSONObject;

import java&#46;lang&#46;Process;
import java&#46;io&#46;IOException;
import java&#46;io&#46;InputStream;
import java&#46;util&#46;Scanner;

import android&#46;util&#46;*;

public class Sysinfo extends CordovaPlugin {
private MemoryInfo memoryInfo;

@Override
public boolean execute(String action, JSONArray args, CallbackContext callback) {

Activity activity = this&#46;cordova&#46;getActivity();
ActivityManager m = (ActivityManager) activity&#46;getSystemService(Activity&#46;ACTIVITY_SERVICE);
this&#46;memoryInfo = new MemoryInfo();
m&#46;getMemoryInfo(this&#46;memoryInfo);

if (action&#46;equals("getInfo")) {
try {
JSONObject r = new JSONObject();
r&#46;put("cpu", this&#46;getCpuInfo());
r&#46;put("memory", this&#46;getMemoryInfo());
Log&#46;d("OUTPUT", r&#46;toString());
callback&#46;success(r);
} catch (final Exception e) {
callback&#46;error(e&#46;getMessage());
}
}

return false;
}

public JSONObject getCpuInfo() {
JSONObject cpu = new JSONObject();
try {
&#47;&#47; Get CPU Core count
String output = readSystemFile("/sys/devices/system/cpu/present");
String[] parts = output&#46;split("-");
Integer cpuCount = Integer&#46;parseInt(parts[1]) + 1;

Code: Select all

cpu&#46;put("count", cpuCount); 

&#47;&#47; Get CPU Core frequency 
JSONArray cpuCores = new JSONArray(); 
for(int i = 0; i < cpuCount; i++) { 
 Integer cpuMaxFreq = getCPUFrequencyMax(i); 
 cpuCores&#46;put(cpuMaxFreq == 0 ? null : cpuMaxFreq); 
} 

cpu&#46;put("cores", cpuCores); 

} catch (final Exception e) { }
return cpu;
}

public JSONObject getMemoryInfo() {
JSONObject memory = new JSONObject();
try {
memory&#46;put("available", this&#46;memoryInfo&#46;availMem);
memory&#46;put("total", this&#46;getTotalMemory());
memory&#46;put("threshold", this&#46;memoryInfo&#46;threshold);
memory&#46;put("low", this&#46;memoryInfo&#46;lowMemory);
} catch (final Exception e) {

}
return memory;
}

@TargetApi(Build&#46;VERSION_CODES&#46;JELLY_BEAN)
public Object getTotalMemory() {
if (Build&#46;VERSION&#46;SDK_INT >= Build&#46;VERSION_CODES&#46;JELLY_BEAN) {
return this&#46;memoryInfo&#46;totalMem;
}
else {
return null;
}
}

/**

  • @return in kiloHertz&#46;

  • @throws SystemUtilsException
    */
    public int getCPUFrequencyMax(int index) throws Exception {
    return readSystemFileAsInt("/sys/devices/system/cpu/cpu" + index + "/cpufreq/cpuinfo_max_freq");
    }

    private String readSystemFile(final String pSystemFile) {
    String content = "&quot
    InputStream in = null;
    try {
    final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile })&#46;start();
    in = process&#46;getInputStream();
    content = readFully(in);
    } catch (final Exception e) { }
    return content;
    }

    private int readSystemFileAsInt(final String pSystemFile) throws Exception {
    String content = readSystemFile(pSystemFile);
    if (content == "") {
    return 0;
    }
    return Integer&#46;parseInt( content );
    }

    private String readFully(final InputStream pInputStream) throws IOException {
    final StringBuilder sb = new StringBuilder();
    final Scanner sc = new Scanner(pInputStream);
    while(sc&#46;hasNextLine()) {
    sb&#46;append(sc&#46;nextLine());
    }
    return sb&#46;toString();
    }
    }
    /code

    and Sysinfo.js file
    code
    /*
    *

  • Licensed to the Apache Software Foundation (ASF) under one

  • or more contributor license agreements&#46; See the NOTICE file

  • distributed with this work for additional information

  • regarding copyright ownership&#46; The ASF licenses this file

  • to you under the Apache License, Version 2&#46;0 (the

  • "License"); you may not use this file except in compliance

  • with the License&#46; You may obtain a copy of the License at
    *

  • http:&#47;&#47;www&#46;apache&#46;org/licenses/LICENSE-2&#46;0
    *

  • 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&#46; See the License for the

  • specific language governing permissions and limitations

  • under the License&#46;
    *
    */

    var argscheck = require('cordova/argscheck'),
    channel = require('cordova/channel'),
    utils = require('cordova/utils'),
    exec = require('cordova/exec'),
    cordova = require('cordova');

    function Sysinfo() {
    this&#46;available = false;
    this&#46;cpu = null;
    this&#46;memory = null;

    var self = this;

    channel&#46;onCordovaReady&#46;subscribe(function() {
    self&#46;getInfo(function(info) {
    self&#46;available = true;
    self&#46;cpu = info&#46;cpu;
    self&#46;memory = info&#46;memory;
    },function(e) {
    self&#46;available = false;
    &#47;&#47;utils&#46;alert("[ERROR] Error initializing Cordova: " + e);
    });
    });
    }

    /**

  • Get system info
    *

  • @param {Function} successCallback The function to call when the heading data is available

  • @param {Function} errorCallback The function to call when there is an error getting the heading data&#46; (OPTIONAL)
    */
    Sysinfo&#46;prototype&#46;getInfo = function(successCallback, errorCallback) {
    exec(successCallback, errorCallback, "Sysinfo", "getInfo", []);
    };

    module&#46;exports = new Sysinfo();
    /code

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Using a 3rd party plugins

Hello!

In the beginning of Sysinfo.js file add these lines precordova&#46;define("com&#46;ankamagames&#46;plugins&#46;sysinfo",

Code: Select all

 function (require, exports, module) {/preand this line in the end pre });/pre
mybebe us
Posts: 0
Joined: Fri Mar 14, 2014 8:42 pm

Using a 3rd party plugins

Hi Maryna,

I added what you said but still have the same errors. I don't know what's going on.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Using a 3rd party plugins

Please post or send project GUID to a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a so we can check logs.

mybebe us
Posts: 0
Joined: Fri Mar 14, 2014 8:42 pm

Using a 3rd party plugins

Where can I find the project GUID?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Using a 3rd party plugins

Sorry, it is in your app link.
For instance prehttps:&#47;&#47;appery&#46;io/app/projects/abdc5a54-a5ac-4e45-a9c7-b3f29dc78c85/pre
GUID is abdc5a54-a5ac-4e45-a9c7-b3f29dc78c85

Return to “Issues”