使用uri的方式打开应用、为什么要设置Action
来源:互联网 发布:网络项目平台 编辑:程序博客网 时间:2024/06/03 20:08
看之前我们学到的代码
Intent intent = new Intent();intent.setAction(intent.ACTION_VIEW);intent.setData(Uri.parse("http://www.baidu.com"));startActivity(intent);
uri:用于标识某一互联网资源名称的字符串
简单理解格式如下:
[scheme:][//host][path][?query][#fragment]
前面我们学习过了activity之间的跳转方法:
http://blog.csdn.net/github_26672553/article/details/60329123
我们现在学习:怎么通过uri的方式,来实现(从ManActivity跳转到IndexActivity)
1、在AndroidManifest.xml 配置文件里:
<activity android:name=".IndexActivity"> <intent-filter> <action android:name="abc" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="diy" android:host="diy.com"/> </intent-filter></activity>
2、MainActivity.java里点击跳转代码:
Intent intent = new Intent(); intent.setData(Uri.parse("diy://diy.com")); startActivity(intent);
3、为了使得程序不报错,我们需要修改以前IndexActivity.java的代码:
public class IndexActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.index); //获取 Intent intent = getIntent(); //String name = intent.getExtras().get("name").toString(); String name = "首页"; //显示到控件上 ((TextView)findViewById(R.id.text1)).setText(name); }}
为是要设置Action
如果我们还有一个activity,它们是scheme都是同样的。类似如下:
<activity android:name=".IndexActivity"> <intent-filter> <action android:name="abc" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="diy" android:host="diy.com"/> </intent-filter> </activity> <activity android:name=".NewsList"> <intent-filter> <action android:name="newslist" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="diy" android:host="diy.com"/> </intent-filter> </activity>
那么在需要跳转的时候,就可以通过action名称来区分了。
Intent intent = new Intent(); intent.setAction("newslist"); intent.setData(Uri.parse("diy://diy.com")); startActivity(intent);
0 0
- 使用uri的方式打开应用、为什么要设置Action
- Intent常用Uri,打开相应的应用
- Android使用Uri打开浏览器的方法
- 为什么struts2的action要设置成“prototype”
- mac 设置打开方式, 图标右键显示简介,可以选择打开使用的方式
- Android通过URL/URI来打开我们的应用
- Android使用URI启动应用的学习
- tomcat 设置uri编码方式
- 打开应用的系统设置
- struts2设置Action的数据方式
- Android “设置”应用的各项如何用代码调用的方式打开
- JQuery datatables插件 使用ajax将struts2的action对象传递给datatables设置数据源方式
- NFC打开指定应用 URI实现
- 如何设置IE7的打开方式
- MyEclipse 设置JSP的默认打开方式
- MyEclipse 设置JSP的默认打开方式
- MyEclipse 设置JSP的默认打开方式
- Eclipse 设置文件的默认打开方式
- 代码单元与代码点
- AndroidStudio_华为手机无法输出日志信息
- 16槽的PCI Express®2.0扩展坞 EB16
- 一个Demo学会用Android兼容包新控件
- GYM 101102 L.Starry Night(贪心+dfs)
- 使用uri的方式打开应用、为什么要设置Action
- 数据的逻辑结构和数据的存储结构
- React Native 的 Navigator 组件使用方式
- 对序列化和反序列化的理解
- mysql系统学习
- pragma restrict_references
- iOS Apple Pay支付
- Android开发优化之——使用软引用和弱引用
- React问题集