Bom Dia Galera , necessito realizar uma pausa de 3 minutos entre uma repetição e outra do for, mas da erro force close.
segue codigo:
package com.example.panico;
import java.util.Calendar;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.os.Vibrator;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.widget.Toast;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.os.Vibrator;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.widget.Toast;
public class ScreenReceiver extends BroadcastReceiver
{
public static int contOn = 0, contOff = 0;
public static boolean wasScreenOn = true;
int minuto=0,segundo=0,minuto2=0,segundo2=0,tot1=0,tot2=0;
{
public static int contOn = 0, contOff = 0;
public static boolean wasScreenOn = true;
int minuto=0,segundo=0,minuto2=0,segundo2=0,tot1=0,tot2=0;
@Override
public void onReceive(final Context context, final Intent intent)
{
Vibrator v;
v=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
{
//Toast.makeText(context,"Deu Certo off"+contOff, Toast.LENGTH_LONG).show();
Log.e("MYAPP", "Deu Certo off"+contOff);
wasScreenOn = false;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
{
//Toast.makeText(context,"Deu Certo on -"+contOn, Toast.LENGTH_LONG).show();
Log.e("MYAPP", "Deu Certo on"+contOn);
wasScreenOn = true;
Calendar c = Calendar.getInstance();
segundo = c.get(Calendar.SECOND);
minuto = c.get(Calendar.MINUTE)*60;
if((tot1!=0)&&(tot1>(segundo+minuto)))
{
tot1 = segundo+minuto;
}else if (tot1==0)
{
tot1 = segundo+minuto;
}
if(contOn == 2)
{
contOn=1;
Calendar c2 = Calendar.getInstance();
segundo2 = c2.get(Calendar.SECOND);
minuto2 = c2.get(Calendar.MINUTE)*60;
tot2 += segundo2+minuto2;
Log.e("MYAPP", "tempo 1 "+tot1);
Log.e("MYAPP", "tempo 2 "+tot2);
if((tot2-tot1)<6)
{
v.vibrate(3000);
tot1 = 0;
tot2 = 0;
for(int i=0;i<MainActivity.suporte.length;i++)
{
if(MainActivity.suporte[i]!=null)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(MainActivity.suporte[i], null, "http://maps.google.com/maps?q="+MainActivity.latitude+""+MainActivity.longitude, null,null);
Log.e("MYAPP", "enviado para"+MainActivity.suporte[i]);
//Toast.makeText(context,"enviado para"+MainActivity.suporte[i], Toast.LENGTH_LONG).show();
}
try {
Thread.sleep(3000);
} catch (InterruptedException ie) {
//Handle exception
}
}
}else if((tot2-tot1)>6)
{
tot1 = 0;
tot2 = 0;
}
}else {
contOn++;
}
}
}
}
public void onReceive(final Context context, final Intent intent)
{
Vibrator v;
v=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
{
//Toast.makeText(context,"Deu Certo off"+contOff, Toast.LENGTH_LONG).show();
Log.e("MYAPP", "Deu Certo off"+contOff);
wasScreenOn = false;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
{
//Toast.makeText(context,"Deu Certo on -"+contOn, Toast.LENGTH_LONG).show();
Log.e("MYAPP", "Deu Certo on"+contOn);
wasScreenOn = true;
Calendar c = Calendar.getInstance();
segundo = c.get(Calendar.SECOND);
minuto = c.get(Calendar.MINUTE)*60;
if((tot1!=0)&&(tot1>(segundo+minuto)))
{
tot1 = segundo+minuto;
}else if (tot1==0)
{
tot1 = segundo+minuto;
}
if(contOn == 2)
{
contOn=1;
Calendar c2 = Calendar.getInstance();
segundo2 = c2.get(Calendar.SECOND);
minuto2 = c2.get(Calendar.MINUTE)*60;
tot2 += segundo2+minuto2;
Log.e("MYAPP", "tempo 1 "+tot1);
Log.e("MYAPP", "tempo 2 "+tot2);
if((tot2-tot1)<6)
{
v.vibrate(3000);
tot1 = 0;
tot2 = 0;
for(int i=0;i<MainActivity.suporte.length;i++)
{
if(MainActivity.suporte[i]!=null)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(MainActivity.suporte[i], null, "http://maps.google.com/maps?q="+MainActivity.latitude+""+MainActivity.longitude, null,null);
Log.e("MYAPP", "enviado para"+MainActivity.suporte[i]);
//Toast.makeText(context,"enviado para"+MainActivity.suporte[i], Toast.LENGTH_LONG).show();
}
try {
Thread.sleep(3000);
} catch (InterruptedException ie) {
//Handle exception
}
}
}else if((tot2-tot1)>6)
{
tot1 = 0;
tot2 = 0;
}
}else {
contOn++;
}
}
}
}
Grato
-- You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.






0 comentários:
Postar um comentário