android:scheme 常用类型,Intent里跳页的模式中scheme 模式的简单使用

Intent里跳页的模式中scheme 模式的简单使用

//在一个android工程 里有2个 java文件 MainActivity 和OtherActivity

//res/layout里 有2个 界面布局

1、在AndroidManifest.xml清单配置 要跳转的页面

2、设置要执行动作的名字 -- name="aaaaaaa"

3、设置intent -- 类型 -- 这里设置默认

4、设置数据的类型 这里是 scheme 类型

注意:name 和 scheme 的内容随便取

代码

//

--------------------------------

MainActivity 类

代码

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

//schema

public void schema(View view){

Intent intent = new Intent();

//这里获取的动作 就是 配置 清单里面 设置的 动作

intent.setAction("aaaaaaa");

//这里Uri.parse里面的内容 -- 配置清单 配好的 内容

//后面要加 : 这是一种格式 : 后面 是要设置的内容

//Uri.parse 一般格式 -- xxx:/xxx/xxx

intent.setData(Uri.parse("kkkkkkkkkkk:"));

startActivity(intent);

}

}

--------------------

//跳到这个 类

OtherActivity 类

代码

public class OtherActivity extends Activity {

private TextView text;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.other_activity);

text = (TextView) this.findViewById(R.id.text);

Intent intent = getIntent();

//获取 数据

Uri uri = intent.getData();

//获取scheme -- 也就是配置清单里 设置的 内容

String scheme = uri.getScheme();

//获取MainActivity 类Uri.parser -- 设置内容 kkkkkkkkkkk:后面的内容

String authority = uri.getAuthority();

//获取MainActivity 类Uri.parser -- 设置内容 kkkkkkkkkkk:后面的内容/后面的内容

String path = uri.getPath();

text.setText(scheme + ":" + authority + "::" + path);

}

}

结果:   kkkkkkkkkkk:null::null

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android开发android:scheme 是一个很重要的属性,用于指定一个应用程序的URI scheme。URI(Uniform Resource Identifier)是用于标识和定位资源的字符串,通常用于网络资源的访问。 通过在AndroidManifest.xml文件使用 android:scheme 属性,可以告诉Android系统该应用程序支持通过特定的URI scheme来进行跳转。例如,可以指定一个自定义的URI scheme,比如"myapp",然后在其他应用程序使用这个自定义URI来启动该应用程序。 具体步骤如下: 1. 在 AndroidManifest.xml 文件的<application>标签内部添加以下代码: ```xml <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="myapp" /> </intent-filter> ``` 这样就指定了该应用程序支持通过"myapp" scheme进行跳转。 2. 然后在其他应用程序,可以通过以下代码来启动该应用程序: ```java String uriString = "myapp://example"; Uri uri = Uri.parse(uriString); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); ``` 在上述代码使用 Uri.parse() 方法将字符串转换为Uri对象,然后使用 Intent.ACTION_VIEW 和指定的Uri对象创建一个Intent对象,最后通过 startActivity() 方法启动该Intent。 通过以上步骤,就可以在其他应用程序使用指定的URI scheme跳转到该应用程序。 需要注意的是,为了确保跳转成功,需要确保该应用程序已经安装在设备上,并且支持该指定的URI scheme
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值