android 程序中可以通过设置scheme,实现在其他程序(eg. browser中点击此scheme的link)来直接打开程序, 或直接打开程序的某个activity。介绍如下:

1. 在androidmanifest中想要启动的activity标签下加入:

<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="myscheme" />
</intent-filter>


这样在browser中点击link (http://myscheme)时就可以打开程序。


twitter中实例:

<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="twitter" android:host="user" />
</intent-filter>

data的完整格式:

<data android:scheme="****" android:host="*****" android:path="****" />


2. 如果打开程序并做一些特殊化处理, 可以在该activity的oncreate中截取intent:

// get intent open by scheme
if (getIntent() != null && getIntent().getData() != null
&& !AppUtils.isEmpty(getIntent().getData().getScheme())) {
mData = getIntent().getData();
openByScheme = true;
}



更多相关文章

  1. Android(安卓)访问权限清单
  2. Android(安卓)killall 命令
  3. Android退出程序问题综述
  4. 程序设置横屏后,锁屏时会被销毁一遍,解锁时又重新加载onCreat的问
  5. Android(安卓)Activty使用示例【慢慢更新】
  6. receiver定制自动启动一个程序
  7. Android驱动入门-在Android系统上运行JAVA程序
  8. Android(安卓)判断、创建和删除快捷方式
  9. Android存储(二):openFileInput和openFileOutput私有目录下文件

随机推荐

  1. 简单说说android的线程封装
  2. ViewPager使用样例
  3. Android基础知识学习——界面转换
  4. android studio设置自动导入
  5. 【android】Sax解析半个例子 :startElemen
  6. Android IntentService 深入分析
  7. JNI基本数据类型转换
  8. android ScrollView 多张图片之间有空白
  9. Android 获取设备唯一标识
  10. Android 原始下载图片 通过HTTp