isso , desculpa o erro, pausa de 3 segundos
2013/6/4 luciofm <luciofm@gmail.com>
1. Nunca bloqueie a UI Thread.2. Sobre BroadcastReceivers: When it runs on the main thread you should never perform long-running operations in it (there is a timeout of 10 seconds that the system allows before considering the receiver to be blocked and a candidate to be killed). You cannot launch a popup dialog in your implementation of onReceive().Lúcio Maciel
luciofm@gmail.comOn Tue, Jun 4, 2013 at 11:39 AM, Maicon Strey <mstrey@gmail.com> wrote:o que aparece no logcat?Thread.sleep(3000); vai fazer uma pausa de 3 segundos e não de 3 minutos.Maicon Strey
Novo Hamburgo - RS - Brasil
------------------------------------Linux user: #525086On Tue, Jun 4, 2013 at 11:35 AM, Rafael Pedro <rafaelpedro.100@gmail.com> wrote: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;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;@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++;
}
}
}
}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.
--
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.
--
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.
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