简体   繁体   English

将数据从Acttivity传递到SmsManager

[英]Pass data from Acttivity to SmsManager

I'm trying to modify the Android source in the following way: When the user sends an SMS, a popup window (in the form of a new activity) is displayed from within SmSManager class asking if the user is sure that he wants to send the SMS. 我正在尝试通过以下方式修改Android源:当用户发送SMS时,从SmSManager类中显示一个弹出窗口(以新活动的形式),询问用户是否确定要发送短信。 If he clicks OK the message is sent. 如果他单击“确定”,则发送消息。 Otherwise it's not. 否则不是。 I have successfully displayed the popup window but now I'm stuck on the onClick event. 我已经成功显示了弹出窗口,但是现在我陷入了onClick事件。 How can I pass data from the activity to the SmSManager class? 如何将数据从活动传递到SmSManager类?

Edit: Code as requested 编辑:根据要求编写代码

In SmsManager.sendTextMessage() : SmsManager.sendTextMessage()

Intent smsIntent = new Intent(Intent.ACTION_MAIN, null);
smsIntent.setComponent(new ComponentName("com.package", "com.package.MyActivity"));
smsIntent.addCategory(Intent.CATEGORY_LAUNCHER);
smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ActivityThread.currentApplication().getApplicationContext().startActivity(smsIntent);

In MyActivity 在MyActivity中

    final Button btn_ok = (Button) findViewById(R.id.btn_ok);
    btn_ok.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // What do I need to write here?
            finish();
        }
    });

You should startActivity for result: 您应该使用startActivity获得结果:

Here are result codes for SmsManager: http://developer.android.com/reference/android/telephony/SmsManager.html 这是SmsManager的结果代码: http : //developer.android.com/reference/android/telephony/SmsManager.html

and here you will find some theory about it: How to manage `startActivityForResult` on Android? 在这里,您会发现一些有关它的理论: 如何在Android上管理`startActivityForResult`?

I found a workaround myself. 我自己找到了解决方法。 I'm storing a value in SharedPreferences in my activity and I retrieve it in the SmsManager class. 我在活动中的SharedPreferences中存储一个值,并在SmsManager类中检索它。 It works for me, but I don't know if it's acceptable from a security point of view 它对我有用,但我不知道从安全角度来看是否可以接受

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM