Alarm Schedule After some times:
Alarm Schedule After some times: à
Like Clash of royal chest Box [take 3/1 hours to open]
=============================.
1. Take time as milliseconds from user :- activity.xml file
2. Make a Java class [ Alarm.java ] which extend by BroadcastReceiver class …
|
public class Alarm extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, “Alarm ..... “, Toast.LENGTH_LONG).show(); Vibrator v = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(10000); } } |
3. Change the [ AndroidManifest.xml ] file à last part of
<application>
………………….
|
<receiver android:name=”.Alarm”/>
|
</application>
4.1. Take user permission for vibration / vibrator in manifest
|
<uses-permission android:name=”android.permission.VIBRATE”/>
|
a. Take time as integer ;
b. Make intent to à Alarm.java
c. Make pendingIntent
d. Create alarmManager with alarm_service
e. Set Alarm as RTC_Wakeup
|
int time = Integer.parseInt(TimeET.getText().toString()); Intent i =new Intent(MainActivity.this,Alarm.class); PendingIntent [WU1] pi = PendingIntent.getBroadcast(getApplicationContext(),0,i[WU2] ,0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis()+time*1000,pi); |
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন