为什么我们在使用Intent时在sms Manager中使用应用程序上下文。在sms manager中扮演应用程序上下文的角色是什么。请告诉我... String no = mobileno.getText()。toString();
字符串msg = message.getText()。toString();
//Getting intent and PendingIntent instance
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);
//Get the SmsManager instance and call the sendTextMessage method to send message
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, pi,null);
Toast.makeText(getApplicationContext(), "Message Sent successfully!",
Toast.LENGTH_LONG).show();
为什么我们在使用Intent时在sms Manager中使用应用程序上下文
你不必。在这种情况下,this
应该适合您所使用的地方getApplicationContext()
。
戴夫·史密斯(Dave Smith)的这篇博客文章解释了不同上下文的作用。
在短信管理器中扮演应用程序上下文的角色是什么。
与Application
Context
无关SmsManager
,或与此无关Toast
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句