1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| public class Spam extends AppCompatActivity {
public int j = 0;
public static int recu = 1;
public int envoye = 1;
public int error = 0;
public String NBMESSAGE;
public String TOTALMESSAGE;
public String MESSAGE;
public TextView ecran;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spam);
Button btnEnvoie = findViewById(R.id.envoyer);
final EditText numero = findViewById(R.id.numTel);
final EditText message = findViewById(R.id.message);
final EditText nbFois = findViewById(R.id.nbSecondes);
final String SENT = "SMS_SENT" ;
final String DELIVERED = "SMS_DELIVERED" ;
final PendingIntent sentPI = PendingIntent.getBroadcast(this,0 ,new Intent(SENT), 0) ;
final PendingIntent deliveredPI = PendingIntent . getBroadcast ( this , 0 , new Intent ( DELIVERED ) , 0 ) ;
ecran = this.findViewById(R.id.ecran);
btnEnvoie.setOnClickListener(new OnClickListener() {
@SuppressLint("SetTextI18n")
public void onClick(View v) {
//On récupère ce qui a été entré dans les EditText
final String num = numero.getText().toString();
final String msg = message.getText().toString();
String NBFOIS = nbFois.getText().toString();
int nbFois2 = Integer.parseInt(NBFOIS);
//Si le numéro est supérieur à 4 charactère et que le message n'est pas vide on lance la procédure d'envoi
if (num.length() >= 4 && msg.length() > 0 && nbFois2 > 0) {
j = 0;
while (j != nbFois2) {
runOnUiThread(new Runnable() {
public void run() {
registerReceiver ( new BroadcastReceiver( ) {
@ Override
public void onReceive (Context arg0 , Intent arg1 ) {
switch ( getResultCode ( ) )
{
case Activity. RESULT_OK :
Log.i("msg envoye", Integer.toString(envoye));
envoye++;
break ;
case SmsManager . RESULT_ERROR_GENERIC_FAILURE :
Toast . makeText ( getBaseContext ( ) , "Generic failure" ,
Toast . LENGTH_SHORT ) . show ( ) ;
break ;
case SmsManager . RESULT_ERROR_NO_SERVICE :
Toast . makeText ( getBaseContext ( ) , "No service" ,
Toast . LENGTH_SHORT ) . show ( ) ;
break ;
case SmsManager . RESULT_ERROR_NULL_PDU :
Toast . makeText ( getBaseContext ( ) , "Null PDU" ,
Toast . LENGTH_SHORT ) . show ( ) ;
break ;
case SmsManager . RESULT_ERROR_RADIO_OFF :
Toast . makeText ( getBaseContext ( ) , "Radio off" ,
Toast . LENGTH_SHORT ) . show ( ) ;
break ;
}
}
} , new IntentFilter(SENT)) ;
}
});
runOnUiThread(new Runnable() {
public void run() {
registerReceiver ( new BroadcastReceiver () {
@ Override
public void onReceive ( Context arg0 , Intent arg1 ) {
switch ( getResultCode ( ) )
{
case Activity . RESULT_OK :
// Log.d("Message reçu :", "message recu");
Log.i("Message recu", "Message Recu");
recu++;
Log.i("msg recu", Integer.toString(recu));
/* Toast . makeText ( getBaseContext ( ) , "Message reçu !!" ,
Toast . LENGTH_SHORT ) . show ( ) ; */
break ;
case Activity . RESULT_CANCELED :
Log.i("msg error", Integer.toString(error));
error++;
break ;
}
}
} , new IntentFilter ( DELIVERED ) ) ;
}
});
SmsManager.getDefault().sendTextMessage(num, null, msg, sentPI, deliveredPI);
try{
Thread.sleep(50);
}catch(InterruptedException e){}
j++;
}
} else {
Toast.makeText(Spam.this, "Entrer le numero et/ou le message et/ou la quantité", Toast.LENGTH_SHORT).show();
}
/* AFFICHAGES */
numero.setText("");
message.setText("Bonjour, ceci est un message SPAM, courage !");
nbFois.setText("");
NBMESSAGE = String.valueOf(j);
TOTALMESSAGE = String.valueOf(nbFois2);
MESSAGE = NBMESSAGE + " sur " + TOTALMESSAGE + " envoyés";
ecran.setText(MESSAGE);
}
});
} |
Partager