0
當發送短信時,讓我們說一個應用程序'myApp'它會在接收器的默認文本消息應用程序中打開。但我想控制接收器的外觀(如改變顏色)。無論如何發送文本並在原生應用程序「myApp」中讀取文本?或者確定它是從'myApp'發送的,並將消息導入'myApp'。可以直接在第三方應用程序(android)上打開短信?
當發送短信時,讓我們說一個應用程序'myApp'它會在接收器的默認文本消息應用程序中打開。但我想控制接收器的外觀(如改變顏色)。無論如何發送文本並在原生應用程序「myApp」中讀取文本?或者確定它是從'myApp'發送的,並將消息導入'myApp'。可以直接在第三方應用程序(android)上打開短信?
相信你能收到的消息進行廣播接收器進入的消息的每一次消息到達啓動的活動,顯示消息...
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);
}
謝謝你,這就是我一直在尋找 – 2012-01-11 21:01:59