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); } } }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析