从appWidget开启系统自带AlarmClock
2012-12-06 19:44
330 查看
Since: API Level 9 有了统一的方法:
此时注意添加权限:com.android.alarm.permission.SET_ALARM
之前的就比较混乱:
完整函数:
if(Build.VERSION.SDK_INT >=9){ Intent intentClock= new Intent(); intentClock.setAction(AlarmClock.ACTION_SET_ALARM); return PendingIntent.getActivity(context, 0, intentClock, 0); }
此时注意添加权限:com.android.alarm.permission.SET_ALARM
之前的就比较混乱:
PackageManager packageManager = context.getPackageManager(); Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER); // Verify clock implementation String clockImpls[][] = { {"HTC Alarm Clock", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" }, {"Standar Alarm Clock", "com.android.deskclock", "com.android.deskclock.AlarmClock"}, {"Froyo Nexus Alarm Clock", "com.google.android.deskclock", "com.android.deskclock.DeskClock"}, {"Moto Blur Alarm Clock", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock"}, {"Samsung Galaxy Clock", "com.sec.android.app.clockpackage","com.sec.android.app.clockpackage.ClockPackage"}, {"google 2.1 Clock", "com.android.deskclock","com.android.deskclock.DeskClock"}, {"emulator 2.1 Clock", "com.android.alarmclock","com.android.alarmclock.AlarmClock"} }; boolean foundClockImpl = false; for(int i=0; i<clockImpls.length; i++) { String vendor = clockImpls[i][0]; String packageName = clockImpls[i][1]; String className = clockImpls[i][2]; try { ComponentName cn = new ComponentName(packageName, className); ActivityInfo aInfo = packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA); alarmClockIntent.setComponent(cn); Log.v(TAG,"Found " + vendor + " --> " + packageName + "/" + className); foundClockImpl = true; } catch (NameNotFoundException e) { Log.v(TAG,vendor + " does not exists"); } } if (foundClockImpl) { PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, alarmClockIntent, 0); return pendingIntent; }else{ return null; }部分来自网络,没有一一验证。
完整函数:
// 获取闹钟的PendingIntent private PendingIntent getClockPendingIntent() { if(Build.VERSION.SDK_INT >=9){ Intent intentClock= new Intent(); intentClock.setAction(AlarmClock.ACTION_SET_ALARM); return PendingIntent.getActivity(context, 0, intentClock, 0); } Log.v(TAG,"SDK_INT:" + Build.VERSION.SDK_INT); PackageManager packageManager = context.getPackageManager(); Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER); // Verify clock implementation String clockImpls[][] = { {"HTC Alarm Clock", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" }, {"Standar Alarm Clock", "com.android.deskclock", "com.android.deskclock.AlarmClock"}, {"Froyo Nexus Alarm Clock", "com.google.android.deskclock", "com.android.deskclock.DeskClock"}, {"Moto Blur Alarm Clock", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock"}, {"Samsung Galaxy Clock", "com.sec.android.app.clockpackage","com.sec.android.app.clockpackage.ClockPackage"}, {"google 2.1 Clock", "com.android.deskclock","com.android.deskclock.DeskClock"}, {"emulator 2.1 Clock", "com.android.alarmclock","com.android.alarmclock.AlarmClock"} }; boolean foundClockImpl = false; for(int i=0; i<clockImpls.length; i++) { String vendor = clockImpls[i][0]; String packageName = clockImpls[i][1]; String className = clockImpls[i][2]; try { ComponentName cn = new ComponentName(packageName, className); ActivityInfo aInfo = packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA); alarmClockIntent.setComponent(cn); Log.v(TAG,"Found " + vendor + " --> " + packageName + "/" + className); foundClockImpl = true; } catch (NameNotFoundException e) { Log.v(TAG,vendor + " does not exists"); } } if (foundClockImpl) { PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, alarmClockIntent, 0); return pendingIntent; }else{ return null; } }
相关文章推荐
- Android如何调试更新系统自带的app
- android:检查系统是否开启消息通知权限,app应用点击开启通知时跳转到app详情页面开启权限
- 主界面获取第三方app,或获取系统自带app ,以及过滤某app 和大家一起分享下,(*^__^*) 嘻嘻……
- 在app未开启时,实现对用户进行通知提醒功能总结(添加事件到手机系统日历并设置闹钟提醒)
- 笔记本Win10系统自带蓝牙默认为开启如何关闭
- Error: [Errno 10013](win10系统下python2.7自带CGIHTTPServer服务开启问题)
- (八十一)利用系统自带App来实现导航
- Mac os x 系统开启自带php环境
- iOS APP利用系统自带库监听网络状态
- Android自用-----系统自带app与用户app
- android技巧:把自己的app变成手机系统自带的app[/system/app]
- android系统添加内置APP(自带.so)
- (八十一)利用系统自带App来实现导航
- 开启使用系统自带的侧滑返回
- loadrunner的 web server 服务器可以正常开启,但是就是打不开loadrunner 自带的航班系统的网站
- 录制QTP自带的flight系统时一直弹出一个对话框,提示Access toD:\QTPWorking\amples\light\app was denied.的错误
- android技巧:把自己的app变成手机系统自带的app[/system/app]
- Android AppWidget系统框架
- iOS 调起地图App进行导航(百度,高德,系统自带高德)URL API方式
- win10 系统开启自带虚拟机的方法