-3

i want to create remainder, i have tried this code but is not working properly if i am setting alarm its not giving any response

here is MainActivity.java

package com.example.ltr_3.dtrem;
public class MainActivity extends Activity {
    TimePicker timePicker;
    DatePicker datePicker;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //---Button view---
        Button btnOpen = (Button) findViewById(R.id.btnSetAlarm);
        btnOpen.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                timePicker = (TimePicker) findViewById(R.id.timePicker);
                datePicker = (DatePicker) findViewById(R.id.date_picker_selected_date);

                //---use the AlarmManager to trigger an alarm---
                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

                //---get current date and time---
                Calendar calendar = Calendar.getInstance();

                //---sets the time for the alarm to trigger---
                calendar.set(Calendar.YEAR, datePicker.getYear());
                calendar.set(Calendar.MONTH, datePicker.getMonth());
                calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
                calendar.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
                calendar.set(Calendar.MINUTE, timePicker.getCurrentMinute());
                calendar.set(Calendar.SECOND, 0);

                //---PendingIntent to launch activity when the alarm triggers---
                Intent i = new Intent("com.example.ltr_3.dtrem.DisplayNotification");

                //---assign an ID of 1---
                i.putExtra("NotifID", 1);

                PendingIntent displayIntent = PendingIntent.getActivity(
                        getBaseContext(), 0, i, 0);

                //---sets the alarm to trigger---
                alarmManager.set(AlarmManager.RTC_WAKEUP,
                        calendar.getTimeInMillis(), displayIntent);
            }
        });
    }
}

MainActivity xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="hello" />

        <DatePicker android:id="@+id/date_picker_selected_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TimePicker android:id="@+id/timePicker"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button
            android:id="@+id/btnSetAlarm"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Set Alarm" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

AlarmDetail.java

package com.example.ltr_3.dtrem;

import android.app.Activity;
import android.app.NotificationManager;
import android.os.Bundle;

public class AlarmDetails extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alarmdetails);

        //---look up the notification manager service---
        NotificationManager nm = (NotificationManager)
                getSystemService(NOTIFICATION_SERVICE);

        //---cancel the notification---
        nm.cancel(getIntent().getExtras().getInt("NotifID"));
    }
}

DisplayNotification.java

package com.example.ltr_3.dtrem;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;

public class DisplayNotification extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //---get the notification ID for the notification;
        // passed in by the MainActivity---
        int notifID = getIntent().getExtras().getInt("NotifID");

        //---PendingIntent to launch activity if the user selects
        // the notification---
        Intent i = new Intent("com.example.ltr_3.dtrem.AlarmDetails");
        i.putExtra("NotifID", notifID);

        PendingIntent detailsIntent =
                PendingIntent.getActivity(this, 0, i, 0);

        NotificationManager nm = (NotificationManager)
                getSystemService(NOTIFICATION_SERVICE);
        Notification notif = new Notification(
                R.drawable.icon,
                "Time's up!",
                System.currentTimeMillis());

        CharSequence from = "AlarmManager - Time's up!";
        CharSequence message = "This is your alert, courtesy of the AlarmManager";
        notif.setLatestEventInfo(this, from, message, detailsIntent);

        //---100ms delay, vibrate for 250ms, pause for 100 ms and
        // then vibrate for 500ms---
        notif.vibrate = new long[] { 100, 250, 100, 500};
        nm.notify(notifID, notif);
        //---destroy the activity---
        finish();
    }
}

2 Answers2

0

It seems like you haven't really looked into this and while I'm not going to post every single bit of code you need to make the app I can point you in the right direction.

First of all I would look at the developer guide to have a base understanding of how audio recording works within android. You can find a link below to the Google developer guidelines.

http://developer.android.com/guide/topics/media/audio-capture.html

The next is a tutorial on how to record audio. What you can do is create an activity or fragment that implements this code.

http://www.tutorialspoint.com/android/android_audio_capture.html

The last link is another tutorial on how to capture audio but also shows you how to implement audio playback which I'm sure is another feature you will want to implement

http://www.techotopia.com/index.php/Android_Audio_Recording_and_Playback_using_MediaPlayer_and_MediaRecorder

One you have done the playback tutorial you can then implement alarm manager to play audio at a particular time on a particular day. Link is below

http://www.vogella.com/tutorials/AndroidTaskScheduling/article.html

I hope this helps you get on the right track.

Andy Joyce
  • 2,802
  • 3
  • 15
  • 24
0

Try Following links it may help you

use alarm manager calling the service.

Don,t forget to call the service in android manifest.xml

try this link

notification Particular time

Community
  • 1
  • 1
Android Dev
  • 421
  • 8
  • 26