package jml.JmlPhoneCall; import android.content.Context; import android.util.Log; import com.google.appinventor.components.annotations.*; import com.google.appinventor.components.runtime.*; import com.google.appinventor.components.common.ComponentCategory; import android.telecom.TelecomManager; import android.Manifest; import android.content.Intent; import android.net.Uri; import androidx.core.app.ActivityCompat; import android.content.pm.PackageManager; import androidx.core.content.ContextCompat; import androidx.annotation.RequiresApi; import android.media.AudioManager; @DesignerComponent(version = 2, description = "gestion appel telephoniques" + "jm Latour", category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "https://community.appinventor.mit.edu/uploads/default/original/3X/e/8/e8acc2352c46f40da15a9703a861513375a3ec45.png") @UsesPermissions(permissionNames = "android.permission.ANSWER_PHONE_CALLS") @SimpleObject(external = true) public class JmlPhoneCall extends AndroidNonvisibleComponent implements Component{ private ComponentContainer container; public Context context; public AudioManager audioManager; private int UI; /** * @param container container, component will be placed in */ public JmlPhoneCall(ComponentContainer container) { super(container.$form()); this.container = container; context = container.$context(); audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); UI=0; } @SimpleFunction(description = "EndCall") //@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void EndCall() { TelecomManager tm = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); if (ActivityCompat.checkSelfPermission(context,Manifest.permission.ANSWER_PHONE_CALLS) != PackageManager.PERMISSION_GRANTED) { return; } if (tm != null) { boolean success = tm.endCall(); // success == true if call was terminated. Log.d("JML", "Raccroché **" + success); } } @SimpleFunction(description = "true if call ended") public boolean HasCallEnded() { TelecomManager tm = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); boolean success = false; if (ActivityCompat.checkSelfPermission(context,Manifest.permission.ANSWER_PHONE_CALLS) != PackageManager.PERMISSION_GRANTED) { return false; } if (tm != null) { success = tm.endCall(); // success == true if call was terminated. Log.d("JML", "Raccroché **" + success); } return success; } @SimpleFunction(description = "AcceptRingingCall") public void AcceptRingingCall() { TelecomManager tm = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); if (tm != null) { if (ActivityCompat.checkSelfPermission(context,Manifest.permission.ANSWER_PHONE_CALLS) != PackageManager.PERMISSION_GRANTED) { return; } tm.acceptRingingCall(); Log.d("JML","acceptRingingCall **" ); } } @SimpleFunction(description = "in-call volume UP") public void InCallVolumeUp() { audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)+1, UI); } @SimpleFunction(description = "in-call volume Down") public void InCallVolumeDown() { audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)-1, UI); } @SimpleProperty(description = "get Max in-call Volume") public int GetMaxVolume() { return methodMaxInCallVolume(); } public int methodMaxInCallVolume(){ return audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL); } @SimpleProperty(description = "get Actal in-call Volume") public int GetInCallVolume() { return methodGetInCallVolume(); } public int methodGetInCallVolume(){ return audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL); } @SimpleProperty(description = "Set in-call volume") public void InCallVolume(int vol) { audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, vol, UI); } @SimpleProperty public void ShowUI(boolean UI) { if(UI) this.UI=1; else this.UI=0; } /* public void call(String num){ android.util.Log.d("gestionappeltelephone", "Call ** : " + num); Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:" + num)); if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { return; } startActivity(intent); } */ }