I am new to PhoneGap. I am using it to deploy my website on android phone. So I created www folder in assets folder and put all my HTML, CSS an js file and written this code to call the index.html page
import org.apache.cordova.DroidGap;
import android.app.ActionBar;
import android.os.Bundle;
import android.view.Window;
public class HelloPhoneGapActivity extends DroidGap {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
Every thing is working fine but now I have to add Action Bar with close button on every page. I don't know how to do that.
Use navigator.app.exitApp(); to exit the application. Either do it on the click of a button or override the back key.
UPDATE:
Create a listener like this
document.addEventListener("backbutton", onBackClickEvent, true);
Then in the onBackClickEvent() write this
function onBackClickEvent() {
navigator.app.exitApp();
}
Related
Creating a webbrowser custom!
I or WE need a custom webbrowser , so far i have a webviewer, or so it seems... i wish that it doesn't start running the current webbrowser on my Phone
so briefly
I want a custom webbrowser ...
visit most recent visited pages ...
avoid running google chrome or any other Webbrowser app on my phone
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView ourBrowser = (WebView)findViewById(R.id.wvBrowser);
ourBrowser.loadUrl("http://www.google.com");
}
}
You can use Zirco browser. It is open source and based on Webview. You can further customize it for your need.
I have an app with embedded CordovaWebView. Accroding to inctruction, in that case i shouldn't extend my activity from DriodGap.
public class CordovaViewTestActivity extends Activity implements CordovaInterface {
CordovaWebView cwv;
/* Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cwv = (CordovaWebView) findViewById(R.id.tutorialView);
cwv.loadUrl("file:///android_asset/www/index.html");
}
}
But i need to use splashscreem. Accroding to instruction, i must do like that:
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("file:///android_asset/www/index.html", 10000);
But my Activity isn't extends from DroidGap.
How can i solve this problem?
Edit your project's main Java file found in the src folder in Eclipse:
Do the following:
Add import org.apache.cordova.*;
Change the class's extend from Activity to DroidGap
more details...
You can implement a regular android splash screen. Here is a good stackoverflow discussion about android splash screen: How do I make a splash screen?
Another way to give the impression of a splash screen is to make your landing page to look like a splash screen and insert a javascript function that will be called after few seconds and will call your current landing page (this way you have "splash screen" for all platforms).
A javascript function can look like the following (assuming your main page is 'index.html':
function loadMainPage(){
setTimeout(function(){this.document.location.href = "index.html"}, 2000);
}
I have a WebView app that I want to behave like this:
The user can follow any link and the new page is opened inside the same WebView, except if the target is YouTube in which case I want two possible scenarios:
Open the YouTube Android app to view the video
Open the standard browser to view the video.
My main activity is as follows:
package com.prgguru.android;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.webkit.WebView;
#SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {
WebView browser;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
browser=(WebView)findViewById(R.id.webkit);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setDefaultFontSize(20);
browser.loadUrl("http://exo-agency.com/funnytube/");
}
}
Thanks in advance.
this is my first app for android, I've been an iPhone dev for 3 years, it's been a change of mindset, and I still find some things odd. First I don't know if this iPhone background might be causing some troubles, but here's what I'm trying to do:
I want to implement an ActionBar with two options working like a TabBar from iOS:
What I want is that when the user selects an action, some Activity will be presented to the user.
Here's what I'm doing so far (which isn't that much):
I'm Using ActionBarSherlock, I have 3 activities: myApp, First and Second
myapp.java only creates the ActionBar elements and loads the activity_first:
package com.example.myApp;
import com.actionbarsherlock.ActionBarSherlock;
import com.actionbarsherlock.view.MenuItem;
import android.os.Bundle;
import com.actionbarsherlock.ActionBarSherlock.OnCreateOptionsMenuListener;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
public class myApp extends SherlockActivity implements OnCreateOptionsMenuListener {
ActionBarSherlock mSherlock = ActionBarSherlock.wrap(this);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("myApp");
mSherlock.setContentView(R.layout.activity_first);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("First")
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add("Second")
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true;
}
}
The activities have nothing so far, apart from the generated stub:
import android.app.Activity;
import android.os.Bundle;
public class First extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
}
}
So I have 1 Question and 1 problem:
Question: Is this the correct use of an ActivityBar? I mean, should it be used to switch activities?
Problem: As you can see in the OnCreate method of myApp class, I'm loading the activity_first, It does load the activity, however it loads the ActionBar Twice, like so:
I don't get why is it being loaded twice. If I remove the line: mSherlock.setContentView(R.layout.activity_first); it loads the Bar once, obviously I need to load the activity...
Also I've assigned the NoActionBar theme to the activity_first in the graphical editor of the XML (activity_first.xml), but it doesn't work. What Can I do to load it just once.
Thank you for your valuable time.
Is this the correct use of an ActivityBar? I mean, should it be used to switch activities?
You can think of "First" and "Second" as being the equivalent of toolbar buttons in a desktop app. You are welcome to have those action bar items start up activities if you wish.
As you can see in the OnCreate method of myApp class, I'm loading the activity_first, It does load the activity, however it loads the ActionBar Twice, like so:
Delete this line:
ActionBarSherlock mSherlock = ActionBarSherlock.wrap(this);
and change mSherlock.setContentView(R.layout.activity_first); to just setContentView(R.layout.activity_first);. I believe that will clear up your problems.
I am developing an android app using phonegap (cordova-2.1.0).
My MainActivity.java code is as following -
package com.app.myapp;
import android.os.Bundle;
import org.apache.cordova.*;
public class MainActivity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
Problem : Whenever I start the application, it shows MainActivity window first and then show the actual HTML code. Is there any way to get rid of MainActivity and show the HTML directly?
Thanks in Advance...
Add this to your AndroidManifest application tag:
android:theme="#android:style/Theme.NoTitleBar"
Should do the trick.