简体   繁体   English

如何在单击通知时打开应用程序?

[英]How to open application while clicking notification?

I have implemented media notification and lock screen notification in my music player.我已经在我的音乐播放器中实现了媒体通知和锁屏通知。 While clicking lock screen notification, how to ask the password to the user and how to open the application.单击锁屏通知时,如何向用户询问密码以及如何打开应用程序。

As well as for media notification while clicking I have opened the application.以及点击时的媒体通知我已经打开了应用程序。 But how to close the notification bar or how to hide the whole notification bar但是如何关闭通知栏或如何隐藏整个通知栏媒体通知图片

and how to show the suggestion of my application in "open with " while clicking the music file in any file directory.以及如何在单击任何文件目录中的音乐文件时在“打开方式”中显示我的应用程序的建议。

What do you mean by ask for password?询问密码是什么意思? just open an activity that asks for password.只需打开一个要求输入密码的活动。

As for open an activity use Nirali solution in: Open application after clicking on Notification至于打开一个活动使用 Nirali 解决方案: 点击通知后打开应用程序

 NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);

Intent notificationIntent = new Intent(context, HomeActivity.class);

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
        | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent intent = PendingIntent.getActivity(context, 0,
        notificationIntent, 0);

notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);

For "open with" you should define intent-filter in your manifest.对于“打开方式”,您应该在清单中定义意图过滤器。 Look at this register as music player and https://developer.android.com/guide/components/intents-filters.html将此寄存器视为音乐播放器https://developer.android.com/guide/components/intents-filters.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM