PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Java class in Windev
Java class in Windev
Iniciado por Meidell, 05,mar. 2018 15:35 - No hay respuesta
Miembro registrado
15 mensajes
Publicado el 05,marzo 2018 - 15:35
Hi, I am trying (desperately) to make the following class work in windev mobile 23. It is supposed to show a custom made toast every time the phone calls. It works fine in android studio...but I am struggeling in windev mobile 23. I have allready added that class as java and that works fine, but I am not sure how to call this class within the windev code.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

/**
* Created by janerikmeidell on 07.02.18.
*/

public class PhoneStateReceiver extends BroadcastReceiver{

public void onReceive( Context context, Intent intent) {
try {
System.out.println("Receiver start");
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

//Toast.makeText(context," Receiver start ",Toast.LENGTH_SHORT).show();
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
//Toast.makeText(context,"Ringing State Number is -",Toast.LENGTH_SHORT).show();

LayoutInflater inflater = (LayoutInflater) context.getSystemService( context.LAYOUT_INFLATER_SERVICE );
View layout = inflater.inflate(R.layout.toast, null, false);
ViewGroup container = (ViewGroup) layout.findViewById(R.id.custom_toast_container);
ImageView img = (ImageView) layout.findViewById(R.id.img);

Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();


}
if ((state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))){
Toast.makeText(context,"Received State",Toast.LENGTH_SHORT).show();
}
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
Toast.makeText(context,"Idle State",Toast.LENGTH_SHORT).show();
}
}
catch (Exception e){
e.printStackTrace();
}
}

}

--
Erik