浏览器
界面
<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);
}
}
}