2013-02-25 2 views
0

Привет, ребята, я создал класс, и теперь я хочу установить Notification вовремя. Например, если кто-то нажимает кнопку, то через десять минут следует указать Notification.Как установить Уведомление вовремя

Код

TextView txtV; 
Button bnot; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.receiving); 
    txtV=(TextView)findViewById(R.id.txtV); 
    bnot=(Button)findViewById(R.id.bN); 
    bnot.setOnClickListener(this); 
    Bundle extras = getIntent().getExtras(); 
    if(extras !=null) { 
     String value = extras.getString("key"); //assign it. 
     txtV.setText("Remember :"+value); //set it to textview. 
     } 
    } 


@Override 
public void onClick(View v) { 
    // TODO Auto-generated method stub 
    Intent intent = new Intent(); 
     Bundle extras = getIntent().getExtras(); 
    String value = extras.getString("key"); //assign it. 
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 
    Notification noti = new Notification.Builder(this) 
    .setTicker("Remember") 
    .setContentTitle(value) 
    .setContentText("Notification content.") 
    .setSmallIcon(R.drawable.ic_launcher) 
    .setContentIntent(pIntent).getNotification(); 
    noti.flags=Notification.FLAG_AUTO_CANCEL; 
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    notificationManager.notify(0, noti); 

} 

} 

ответ

0

Начать сигнал на 10 менуэт с момента, когда кнопка была нажата

0
AlarmManager alarm = (AlarmManager)getActivity().getSystemService(Context.ALARM_SERVICE); 
Calendar cal = Calendar.getInstance(); 
//1000*60*10 = 10 minutes 
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 1000*60*10, pendingIntent); 
Смежные вопросы