关于状态栏收起的问题。

最近在搞个东西,遇到了一些奇葩的需求。其中一个就是在点击通知之后收起状态栏。

正常情况下还好,如果遇到自定义的RemoteViews就xxx,经过google之后发现一个有效的解决方法就是发送一个系统广播


通知创建部分代码:

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);


builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContent(remoteViews);
builder.setAutoCancel(true);
builder.setDeleteIntent(PendingIntent.getBroadcast(getApplicationContext(), 1, new Intent("delete"), PendingIntent.FLAG_UPDATE_CURRENT));
remoteViews.setOnClickPendingIntent(R.id.notifyMessage, PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent("OnclickReceiver"), PendingIntent.FLAG_UPDATE_CURRENT));


remoteViews.setTextViewText(R.id.notifyMessage, String.format(context.getString(R.string.text_notify_message),networkName));

Notification n = builder.build();

NotificationManager manger = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manger.notify(NOTIFICATIONID, n);



BroadCastReceiver 部分代码:

public class ListenerReceive extends BroadcastReceiver {
final static public  String TAGNAME = "OnclickReceiver";

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equalsIgnoreCase("OnclickReceiver")){


Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
try {
pi.send(context, 0, new Intent());
} catch (CanceledException e) {
e.printStackTrace();
}

NotificationManager manage = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
manage.cancel(NOTIFICATIONID);

//收起状态栏
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

}
}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值