FORUMS PROFESSIONNELS
WINDEV
,
WEBDEV
et
WINDEV Mobile
Accueil
|
Messages récents
|
Connexion
|
Déconnexion
|
Français
Accueil
→
WINDEV Mobile 2024
→
Android and BroadcastReceiver
Android and BroadcastReceiver
Débuté par Meidell, 26 mar. 2018 08:23 - 2 réponses
Connectez-vous…
Meidell
#1
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
Signaler
0
0
ARV
#2
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.
Signaler
1
0
Meidell
#3
Membre enregistré
15 messages
Posté le 27 mars 2018 - 09:55
Thanks.
--
Erik
Signaler
0
0
→ Revenir à WINDEV Mobile 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (précédentes versions)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Type de recherche
Uniquement les sujets
Tous les messages
Période de recherche
Date indifférente
Moins d'une heure
Moins de 24 heures
Moins d'une semaine
Moins d'un mois
Moins d'un an
Annuler
Aperçu de votre message
Ajouter une image
Importer une image depuis une URL
Envoyer une image depuis un fichier de votre disque
Déposez ici un fichier ou cliquez sur "Parcourir..."
ou
Annuler
0%
WLangage
SQL
XML, HTML
JAVA, Javascript
Texte