本文介绍了如何在Intent中将PendingIntent发送到我的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想告诉我的服务完成一项操作后该怎么做.因此,我想向该服务发送 PendingIntent
,以便它可以启动它(通过使用 PendingIntent.send()
)
I want to tell my service what to do when it finish to perform an action.So I want to send the service a PendingIntent
, so it can start it (by using PendingIntent.send()
)
PendingIntent pendingIntent;
Intent newInt;
newInt = new Intent(Intent.ACTION_SENDTO);
newInt.setData( Uri.parse( "sms:052373"));
newInt.putExtra("sms_body", "The SMS text");
pendingIntent = PendingIntent.getActivity(this, 0, newInt, 0);
现在的问题是如何开始将 pendingIntent
附加到 pendingIntent
?
Now the question how to start to attach the pendingIntent
to the pendingIntent
?
我尝试了例如:
NewIntent.putExtra("pendingIntent",pendingIntent);
startService(NewIntent);
但这是行不通的.
在服务中:
PendingIntent pendingIntent = (PendingIntent) intent.getParcelableExtra("pendingIntent");
pendingIntent.send();
推荐答案
我成功了!
查看此内容:
PendingIntent pendingIntent;
Intent ownIntent;
ownIntent = new Intent(Intent.ACTION_SENDTO);
ownIntent.setData(Uri.parse("sms:0523737233"));
ownIntent.putExtra("sms_body", "The SMS text");
Log.e("abc", "7");
pendingIntent = PendingIntent.getActivity(this, 0, ownIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
Log.e("abc", "9");
ownIntent.putExtra("pendingIntent", pendingIntent);
ownIntent.putExtra("uriIntent", ownIntent.toUri(0));
startService(ownIntent);
并在服务中:
PendingIntent pendingIntent = (PendingIntent) intent.getParcelableExtra("pendingIntent");
pendingIntent.send();
这篇关于如何在Intent中将PendingIntent发送到我的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!