3

I've implemented a plugin based on Simon“s answer (Call predefined number automatically on Android with PhoneGap) on my own application sucssesfully.

But when I end the call, the application restarts, any idea of what can i do?

This is my code

package com.phonegap.plugin;


import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;

import android.content.Intent;
import android.net.Uri;

/**
 * This class echoes a string called from JavaScript.
 */
public class DirectCall extends Plugin {

@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    try {
        if (action.equals("call")) {
            String number = "tel:" + args.getString(0);
            Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number)); 
            this.cordova.getActivity().startActivity(callIntent);
        }
        else {
            status = PluginResult.Status.INVALID_ACTION;
        }
        return new PluginResult(status, result);
    } catch (JSONException e) {
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
}


}

I search android documentation, but I did not find answer to my question.

Any help will be appreciated :)

Community
  • 1
  • 1

0 Answers0