views:

70

answers:

1
public class Alarm extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Intent intent = new Intent(this, AlarmReceiver.class);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
        intent, PendingIntent.FLAG_ONE_SHOT);

        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10 * 1000), pendingIntent);
        Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
    }
}

and

public final class AlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();
    }
}

After 10 secs am gettign toast as alarm worke..but no default sound ?how get the sound for alarm in android and instead of toas how can i display an dialog..?

+1  A: 

AlarmManager has nothing to do with sounds. You are perhaps confusing AlarmManager with an alarm clock application. You are welcome to play a sound via your BroadcastReceiver, though I have not tried this.

CommonsWare
CommonsWare..how can i play sound via broadcastReceiver..?please help me.
Sridhar Bandi