嗨,我已经创建了我的第一个android 应用程序来在特定时间播放声音,我的代码做得很好,我添加了声音播放的日期和时间列表。当我搜索更多关于如何在手机锁定为闹钟时播放声音时。最后我到达了我必须使用警报管理器。请我需要有人帮助我,因为我做不到。当我在声音播放下方添加的特定时间时,我想要。
注意:我使用接口类调用调用html文件到 android
public class WebAppInterface {
Context mContext;
public MediaPlayer mp = null;
public static boolean checked = false;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
mp = MediaPlayer.create(mContext,R.raw.sound);
}
@JavascriptInterface
public void playsound(String value ) throws ParseException {
//get current date time with Date()
String dateStr = "0, 3, 11, 9, 7, 2013";
SimpleDateFormat dateFormat = new SimpleDateFormat("ss,hh,mm,yyyy,MM,dd");
Time time = new Time();
System.out.println(dateFormat.format(time));
//1day
time.set(0, 3, 11, 9, 7, 2013);
time.set(0, 3, 18, 9, 7, 2013);
time.set(0, 5, 0, 9, 7, 2013);
time.set(0, 12, 1, 9, 7, 2013);
time.set(0, 3, 37, 9, 7, 2013);
time.set(0, 7, 0, 9, 7, 2013);
time.set(0, 8, 32, 9, 7, 2013);
//2day
time.set(0, 3, 11, 10, 7, 2013);
time.set(0, 3, 18, 10, 7, 2013);
time.set(0, 5, 0, 10, 7, 2013);
time.set(0, 12, 1, 10, 7, 2013);
time.set(0, 3, 37, 10, 7, 2013);
time.set(0, 7, 0, 10, 7, 2013);
time.set(0, 8, 31, 10, 7, 2013);
}
public class x extends Activity {
private MediaPlayer mediaplayer;
private String TAG;
Context mContext;
private IntentListener listener = new IntentListener();
WebAppInterface wb=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
//Call HTML Files
WebView myWebView = (WebView) findViewById(R.id.web_engine);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("file:///android_asset/index.html");
//Initialise WebAppInterface and pass this ref..
wb=new WebAppInterface(this);
myWebView.addJavascriptInterface(wb, "Android");
}
}