How to use phonegap when developing native android app

I am developing android native app and having so many package in this. In this project am using webview where i am displaying html by consuming xslt. I want to use native alert of android instead of javascript alert.
How can i use phonegap in this scenario and where i need to change.

Upvotes: 0

Views: 479

Answers (2)

sourav
sourav

Reputation: 676

You can include the PhoneGap/Cordova js file and use Phonegap notification API to display native alert instead of js alert.

alert("This is a normal javascript alert");

navigator.notification.alert("This is a PhoneGap notification alert");

For more info you can follow this link

http://docs.phonegap.com/en/edge/cordova_notification_notification.md.html#Notification

Upvotes: 1

Radek Pech
Radek Pech

Reputation: 3098

You should write a Cordova (PhoneGap) plugin to handle the alert:

public class AlertPlugin extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("alert")) {
        callbackContext.success(alert(args.getString(0))); //alert() is your method to display an alert ;)
        return true;
    }
            return false;
}

Then you can overwrite Javascripts alert method to call the plugin:

window.alert = function(message) {
    var callback = function() {}; //add some handle code here!!!
    cordova.exec(callback, callback, 'AlertPlugin', 'alert', [message]);
}

Upvotes: 0

Related Questions