android 简单闹铃,Android_android闹铃简单实现,1.闹铃activity http://schemas.android - phpStudy...

android闹铃简单实现

1.闹铃activity

http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="设置时间"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/setTime"

android:text="设置铃声"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/setRing"

android:text="设置完成"/>

3.广播接收闹铃信息:

package com.example.myalarm;

import java.io.IOException;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.media.MediaPlayer;

import android.net.Uri;

import android.util.Log;

import android.widget.Toast;

public class AlarmBroadcastReceiver extends BroadcastReceiver {

Uri ringUri;

@Override

public void onReceive(Context context, Intent intent) {

String msg = intent.getStringExtra("msg");

Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();

MediaPlayer mp = new MediaPlayer();

String uri = intent.getStringExtra("ringURI");

if (uri!=null) {

ringUri = Uri.parse(uri);

Log.d("AlarmActivity", ringUri.toString());

}

try {

mp.setDataSource(context, ringUri);

mp.prepare();

} catch (IllegalArgumentException e) {

e.printStackTrace();

} catch (SecurityException e) {

e.printStackTrace();

} catch (IllegalStateException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

mp.start();

}

}

4.在manifest文件中注册广播

以上代码就是实现Android闹钟的全部代码了,希望大家能够喜欢。相关阅读:

linux配置java环境变量详细过程

总结C#网络编程中对于Cookie的设定要点

C++封装远程注入类CreateRemoteThreadEx实例

解析Mysql多表查询的实现

Win7系统exFAT格式无法写入文件怎么办?解决方法

ThinkPHP中处理表单中的注意事项

AJAX应用中必须要掌握的重点知识(分享)

php以post形式发送xml的方法

JavaScript中获取HTML元素值的三种方法

Mac 安装和卸载 Mysql5.7.11 的方法

如何解决win10系统开始菜单和通知中心无法打开

深入理解JavaScript函数参数(推荐)

JS给超链接加确认对话框的方法

phpphp图片采集后按原路径保存图片示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值