我想创建剩余部分,我已经尝试过这段代码,但如果我设置闹钟它没有给出任何回复,则无法正常工作
这是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();
}
}
答案 0 :(得分:0)
看起来你还没有真正研究过这个问题,虽然我不会发布你需要制作应用程序的每一段代码,但我可以指出你正确的方向。
首先,我会看一下开发者指南,了解音频录制在android中的工作原理。您可以在下方找到Google开发人员指南的链接。
http://developer.android.com/guide/topics/media/audio-capture.html
接下来是关于如何录制音频的教程。您可以做的是创建一个实现此代码的活动或片段。
http://www.tutorialspoint.com/android/android_audio_capture.html
最后一个链接是关于如何捕获音频的另一个教程,但也向您展示了如何实现音频播放,我确信这是您想要实现的另一个功能
您已完成播放教程,然后您可以实施警报管理器,以便在特定日期的特定时间播放音频。链接在
之下http://www.vogella.com/tutorials/AndroidTaskScheduling/article.html
我希望这可以帮助你走上正确的轨道。
答案 1 :(得分:0)
尝试以下链接,它可能会对您有所帮助
使用闹钟管理器调用该服务。
不要忘记在android manifest.xml中调用该服务