短信可以直接在第三方应用程序(android)上打开吗?
当一条短信以表单形式发送时,比如说一个应用程序“myApp”,它将在接收方的默认短信应用程序中打开。但我想控制它对接收器的外观(比如改变颜色)。在本机应用程序“myApp”中是否有发送文本和读取文本的方法?或者识别它是从“myApp”发送的,并将消息导入“myApp”。确保您可以接收消息,使广播接收器在每次消息到达时接收消息,启动显示消息的活动短信可以直接在第三方应用程序(android)上打开吗?,android,text,messages,Android,Text,Messages,当一条短信以表单形式发送时,比如说一个应用程序“myApp”,它将在接收方的默认短信应用程序中打开。但我想控制它对接收器的外观(比如改变颜色)。在本机应用程序“myApp”中是否有发送文本和读取文本的方法?或者识别它是从“myApp”发送的,并将消息导入“myApp”。确保您可以接收消息,使广播接收器在每次消息到达时接收消息,启动显示消息的活动 public class SMSApp extends IntentReceiver { private static final String
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);
}