Android 从BroadcastReceiver类启动意图
我的应用程序接收短信并更改活动,以在我的应用程序中显示警报对话框Android 从BroadcastReceiver类启动意图,android,Android,我的应用程序接收短信并更改活动,以在我的应用程序中显示警报对话框Toast运行良好,但不会改变活动onReceive()接收包含电子邮件的短信,根据该电子邮件id,我的应用程序搜索相关的联系人号码并在回复消息中发回 public void onReceive( Context context, Intent intent ) { // Get SMS map from Intent Bundle extras = intent.getExtras(); String
Toast
运行良好,但不会改变活动onReceive()
接收包含电子邮件的短信,根据该电子邮件id,我的应用程序搜索相关的联系人号码并在回复消息中发回
public void onReceive( Context context, Intent intent )
{
// Get SMS map from Intent
Bundle extras = intent.getExtras();
String messages = "";
if ( extras != null )
{
// Get received SMS array
Object[] smsExtra = (Object[]) extras.get( "pdus" );
// Get ContentResolver object for pushing encrypted SMS to incoming folder
//ContentResolver contentResolver = context.getContentResolver();
for ( int i = 0; i < smsExtra.length; ++i )
{
SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
String body = sms.getMessageBody().toString();
String address = sms.getOriginatingAddress();
messages += "SMS from " + address + " :\n";
messages += body + "\n";
// Here you can add any your code to work with incoming SMS
// I added encrypting of all received SMS
}
// Display SMS message
Toast.makeText( context, messages, Toast.LENGTH_SHORT ).show();
Intent i=new Intent(context,AlertActivity.class);
// context.startActivity(i);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
public void onReceive(上下文、意图)
{
//从Intent获取SMS映射
Bundle extras=intent.getExtras();
字符串消息=”;
如果(附加值!=null)
{
//获取接收到的SMS阵列
Object[]smsExtra=(Object[])extras.get(“PDU”);
//获取ContentResolver对象,用于将加密短信推送到传入文件夹
//ContentResolver ContentResolver=context.getContentResolver();
对于(int i=0;i
在启动AlertActivity活动后,您正在添加添加标志(Intent.FLAG\u ACTIVITY\u NEW\u TASK)
。使用以下方法:
Intent i=new Intent(context,AlertActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
为什么要评论这一行?