屏蔽状态栏通知,以及控制手机有打过电话,同时控制某些应用一天只能弹出一次状态栏通知
屏蔽状态栏通知,以及控制手机有拨打电话记录,同时控制某些应用一天只能弹出一次状态栏通知。看了下记录这是2013,2014年做的一个功能,应该是4.4的版本,在此记录一下吧,主要是控制一些内置的一些应用在消费者手里之前不要弹通知出来,同时后续一天只能弹一条通知。后面的版本如果修改应该也差不多,看了下这些文件也都有,不过现在看来,还是有些地方可以改进的,就此记录一下,不去改了
修改文件
frameworks/base/services/java/com/android/server/NotificationManagerService.java
frameworks/base/core/java/android/app/NotificationManager.java
frameworks/base/core/java/android/app/INotificationManager.aidl
packages/apps/Phone/src/com/android/phone/PhoneGlobals.java
INotificationManager.aidl文件添加如下,用于获取播出电话的时间
long getCallOutingTime();
PhoneGlobals.java修改
import android.database.Cursor;
onCreate()中添加,用于NotificationManager中获取获取打电话时间
intentFilter.addAction("android.intent.action.notificaiton.send.getcalloutingtime");
添加函数getOutCallTime,用于获取播出电话的时间
private long getOutCallTime(Context context)
{
long incoming = 0L;
long outgoing = 0L;
Cursor cursor = context.getContentResolver().query(Calls.CONTENT_URI,
new String[] { Calls.DURATION, Calls.TYPE, Calls.DATE },
null,null,Calls.DEFAULT_SORT_ORDER);
//((Activity) context).startManagingCursor(cursor);
if(cursor == null)
return 0;
boolean hasRecord = cursor.moveToFirst();
int count = 0;
while (hasRecord) {
int type = cursor.getInt(cursor.getColumnIndex(Calls.TYPE));
long duration = cursor.getLong(cursor.getColumnIndex(Calls.DURATION));
switch (type) {
case Calls.INCOMING_TYPE:
incoming += duration;
break;
case Calls.OUTGOING_TYPE:
outgoing += duration;
default:
break;
}
count++;
hasRecord = cursor.moveToNext();
}
cursor.close();
Log.v(LOG_TAG, "getCallTime outgoing=" + outgoing + ", " + "incoming" + incoming);
return outgoing;
}
广播接收处理,接收到广播后,发出统计到的时间,
private class PhoneGlobalsBroadcastReceiver extends BroadcastReceiver中
if(intent.getAction().equals("android.intent.action.notificaiton.send.getcalloutingtime"))
{
long time = getOutCallTime(context);
if(time > 65535)
time=time/1800+10;
else
time=time/1800;
int ttime = (int)time;
Intent intentTime = new Intent("android.intent.action.notificaiton.receive.getcalloutingtime");
intentTime.putExtra("notification.receive.calloutingtime", ttime);
context.sendBroadcast(intentTime);
Log.d(LOG_TAG, "PhoneGlobalsBroadcastReceiver ssjj getOutCallTime"+getOutCallTime(context) + " ttime="+ttime);
return;
}
NotificationManager.java处理,主要的功能逻辑实现是在这个文件了.前几天还在这个文件里屏蔽一些应用的通知,智能设备里可能用的挺多,内置了一些应用又不想让他弹通知,没事弹个通知挺讨厌. 挺好用
import android.database.Cursor;
import android.provider.CallLog.Calls;
import android.provider.CallLog;
import android.content.Intent;
import android.content.IntentFilter;
import android.app.PendingIntent;
import java.util.Calendar;
import android.content.SharedPreferences;
public void notify(String tag, int id, Notification notification)中添加, 看到个时间戳 ,20113年的,哈哈,名字我就删了哈,不暴露了
需要注意IsDeleteNotify函数中if( pkg.equals("com.fengyou.ldqp")||pkg.equals("com.tencent.mobileqq") ) 这里添加需要屏蔽的apk
// add 20131227
if(IsDeleteNotify(pkg))
return;
//end
添加函数
//add 20131228
private void updateCallTime()
{
Log.w("TAG", "send android.intent.action.notificaiton.send.getcalloutingtime");
Intent intent = new Intent("android.intent.action.notificaiton.send.getcalloutingtime");
mContext.sendBroadcast(intent);
}
private long getOutCallTime()
{
long time = 0;
if (sService == null)
getService();
try {
time = sService.getCallOutingTime();
} catch (RemoteException e) {
Log.e(TAG, "getOutCallTime error="+e);
}
return time;
}
private static int mDay = -1;
private void saveDay(int saveDay)
{
SharedPreferences sp = mContext.getSharedPreferences("notificationSaveDayFile", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putInt("NOTIFICATION_SAVE_DAY", saveDay);
editor.commit();
}
private int readDay()
{
SharedPreferences sp = mContext.getSharedPreferences("notificationSaveDayFile", Context.MODE_PRIVATE);
int saveDay = sp.getInt("NOTIFICATION_SAVE_DAY", -1);
return saveDay;
}
private boolean isSameDay()
{
Calendar mCalendar = Calendar.getInstance();
int oldDate = readDay();//mDay;
mDay = mCalendar.get(Calendar.DAY_OF_MONTH);
saveDay(mDay);
if (localLOGV) Log.v(TAG, "isSameDay mDay=" + mDay + " oldDate="+oldDate );
if(oldDate == mDay)
{
return true;
}
else
{
return false;
}
}
private boolean IsDeleteNotify(String pkg)
{
long outCallTime = getOutCallTime();
if(outCallTime <= 0) //read after ,don't read
updateCallTime();
if (localLOGV) Log.v(TAG, "IsDeleteNotify outCallTime=" + outCallTime + " pkg="+pkg );
if( pkg.equals("com.fengyou.ldqp")||pkg.equals("com.tencent.mobileqq") ) // 1 is half hour, 2 is one hour //com.android.systemui com.mediatek.mtklogger com.yunos.alicontacts com.fengyou.ldqp
{
if(outCallTime > 0 && isSameDay()==false)
return false;
else
return true;
}
else
return false;
}
public void notifyAsUser(String tag, int id, Notification notification, UserHandle user)中也添加
//add 20131227
if(IsDeleteNotify(pkg))
return;
//end
NotificationManagerService.java修改,主要是用来获取拨打电话的时间
private long mOutingTime = 0;
public long getCallOutingTime()
{
return mOutingTime;
}
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver()中添加
if (action.equals("android.intent.action.notificaiton.receive.getcalloutingtime"))
{
mOutingTime = intent.getIntExtra("notification.receive.calloutingtime", 0);
Log.i(TAG, "songjian receive mOutingTime = " + mOutingTime);
return;
}
NotificationManagerService(Context context, StatusBarManagerService statusBar,
LightsService lights)中添加
filter.addAction("android.intent.action.notificaiton.receive.getcalloutingtime");
到此修改完了
屏蔽状态栏通知,以及控制手机有打过电话,同时控制某些应用一天只能弹出一次状态栏通知相关推荐
- windows7的用户账户控制每次重启计算机时都会被关闭,win7系统更改设置总是弹出用户账户控制的解决方法...
很多小伙伴都遇到过win7系统更改设置总是弹出用户账户控制的困惑吧,一些朋友看过网上零散的win7系统更改设置总是弹出用户账户控制的处理方法,并没有完完全全明白win7系统更改设置总是弹出用户账户控制 ...
- python控制手机自动刷新闻_python +adb控制手机自动化签到
#coding=utf8 importos,re,time,loggingimportpyautoguifrom apscheduler.schedulers.background import Ba ...
- ubuntu下安卓刷机教程和scrcpy无线控制手机
由于手头有个闲置的安卓手机,平时一般固定在手机支架上(如下图),当做时钟.闹钟还有树莓派远程桌面,偶尔也拿来看看视频,但是每次拿上拿下太麻烦了.突然想到能不能用电脑来控制手机,这样就方便的多了.所以心 ...
- 华为手机连接电脑用什么软件_CCW分享:用电脑控制手机!非华为荣耀手机用户请看这里!...
继华为/荣耀推出Huawei Share和Magic-link一碰传功能后,多屏协同就成为了很多PC和手机厂商彰显"软实力"的战场,联想.华硕和戴尔等电脑品牌也纷纷推出了类似的多屏 ...
- showdialog wpf 如何关闭_WPF用ShowDialog()弹出窗体时控制该窗体的显示位置,并传值回父窗体...
原文:http://blog.csdn.net/kiss0622/article/details/5852153 方法一: 1.父窗口代码 Window1.xaml.cs private void B ...
- 组策略 计算机 用户账户控制,Win10系统总是弹出用户账户控制提示是否允许程序修改计算机的解决方法...
Win10系统总是弹出用户账户控制提示"是否允许程序修改计算机"的解决方法 不少使用Win10系统的用户都会遇到这样一个问题:当我们打开程序时,系统总会弹出"你要允许以下 ...
- 桌面消息提醒_对win7的支持已近尾声,如何关闭不断弹出的提醒通知
微软已经正式宣布,到2020年1月14日,对Windows 7的支持将终止,为了确保每个人都知道截止日期,从2019年10月15日开始,运行旧操作系统的电脑将再次在桌面上弹出一个提醒通知. 该通知提醒 ...
- iOS键盘弹出通知后加入动画
首先我们要注册键盘弹出和弹入的通知 [[NSNotificationCenter defaultCenter] addObserver:self ...
- 用Java弹出创建新的消息通知
首先创建JFrame作为弹出窗口. 在其中添加一些JLabel以包含信息,并在适当的位置分配它们,使其看起来像一条通知消息. 下面给出了示例代码: String message = 'You got ...
最新文章
- java opengl es_Java-Android-使用openGL ES绘制3D然后绘制2D
- 学完python基础开始学爬虫_零基础入门Python爬虫不知道怎么学?这是入门的完整教程...
- Mysql无法添加环境变量解决办法
- 为什么mysql与eclipse_为什么这个SQL在MySQL中而不是通过Eclipse执行?
- Unity—AssetBundle的打包及四种加载资源方式
- 四川大学计算机网络_四川大学20考研情况
- Android Studio生成aar包的方法以及解压aar包的方法
- 三点估算pmp_我本人是做项目经理的,我把考PMP也当成一个项目来规划
- android开发适配深色模式,手机不支持深色模式,如何用软件解决深色模式的问题?(附有系统全局深色模式实现方法...
- 阅文集团副总裁傅徐军:最佳技术架构选型方法论
- 你需要知道的基础算法知识——STL和基础数据结构(五)
- Google Chrome 独立安装下载
- 主编编辑器出现未经授权图片不可引用怎么办?
- 用七牛生成音乐外链方法
- 可能是最高颜值的三方网易云音乐播放器 (全平台支持)
- 【Java】抽象类和接口的区别
- The Little Schemer 中文版
- PHP之ctype扩展
- 本地ASP.NET开发页面使用AzureAD(AAD)验证登录
- 2022漂亮有质感的SummerAdmin后台模板+Layui内核