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”/>

5. 1.    MainActivity.java à
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);


PendingIntent is a token that you give to a foreign application (e.g. NotificationManager , AlarmManager , Home Screen AppWidgetManager , or other 3rd party applications), which allows the foreign application to use your application's permissions to execute a predefined piece of code.
Intent to Alarm class
 -----------------------------------------------------------------------------------------------------------------

মন্তব্যসমূহ

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

API (Application Programming Interface) .

Add Gif file in Android xml file