在当前短信内容的activity中写  

         Bundle bun = new Bundle();


        bun.putString("message", "短信内容");


        Intent in = new Intent(第二个Activity.this, 第一个Activity.class);


        in.putExtras(bun);

在要传内容的activity中写:


           Bundle bu = this.getIntent().getExtras();

String message = bu.getString("message");//获取短信内容

public class SMSReceiver extends BroadcastReceiver
{
    /*当收到短信时,就会触发此方法*/
    public void onReceive(Context context, Intent intent)
    {
        Bundle bundle = intent.getExtras();
        Object messages[] = (Object[]) bundle.get("pdus");
        SmsMessage smsMessage[] = new SmsMessage[messages.length];
        for (int n = 0; n < messages.length; n++)
        {
            smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
        }
        //调用显示短信内容的Activity
        Intent intent = new Intent();
        intent.setClass(this, MyView.class);
        intent.putExtra("sms_body", smsMessage[0].getMessageBody());
        startActivity(intent);
    }
}

回复三楼,按您所说的改了,
//调用显示短信内容的Activity
Intent intent2 = new Intent();
intent2.setClass(this, Activity01.class);
                   //setClass出错:The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (SMSReceiver, Class<Activity01>)

intent2.putExtra("sms_body", smsMessage[0].getMessageBody());
startActivity(intent2);
                //startActivity出错:The method startActivity(Intent) is undefined for the type SMSReceiver

回复二楼: 二楼思路明确;
回复楼主: 有没有注意到二楼跟三楼的代码区别——intent.setClass(第二个Activity.this, 第一个Activity.class)和intent.setClass(this, 第一个Activity.class),当在方法中调用setClass()这个方法的时候,是可以用this的。挡在内部类中(比如事件监听类OnClickListener)调用这个方法的时候要变为Activity.class。希望能够帮助楼主。

The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (GameV的更多相关文章

  1. 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)

    Fragment newfragment =new MyFragment();fragmentTransaction.replace(R.layout.activity_main,newfragmen ...

  2. The method load(Class, Serializable) in the type HibernateTemplate is not applicable for the arguments (Class, int)

    引入别人的项目发现利用HibernateTemplate的load的方法报错了.错误提示为: The method load(Class, Serializable) in the type Hibe ...

  3. The method format(String, Object[]) in the type String is not applicable for the arguments

    今天,我弟遇到一个有意思的错误~ 程序: package com.mq.ceshi1; public class StringFormat { public static void main(Stri ...

  4. The method setOnClickListener(View.OnClickListener) in the type View is not applicable

    开始学习 android 了,学习的是高明鑫老师的android视频教程(android视频教学). 学到第八讲时, 在写动态设置时报错: The method setOnClickListener( ...

  5. The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){}, String, int)

    package comxunfang.button; import android.support.v7.app.ActionBarActivity; import android.os.Bundle ...

  6. The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)

    The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the ...

  7. The method setItems(String) in the type ForTokensTag is not applicable for the arguments (Object)

    1. 问题 看到这个错误以为是貌似jsp页面有误,c:forTokens标签用错了?? An error occurred at line: in the jsp file: /WEB-INF/pag ...

  8. [log4j]Error:The method getLogger(String) in the type Logger is not applicable for the arguments

    原因:本该导入import org.apache.log4j.Logger; 结果成了import java.util.logging.Logger; 如果硬把private static Logge ...

  9. .replace(R.id.container, new User()).commit();/The method replace(int, Fragment) in the type FragmentTransaction is not app

    提示错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arg ...

随机推荐

  1. 64_s3

    sugar-toolkit-gtk3-devel-0.110.0-2.fc26.i686.rpm 13-Feb-2017 10:56 22626 sugar-toolkit-gtk3-devel-0. ...

  2. URAL题解三

    URAL题解三 URAL 1045 题目描述:有\(n\)个机场,\(n-1\)条航线,任意两个机场有且只有一种方案联通.现有两个恐怖分子从\(m\)号机场出发,第一个人在机场安装炸弹,乘坐飞机,引爆 ...

  3. HDU 4614 Vases and Flowers(线段树+记录区间始末点或乱搞)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 题目大意:有n个空花瓶,有两种操作: 操作①:给出两个数字A,B,表示从第A个花瓶开始插花,插B ...

  4. 对于JAVA多线程卖票小程序的理解

    昨天把多线程重新看了一遍,发现自己还是有许多需要理解的地方,现在写一篇总结. 一:利用继承Thread类会出现的问题: public class SellTicketsThread extends T ...

  5. 微信小程序-textarea中的文本读取以及换行问题

    今天客户那边要求textarea中输入的问题可以按回车键换行,而我使用的是bindinput获取值,但是呢bindinput 处理函数的返回值并不会反映到 textarea 上,按回车键导致点击换行符 ...

  6. base64的作用

    本函数将字符串以 MIME BASE64 编码.此编码方式可以让中文字或者图片也能在网络上顺利传输.在 BASE64 编码后的字符串只包含英文字母大小写.阿拉伯数字.加号与反斜线,共 64 个基本字符 ...

  7. 应用nslookup命令查看A记录、MX记录、CNAME记录和NS记录

    https://blog.csdn.net/qq_38058202/article/details/80468688

  8. 作死自救日记——不小心修改linux下/etc/sudoers权限的解决办法

    作死自救日记,献给跟我一样不小心作了死的人 ================================================ 今天不小心作死修改了/etc/sudoers的权限,作死命 ...

  9. 【51nod】1244 莫比乌斯函数之和

    题解 求积性函数的前缀和?杜教筛! 这不给一发杜教筛入门必备之博客= = https://blog.csdn.net/skywalkert/article/details/50500009 好了,然后 ...

  10. cordova 使用WKWebView 适配iphoneX及解决不能拨打电话问题

    先安装插件 cordova-plugin-wkwebview-engine 然后修改插件中CDVWKWebViewEngine.m文件,下面是全部代码,修改部分已经进行注释     /* Licens ...