Direct call on Android will restart the app

I have implemented plugin

based on Simon's answer ( Automatically assign a phone number on Android using PhoneGap ) in my own app.

But when I end the call, the application restarts, any idea what I can 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'm looking for Android documentation, but I couldn't find an answer to my question.

Any help would be appreciated :)

+3


source to share





All Articles