您的位置:首页 > 移动开发 > Android开发

android_activity隐式意图跳转到浏览器和短信的界面

2016-03-07 23:56 603 查看

浏览器

界面

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="欲知更多详情,请访问:" />
<TextView
android:id="@+id/tv"
<!--TextView本身是没有点击事件的,所以要添加android:clickable="true"-->
android:clickable="true"
android:onClick="click"
android:textColor="#0000ff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="http://www.nihao.com" />

</LinearLayout>


MainActivity

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

findViewById(R.id.tv).setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

/*
//这段代码是来自系统上成源代码的。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="about" />
<data android:scheme="javascript" />
</intent-filter>*/

Intent intent = new Intent();

intent.setAction("android.intent.action.VIEW");

intent.addCategory("android.intent.category.DEFAULT");

intent.setData(Uri.parse("http://www.nihao.com"));

startActivity(intent);
}
});
}
}


短信

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

/*
//这段代码来自系统上成源代码
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
*/

public void share(View v){

for (int i = 0; i < 100; i++) {

Intent intent = new Intent();

intent.setAction("android.intent.action.SENDTO");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("sms:"));

//这里的key,不能乱写,只有去起看一看源码中是怎么接收的,再逆推回来即可
intent.putExtra("sms_body", "推荐您使用一款软件,我最近都在使用它,挺不错的");

startActivity(intent);
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 浏览器 短信