android学习(十) 从其他应用接收简单数据
2017-04-09 10:52
537 查看
更新你的Manifest
<activity android:name=".MainActivity" > <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEND_MULTIPLE" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> </activity>
关于此的相关内容android学习(七) 允许其他应用启动您的Activity
当另一个应用通过startActivity()构造一个Intent试图分享这些时,你的申请将被作为一个选择。如果用户选择了你的一样,相应的活动将在MainActivity开始。然后在你的代码和UI里适当处理内容。
处理传入的内容
调用getIntent()得到Intent,一旦你有了这个对象,你可以检查内容来决定下一步该怎么做。private void handleIntent(){ Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if(Intent.ACTION_SEND.equals(action)&&type!=null){ if("text/plain".equals(type)){ handleSendText(intent); } else if(type.startsWith("image/*")){ handleSendImage(intent); } } else if(Intent.ACTION_SEND_MULTIPLE.equals(action)&&type!=null){ if (type.startsWith("image/")) { handleSendMultipleImages(intent); // Handle multiple images being sent } } else { //处理其他的Intent } } //处理图片时尽量在单线程中 private void handleSendMultipleImages(Intent intent) { ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (imageUris != null) { } } private void handleSendImage(Intent intent) { Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); if (imageUri != null) { } } private void handleSendText(Intent intent) { String shareText = intent.getStringExtra(Intent.EXTRA_TEXT); if(shareText!=null){ } }
摘自android developer
相关文章推荐
- 【Android Developers Training】 33. 接收来自其它应用的简单数据
- Google Android开发者文档系列-创建有内容分享特性的应用之接收其它应用程序发送的简单数据
- android学习(九) 发送简单数据到其他应用程序
- Android简单数据存储类SharedPreferences详解及实例(通过“记住密码”功能学习SharedPreferences)
- Android简单数据存储类SharedPreferences详解及实例(通过“记住密码”功能学习SharedPreferences)
- Android客户端与数据库交互数据的简单学习
- android基础学习之wifi的简单应用
- android 清除data/data/ 下其他应用的数据
- 数据结构与算法学习笔记——堆栈及其应用(10以内简单四则计算器)
- Android应用学习(一)实现activity自动跳转和简单的登录
- 【Android Developers Training】 32. 向其它应用发送简单数据
- 和其他App分享简单的数据(2)从其他App中接收简单的数据
- TinyOS学习笔记8-简单发送接收数据
- Android学习之简单的数据存储
- TinyOS学习笔记8-简单发送接收数据
- Android简单数据存储类SharedPreferences详解及实例(通过“记住密码”功能学习SharedPreferences) .
- 【Android开发学习07】存储简单数据的利器--Preferences
- android 读写其他应用SharedPreferences存储的数据
- 【C#学习】聊天机器人,网络数据的简单应用