【发布时间】:2015-06-20 15:47:38
【问题描述】:
我正在尝试制作一个 android 应用程序,它将向来电发送短信(短信内容将由用户指定)。我正在使用广播接收器,我想在其中使用主要活动中的编辑文本(短信内容)的值(来电到达时)。我尝试了 Intent 但我没有得到解决方案。请帮忙。
主要活动:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et1=(EditText)findViewById(R.id.editText1);
btn=(Button)findViewById(R.id.button1);
}
public void clicksave(View shilpa)
{
s1=et1.getText().toString();
}
广播接收器:
public class MyCallReceiver extends BroadcastReceiver
{
static String incomingNumber="";
Context ct;
public void onReceive(Context context, Intent intent)
{
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING))
{
incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
try
{
SmsManager smsmanager=SmsManager.getDefault();
smsmanager.sendTextMessage(incomingNumber, null,"######",null,null);
Toast.makeText(context, "Message sent succesfully",Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Toast.makeText(context, "SMS failed", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
}
【问题讨论】:
-
您可以发布一些代码以便我们查看您的尝试吗?
-
请发布您的代码
-
清楚你的代码..
-
好吧,当用户接听电话时,您的活动不存在,您将如何处理?将消息保存在首选项中,并在来电时阅读
-
你能发布一下语法吗?
标签: android