Trying to Embed Cordova app into Native Android - android

When I try to follow the guide of Cordova to embed it into a native android application I can't build.
I use this guide:
https://cordova.apache.org/docs/en/latest/guide/platforms/android/webview.html
When I put everything in my main activity I receive an error on config.
It says can't resolve symbol 'config'. I have no clue what I am doing wrong or how to solve it.
onCreate
/* Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cwv = (CordovaWebView) findViewById(R.id.tutorialView);
config.init(this);
cwv.loadUrl(config.getStartUrl());
}

Related

IBM Worklight 6.1 [Application Error] There was a network error (file:///android_asset/www/index.html)

On android: The app sometimes gives [Application Error] There was a network error (file:///android_asset/www/index.html).
searched in others answers but not worked.
Below is my Appname.js in the path:
android/native/src/common/Appname/Appname.java
public class appName extends WLDroidGap {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
/**
* onWLInitCompleted is called when the Worklight runtime framework initialization is complete
*/
#Override
public void onWLInitCompleted(Bundle savedInstanceState){
super.loadUrl(getWebMainFilePath());
// Add custom initialization code after this line
}
}
How can I achieve this?
What is it both index.html and appname.java/js?
In Worklight 6.1.0.x, a new application is given index.html and main.js/main.css/appname.java
Did you rename any of your project files?
What is the value for mainFile in application-descriptor.xml? Make sure it is "index.html".

Viewdidappear equivalent method in android

In android i need to check files exist every time when the app is launched,i need to know the method in android which will be called when the app is launched,on create is called once when app is deployed first,but i need check each time when app is relaunched again?
Oncreate Method of your first activity will call everytime when application launch.so, put below code for checking file existance.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File f = new File(filePathString);
if(f.exists())
{
/* do something */
}
else
{
/* do something */
}

google play service mainactivity

I've implemented the Google Play Services demo code found at this url:
https://github.com/kpbird/google-play-service/blob/master/src/com/kpbird/googleplayservice/MainActivity.java
And everything works. However if the function getAccountNames() is called within onCreate, the application momentarialy flashes before loading the set content view. It's like there are two activity views are being initiatied.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtAccount = (TextView) findViewById(R.id.txtAccount);
txtToken = (TextView) findViewById(R.id.txtToken);
getAccountNames();
}
Why would placing getAccountNames() in the onCreate create this visual effect when the application launches.

CCGLSurfaceView Error

I'm developing some sample code.
I had some problem using cocos2d.
That is the CCGLSurfaceView problem.
Firstly, I imported cocos2d.jar in my project with fps_images.png file.
And i modify my project for using the cocos2d library.
Here are the code.
public class ToadActivity extends Activity {
protected CCGLSurfaceView _glSurfaceView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
_glSurfaceView = new CCGLSurfaceView(this);
setContentView(_glSurfaceView);
}
#Override
public void onStart()
{
super.onStart();
CCDirector.sharedDirector().attachInView(_glSurfaceView);
CCDirector.sharedDirector().setDisplayFPS(true);
CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);
}
}
==>>> _glSurfaceView = new CCGLSurfaceView(this);
Here, My application found a error. And at the result, it is killed in my android simulator.
What's the problem?
That library are decreated, not update more. It will be better start using: http://www.cocos2d-x.org/. It use c++, to work on android, use JNI (Native code). Code can be ported to other plataforms, like IOs.
Hope it help!

Android App with PhoneGap: InvocationTarget Exception by calling addJavascriptInterface

I am using the Android SDK and PhoneGap to create a native Android App. Now I want to use Java methods in the view, calling by JS methods.
In the Main Class I called the "addJavascriptInterface" method to bind a java class with the view.
public class App extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
appView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
super.loadUrl("file:///android_asset/www/index.html");
}
}
The problem is I get an InvocationTarget Exception when the programm executes the line "appView.addJavascript..." and the program crashes on the device.
Any solutions here?
Thanks!
Calling Java methods from JavaScript is exactly what PhoneGap plugins enable. Checkout several examples here
Using addJavascriptInterface before super.init(); can make the application crash.
You should try the following :
public class App extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
appView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
super.loadUrl("file:///android_asset/www/index.html");
}
}

Categories

Resources