android 去掉通知栏

推荐方法:在自定义的styles中设置隐藏状态栏和标题栏的theme,并在AndroidManifest.xml文件中的application或某个activity中设置。

styles文件如下

[html]  view plain  copy
  1. <resources>  
  2.   
  3.     <!-- Base application theme. -->  
  4.     <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">  
  5.         <!-- Customize your theme here. -->  
  6.         <item name="colorPrimary">@color/colorPrimary</item>  
  7.         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>  
  8.         <item name="colorAccent">@color/colorAccent</item>  
  9.     </style>  
  10.   
  11.     <style name="AppTheme.NoBar">  
  12.         <item name="windowNoTitle">true</item>  
  13.         <item name="android:windowFullscreen">true</item>  
  14.     </style>  
  15.   
  16. </resources>  
AndroidManifest.xml文件如下:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.jianchi.fsp.myapplication">  
  4.   
  5.     <application  
  6.         android:allowBackup="true"  
  7.         android:icon="@mipmap/ic_launcher"  
  8.         android:label="@string/app_name"  
  9.         android:supportsRtl="true"  
  10.         android:theme="@style/AppTheme">  
  11.         <activity android:name=".MainActivity" android:theme="@style/AppTheme.NoBar">  
  12.             <intent-filter>  
  13.                 <action android:name="android.intent.action.MAIN" />  
  14.                 <category android:name="android.intent.category.LAUNCHER" />  
  15.             </intent-filter>  
  16.         </activity>  
  17.     </application>  
  18.   
  19. </manifest>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android提供了NotificationListenerService类,可以用于读取通知中的通知。 首先,在AndroidManifest.xml文件中注册NotificationListenerService: ``` <service android:name=".MyNotificationListenerService" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> <intent-filter> <action android:name="android.service.notification.NotificationListenerService" /> </intent-filter> </service> ``` 然后创建一个继承自NotificationListenerService的类MyNotificationListenerService: ``` public class MyNotificationListenerService extends NotificationListenerService { @Override public void onNotificationPosted(StatusBarNotification sbn) { super.onNotificationPosted(sbn); // 获取通知所属应用的包名 String packageName = sbn.getPackageName(); // 获取通知的内容 Notification notification = sbn.getNotification(); if (notification != null && notification.extras != null) { String title = notification.extras.getString(Notification.EXTRA_TITLE); String text = notification.extras.getString(Notification.EXTRA_TEXT); // 对通知内容进行处理 // ... } } @Override public void onNotificationRemoved(StatusBarNotification sbn) { super.onNotificationRemoved(sbn); // 通知被移除时的处理逻辑 } } ``` 在MyNotificationListenerService类中的onNotificationPosted()方法可以获取到每个收到的通知,其中StatusBarNotification对象中包含了通知的相关信息,例如通知所属应用的包名、通知的标题和内容等。你可以根据自己的需求对通知进行处理。 请注意,使用NotificationListenerService需要添加BIND_NOTIFICATION_LISTENER_SERVICE权限,因此在注册服务时需要在AndroidManifest.xml中添加权限声明。另外,用户需要在系统设置中手动授权才能让应用读取通知,可以通过以下代码跳转到设置页面: ``` Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); startActivity(intent); ``` 以上是使用NotificationListenerService读取通知通知的基本步骤,你可以根据自己的需求进一步处理通知内容或者监控通知的移除等操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值