【问题标题】:Android SMS Broadcast Receiver checking message formatAndroid SMS Broadcast Receiver 检查消息格式
【发布时间】:2014-05-10 13:59:47
【问题描述】:

我正在构建检查接收消息格式的 Android 应用程序 如果它以 $A 开头,则启动 Activity A 并将消息内容发送到 Activity A 如果它以 $B 开头,它将启动 Activity B 并将消息的内容发送到 Activity B 请任何帮助

【问题讨论】:

    标签: android sms broadcastreceiver broadcast


    【解决方案1】:

    你可以这样做

    if(messages.getMessageBody().contains("$A")) {
    
         //Write your code here
    
    }
    else if(messages.getMessageBody().contains("$B")) {
    
         //Write your code here
    
    }
    

    要将数据传递给下一个活动,请这样做,

    Intent i = new Intent(FirstScreen.this, SecondScreen.class);   
    i.putExtra("STRING_I_NEED", strName);
    

    然后,要检索该值,请尝试以下操作:

    String newString;
    if (savedInstanceState == null) {
        extras = getIntent().getExtras();
        if(extras == null) {
            newString= null;
        } else {
            newString= extras.getString("STRING_I_NEED");
        }
    } else {
        newString= (String) savedInstanceState.getSerializable("STRING_I_NEED");
    }
    

    【讨论】:

    • 但是 smsreciever 是一个没有屏幕的类,它是一个隐藏的活动
    • intent i = new Intent (first screen.this, SecondScreen.class) 不起作用
    • 看到这个link和这个link也是为了那个..只需调用startActivity()
    猜你喜欢
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2013-11-07
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多