短信可以直接在第三方应用程序(android)上打开吗?

发布于 2024-12-26 10:15:52 字数 135 浏览 1 评论 0原文

当发送短信时,假设有一个应用程序“myApp”,它将在接收者的默认短信应用程序中打开。但我想控制它对接收者的外观(例如改变颜色)。是否有办法发送文本并在本机应用程序“myApp”中读取该文本?或者确定它是从“myApp”发送的并将消息导入到“myApp”。

when a text message is sent form, lets say an application 'myApp' it'll open in default text message app of the receiver. but i want to control how it looks to receiver(like changing colour). Is there anyway to send text and read that text in native app, 'myApp'? Or identify it was sent from 'myApp' and import message to 'myApp'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ可否回来 2025-01-02 10:15:52

确保您可以接收消息 为传入消息创建广播接收器,每次消息到达时启动显示消息的活动...

public class SMSApp extends IntentReceiver {
    private static final String LOG_TAG = "SMSApp";

    /* package */ static final String ACTION =
            "android.provider.Telephony.SMS_RECEIVED";

    public void onReceiveIntent(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION)) {
            StringBuilder buf = new StringBuilder();
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                SmsMessage[] messages = Telephony.Sms.Intents.getMessagesFromIntent(intent);
                for (int i = 0; i < messages.length; i++) {
                    SmsMessage message = messages[i];
                    buf.append("Received SMS from  ");
                    buf.append(message.getDisplayOriginatingAddress());
                    buf.append(" - ");
                    buf.append(message.getDisplayMessageBody());
                }
            }
           //start you messages activity 

        Intent i = new Intent();
        i.setClassName("com.test", "com.test.myMessagesAcivity");
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        //prepare message text to be sent to the activity via bundle 
        Bundle bundle = new Bundle();
        bundle.putString("message", but.toString());
        i.putExtras(bundle);
        context.startActivity(i);


        }
    }


}

并在清单文件中添加这些权限

<uses-permission android:id="android.permission.RECEIVE_SMS" />

<uses-permission android:name="android.permission.SEND_SMS"/>

和此接收器

<receiver class="SMSApp">

            <intent-filter>

                <action android:value="android.provider.Telephony.SMS_RECEIVED" />

            </intent-filter>

        </receiver>

从您的应用程序发送短信

,并使用此方法

public void eb3atSMS(String phoneNumber, String message)
    {        

        PendingIntent pi = PendingIntent.getActivity(this, 0,
            new Intent(this, **DummyClasshere.class**), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    }    

sure you can to receive messages make a broadcast receiver for ingoing messages an each time a message arrive start your activity that displays the message ...

public class SMSApp extends IntentReceiver {
    private static final String LOG_TAG = "SMSApp";

    /* package */ static final String ACTION =
            "android.provider.Telephony.SMS_RECEIVED";

    public void onReceiveIntent(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION)) {
            StringBuilder buf = new StringBuilder();
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                SmsMessage[] messages = Telephony.Sms.Intents.getMessagesFromIntent(intent);
                for (int i = 0; i < messages.length; i++) {
                    SmsMessage message = messages[i];
                    buf.append("Received SMS from  ");
                    buf.append(message.getDisplayOriginatingAddress());
                    buf.append(" - ");
                    buf.append(message.getDisplayMessageBody());
                }
            }
           //start you messages activity 

        Intent i = new Intent();
        i.setClassName("com.test", "com.test.myMessagesAcivity");
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        //prepare message text to be sent to the activity via bundle 
        Bundle bundle = new Bundle();
        bundle.putString("message", but.toString());
        i.putExtras(bundle);
        context.startActivity(i);


        }
    }


}

and in your manifest file add these permissions

<uses-permission android:id="android.permission.RECEIVE_SMS" />

<uses-permission android:name="android.permission.SEND_SMS"/>

and this receiver

<receiver class="SMSApp">

            <intent-filter>

                <action android:value="android.provider.Telephony.SMS_RECEIVED" />

            </intent-filter>

        </receiver>

and to send SMS from your app

use this method

public void eb3atSMS(String phoneNumber, String message)
    {        

        PendingIntent pi = PendingIntent.getActivity(this, 0,
            new Intent(this, **DummyClasshere.class**), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    }    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文