大佬教程收集整理的这篇文章主要介绍了android – 通知动作没有启动新的Activity?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Context context = getBaseContext(); NotificationCompat.builder mBuilder = new NotificationCompat.builder(context) .setsmallIcon(R.mipmap.notificationicon) .setContenttitle(notificationtitlE) .setContentText("Access request for " + appName + " : " + otp) .setDefaults(Notification.DEFAULT_ALL) .setPriority(NotificationCompat.PRIORITY_HIGH) .addAction(R.drawable.ic_tick,"Approve",someApproveIntent? );
这是我的通知构建器,在查看之后,似乎addAction方法正在寻找新的/ pendingIntent,这让我感到困惑,因为我无法在线找到任何Intents不会导致新活动被触发的示例.
我将如何实现一些代码(可能是一种方法),而不是在每个动作上启动一个新的Activity …
谢谢你的帮助
无论您在何处构建通知……
您的通知操作将直接启动服务.
NotificationCompat.builder builder = new NotificationCompat.builder(context)... Intent iAction1 = new Intent(context,Myservice.class); iAction1.setAction(Myservice.ACTION1); PendingIntent piAction1 = PendingIntent.getservice(context,iAction1,PendingIntent.FLAG_updatE_CURRENT); builder.addAction(iconAction1,titleAction1,piAction1); // Similar for action 2.@H_625_4@myservice.java
Intentservices一个接一个地连续运行.他们在工作线程上完成工作.
public class Myservice extends Intentservice { public static final String ACTION1 = "ACTION1"; public static final String ACTION2 = "ACTION2"; @Override public void onHandleIntent(Intent intent) { final String action = intent.getAction(); if (ACTION1.equals(action)) { // do stuff... } else if (ACTION2.equals(action)) { // do some other stuff... } else { throw new IllegalArgumentexception("Unsupported action: " + action); } } }
AndroidManifest.xml中
不要忘记在清单中注册服务.
<manifest> <application> <service android:name="path.to.Myservice" android:exported="false"/> </application> </manifest>
以上是大佬教程为你收集整理的android – 通知动作没有启动新的Activity?全部内容,希望文章能够帮你解决android – 通知动作没有启动新的Activity?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。