MA 10 S

10.1 #26 BroadcastReceiver AUS^

10.3 #28 ProgressDialog MA

10.4 KeyEvent

10.5 #30 UML Statechart MfêS^Iffi^tJ

10.6 #31 MapView

10.7 #32 WebView

10.1 #26 : BroadcastReceiver

«{finals®» Activity m^M Intent m^ln Android ' ft Android IB ' S Android ^m&R^mrnnm Activity = ^T Activity ' ©fflMTO ^S Intent BoradcastReceiver m Service Mfimfr Activity X

' ilfflg^lSflfP^i User Um ° BroadcastReceiver m Service °

^ffiW^MM—ffl BroadcastReceiver I^TSB ' WikMM—M Activity TS Intent Android ' S Android BroadcastReceiver TSBX

2. m^^T<repeat_alarm>gffi ' BroadcastReceiver m^WSM^^W Alarm Mananger Intent ' Title MMl^ffi : "from AlarmReceiver"^^ :

3. $n^ffiT<stop_alarm>gffi ' Alarm Manager Intent T -

10.1.2 MMPB

Step-2: MM IntentReceiver ^A^^ : AlarmReceiver ' fig^l^T :

package com.misoo.kx01; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent;

public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { ac01 app = ac01.getApp(); app.btEvent("from AlarmReceiver");

package com.misoo.kx01;

import java.util.Calendar;

import android.app.Activity;

import android.app.AlarmManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.os.Bundle;

import android.os.SystemClock;

import android.widget.Button;

import android.view.View;

import android.view.View.OnClickListener;

public class ac01 extends Activity implements OnClickListener{ private static ac01 appRef = null; private Button btn, btn2; boolean k = false;

@Override protected void onCreate(Bundle icicle) {

super.onCreate(icicle);

appRef = this; setContentView(R.layout.repeat_alarm);

btn = (Button)findViewById(R.id.repeat_al); btn.setBackgroundResource(R.drawable.bk); btn. setOnClickListener(this); btn2 = (Button)findViewById(R.id.stop_al); btn2.setBackgroundResource(R.drawable.bk); btn2. setOnClickListener(this);

Intent intent = new Intent(ac01.this, AlarmReceiver. class); Pendinglntent p_intent = PendingIntent.getBroadcast(ac01.this, 0, intent, 0); Calendar calendar = Calendar.getInstance(); calendar. setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECCWD, 15);

// Schedule the alarm!

AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am. set( AlarmManager.RTC_ WAKEUP, calendar.getTimeInMillis(), p_intent);

public static ac01 getApp() { return appRef; } public void btEvent( String data ) { k = !k;

if(k) setTitle(data); else setTitle("wait...");

setTitle("Repeating...");

Intent intent = new Intent(ac01.this, AlarmReceiver. class); PendingIntent p_intent = PendingIntent.getBroadcast(ac01.this, 0, intent, 0);

// We want the alarm to go off 30 seconds from now. long firstTime = SystemClock.elapsedRealtime(); firstTime += 800;

// Schedule the alarm!

AlarmManager am = (AlarmManager)getSystemService(

ALARMSERVICE); am.setRepeating(AlarmManager.ELAPSED_RE4LTIME_WAKEUP, firstTime, 800, p_intent);

Intent intent = new Intent(ac01.this, AlarmReceiver. class); PendingIntent p_intent = PendingIntent.geffiroadcasi(ac01.this, 0, intent, 0); AlarmManager am = (AlarmManager)getSystemService(AZARM_SER^7C£); am.cancel(p_intent); finishO;

Step-4: AndroidManifest.xml ' :

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.misoo.kx01 "> <application android:icon="@drawable/icon">

<activity android:name=".ac01" android:label="@string/app_name"> <intent-filter>

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

<receiver android:name=".AlarmReceiver"> </receiver> </application> </manifest>

0 0

Post a comment