PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → Android and BroadcastReceiver
Android and BroadcastReceiver
Débuté par Meidell, 26 mar. 2018 08:23 - 2 réponses
Membre enregistré
15 messages
Posté le 26 mars 2018 - 08:23
Hi, I would like to introduce the following class in android java, as class or procedure. Any way works as long as I can get it to work (and show a toast when somebody calls). Can you help?

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;


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();

}
}
catch (Exception e){
e.printStackTrace();
}
}

}

--
Erik
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 26 mars 2018 - 17:25
Hi Meidell

I only know that you can only import the libs on the top of the procedure, you can't put a class but you can put your methods on the procedure.
So in the end it's like it said procedure = methods.

best regards.
Membre enregistré
15 messages
Posté le 27 mars 2018 - 09:55
Thanks.

--
Erik