簡體   English   中英

短信可以直接在第三方應用(android)上打開嗎?

[英]can text messages be opened directly on third party app (android)?

當發送短信時,假設有一個應用程序“ myApp”,它將在接收方的默認短信應用程序中打開。 但我想控制它對接收器的外觀(如改變顏色)。 無論如何,是否可以在本地應用程序“ myApp”中發送文本並閱讀該文本? 或者確定它是從“ myApp”發送的,並將消息導入到“ myApp”。

確保您可以接收消息,並在每次到達消息時使接收消息成為廣播接收器,以啟動顯示消息的活動...

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);        
    }    

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM