通知上的回调PendingIntent(callback PendingIntent on a notification)
我有一个应用程序正在接收GCM通知并链接到此通知的pendingIntent以打开URL:
private void sendNotification(String message) { PendingIntent pendingIntent; Intent intent; NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (url != null) { intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(url)); pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(pendingIntent);
它工作正常,但我希望在打开此意图时得到通知(最终用户点击通知打开URL)。
我尝试使用OnFinished回调,但这样做:
PendingIntent.OnFinished finish = new PendingIntent.OnFinished() { public void onSendFinished(PendingIntent pi, Intent intent, int resultCode, String resultData, Bundle resultExtras) { //sending information to Ordolink server as user opened the URL ...do my stuff.... } }; try { pendingIntent.send(Activity.RESULT_OK, finish, null); } catch (CanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); }
一旦收到通知,就会打开pendingIntent
我试过像这样使用BroadcastReceiver:
我的活动:
Intent intent_broadcast = new Intent(this, MyBroadcastReceiver.class); intent_broadcast.putExtra("url", url); pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent_broadcast, PendingIntent.FLAG_ONE_SHOT); pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent_broadcast, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(pendingIntent);
BroadcastReceiver:
public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d("JRE", "Callback onReceive Intent open URL"); Intent myIntent = new Intent(Intent.ACTION_VIEW); myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); myIntent.setData(Uri.parse(intent.getStringExtra("url"))); context.startActivity(myIntent); }
}
我还在Manifest中声明了BroadcastReceiver:
<receiver android:name="MyBroadcastReceiver" > </receiver>
但永远不会调用MyBroadcastReceiver。 任何想法 ?
I have an app who is receiving a GCM notification and link to this notification a pendingIntent to open an URL:
private void sendNotification(String message) { PendingIntent pendingIntent; Intent intent; NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (url != null) { intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(url)); pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(pendingIntent);
it works fine but I would like to be informed when this intent is opened (end user click on the notification to open the URL).
I tried to use the OnFinished callback but by doing this:
PendingIntent.OnFinished finish = new PendingIntent.OnFinished() { public void onSendFinished(PendingIntent pi, Intent intent, int resultCode, String resultData, Bundle resultExtras) { //sending information to Ordolink server as user opened the URL ...do my stuff.... } }; try { pendingIntent.send(Activity.RESULT_OK, finish, null); } catch (CanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); }
pendingIntent is opened as soon as the notification is received
I tried by using BroadcastReceiver like this:
my activity:
Intent intent_broadcast = new Intent(this, MyBroadcastReceiver.class); intent_broadcast.putExtra("url", url); pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent_broadcast, PendingIntent.FLAG_ONE_SHOT); pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent_broadcast, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(pendingIntent);
the BroadcastReceiver :
public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d("JRE", "Callback onReceive Intent open URL"); Intent myIntent = new Intent(Intent.ACTION_VIEW); myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); myIntent.setData(Uri.parse(intent.getStringExtra("url"))); context.startActivity(myIntent); }
}
and I also declared the BroadcastReceiver in the Manifest:
<receiver android:name="MyBroadcastReceiver" > </receiver>
but the MyBroadcastReceiver is never called. any idea ?
原文:https://stackoverflow.com/questions/37436084
最满意答案
您可以使用
preg_match()
完成此操作:$whois = shell_exec('whois -h riswhois.ripe.net ' . $ip); $result = preg_match('/^descr:\s*(.+)$/m', $matches); $descr = $matches[1];
注意mutliline(
m
)修饰符的使用。You can accomplish this using
preg_match()
:$whois = shell_exec('whois -h riswhois.ripe.net ' . $ip); $result = preg_match('/^descr:\s*(.+)$/m', $matches); $descr = $matches[1];
Note the use of the mutliline (
m
) modifier.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
如果您的sed允许通过-i参数进行编辑: sed -e 's/$/string after each line/' -i filename 如果没有,你必须创建一个临时文件: typeset TMP_FILE=$( mktemp ) touch "${TMP_FILE}" cp -p filename "${TMP_FILE}" sed -e 's/$/string after each line/' "${TMP_FILE}" > filename If your sed allows in pla ...
-
preg_split包含文本的变量,并遍历返回的数组: foreach(preg_split("/((\r?\n)|(\r\n?))/", $subject) as $line){ // do stuff with $line } preg_split the variable containing the text, and iterate over the returned array: foreach(preg_split("/((\r?\n)|(\r\n?))/", $subject) ...
-
您可以为此操作创建一个简单的正则表达式,您可以查看下面的代码;
用PHP解析一个字符串(Parse a string with PHP)[2021-12-18]
为什么不使用serialize()和unserialize() ? http://php.net/manual/en/function.serialize.php Why not use serialize() and unserialize()? http://php.net/manual/en/function.serialize.php如何用PHP包含某个字符串的文件解析一行?(How to parse a line out of a file that contains a certain string with PHP?)[2023-09-14]
您可以使用preg_match()完成此操作: $whois = shell_exec('whois -h riswhois.ripe.net ' . $ip); $result = preg_match('/^descr:\s*(.+)$/m', $matches); $descr = $matches[1]; 注意mutliline( m )修饰符的使用。 You can accomplish this using preg_match(): $whois = shell_exec('whois -h ...尝试一下: sed -n ':a; //,/<\/event>/ N; / /,/<\/event>/!b; /<\/event>/ {/uniqueId="1279939300.862594_PFM_1_1912320699"\|uniqueId="1281686522.353435_PFM_1_988171542"/p;d}; ba' Give this a try: sed -n ':a; / /,/<\/event>/ N; / /,/<\/eve ... PHP - 如何检查一行中字符串的前4个值是否为数字(PHP - How to check if the first 4 values of a string on a line are numerical)[2023-08-09]
我相信你的意思是4个第一个字符是数字。 您可能想要使用正则表达式: if (preg_match('/^\d{4}.*/', $yourSingleLineString)) { //it is starting by 4 digits so do what you need to } preg_match检查你的字符串是否与给定的模式匹配。 该模式实际上说:从行的开头(^)开始,数字(\ d)重复4次({4}),然后有任何字符(。)零次或多次(*)。 I believe you mean 4 fi ...对于您的情况,使用: $string="date: march 27, 2017"; 或$string="start: 12:30pm"; 您可以选择以下任何一种技术: *注意:如果担心针头存在( 冒号或冒号空间 ),那么你应该使用其中一种防伪选项,否则需要额外的考虑来捕捉没有针头的字符串。 使用strpos()和substr() * false-proof: $string=($pos=strpos($string,": "))?substr($string,$pos+2):$string; 使用str ...相关文章
更多- nslocal notification
- HTML5 Notification 桌面提醒功能 API
- Becoming a data scientist
- Android 微信的回调跨进程间的调用 (分享)
- 怎样理解java中的回调函数
- [转]So You Want To Be A Producer
- trouble is a friend
- Fading Like a Flower - Roxette
- 按钮样式
- She’s Not Carrying A Handbag
最新问答
更多- 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
- 如何打破按钮上的生命周期循环(How to break do-while loop on button)
- C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
- 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
- 如何并排放置两个元件?(How to position two elements side by side?)
- 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
- 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
- Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
- 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
- 电脑高中毕业学习去哪里培训
- 电脑系统专业就业状况如何啊?
- IEnumerable
linq表达式(IEnumerable linq expressions) - 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
- Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
- 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
- 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
- 的?(The ? marks in emacs/haskell and ghc mode)
- 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
- 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
- 悬停时的图像转换(Image transition on hover)
- IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
- 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
- java分布式框架有哪些
- Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
- PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
- 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
- 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
- typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
- 武陟会计培训类的学校哪个好点?
- 从链接中删除文本修饰(Remove text decoration from links)