`
meohao
  • 浏览: 96278 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

写在20110903:ACTION_GET_CONTENT

 
阅读更多
如彩信、Email、Gmail、网站等添加附件,如果应用本身没有做文件浏览选择的功能,此时应用可以通过发送ACTION_GET_CONTENT的系统接口来获取其他具备浏览选择文件功能的应用来支持该功能,比如此时添加附件会弹出一个选择框,有图库、音乐播放器等,现在如果想让FM也支持,在AndroidMenifest.xml中添加如下配置:
<intent-filter>
  <action andriod:name="android.intent.action.GET_CONTENT"/>
  <category android:name="android.intent.category.OPENABLE"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:mimetype="*/*"/>
</intent-filter>

在点击Item打开File的时候添加如下代码:
String action=mContext.getIntent().getAction();
if(!TextUtils.isEmpty(action)&&action.equals(Intent.ACTION_GET_CONTENT)){
   Uri uri=getDbUriFromFilepath(mContext,filepath);     
   //从数据库中查询该物理路径对应的Uri
   if(uri!=null){
      intent.setDataAndType(uri,type);
   }else{
      intent.setDataAndType(Uri.fromFile(new File(filepath)),type);
   }
   mContext.setResult(Activity.RESULT_OK,intent);
   mContext.finish();
   return;
}
分享到:
评论

相关推荐

    Android中获取系统图片示例

    在这段代码中,我们创建了一个Intent,指定了ACTION_GET_CONTENT,并设置了类型为"image/*",表示我们希望选择的是任何类型的图片。然后通过startActivityForResult启动,REQUEST_IMAGE_PICK是请求码,用于在...

    viewpager相关

    this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } activity_main: &lt;LinearLayout xmlns:android=...

    在不使用Devise的情况下在RubyonRails中实现API密钥.zip

    在Ruby on Rails框架中,开发API时通常会使用如Devise这样的身份验证库来处理用户认证。然而,有时我们可能需要自己实现API密钥的管理,以满足特定的需求或者避免引入额外的依赖。本教程将深入讲解如何在不使用...

    SwipeListViewTest项目

    &lt;TextView android:id="@+id/example_row_tv_title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="18sp" /&gt; 这个布局...

    Android开发技巧总汇(5)

    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) { Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); for (int i = 0; i ; i++) { ...

    photo.rar

    在Android应用开发中,调用系统相机是一项常见的功能,它允许用户通过应用程序拍摄照片或选择已有的图片。在实现这个功能时,我们通常会遇到如何弹出底部提示框来增强用户体验的问题。"photo.rar"文件可能包含了一个...

    Android自定义控件下拉刷新实例代码

    switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mLastMotionY = event.getY(); mIsBeingDragged = false; break; case MotionEvent.ACTION_MOVE: if (!mIsBeingDragged && Math.abs(event.getY...

    Android实现图片自动轮换

    从手机相册中选择一幅图片并显示在屏幕上 */ public class MainActivity extends AppCompatActivity { private Button btn_choose; private ImageView img_show; private final int REQUEST_PICTURE_CHOOSE = 1...

    android涂鸦板

    switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // 处理按下事件 break; case MotionEvent.ACTION_MOVE: // 绘制线条 Canvas canvas = mSurfaceHolder.lockCanvas(); if (canvas != null) { ...

    自定义侧滑删除菜单

    switch (event.getAction()) { case MotionEvent.ACTION_DOWN: initialX = event.getX(); break; case MotionEvent.ACTION_MOVE: float currentX = event.getX(); float deltaX = currentX - initialX; if ...

    android 自定义软键盘

    if (event.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); // 获取被点击的按键 View view = findViewById((int) getTag(y, x)); if (view instanceof...

    android实现随手指拖动滑屏

    switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // 手指按下时记录初始坐标 downX = event.getX(); break; case MotionEvent.ACTION_MOVE: // 手指移动时获取当前坐标 float moveX = event....

    android 自定义滑动按钮

    switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_UP: // 判断滑动方向 if (x - slideImage.getLeft() &gt; slideImage.getWidth() / 2) { setChecked(true); } ...

    file_get_contents&#40;php://input, r&#41;实例介绍

    在 `action.php` 中,我们使用 `file_get_contents('php://input', 'r')` 来获取 POST 数据的原始内容。`'r'` 参数表示以只读模式打开输入流。 `$_POST` 超全局数组通常用于存储通过 POST 方法提交的表单数据,它是...

    popupwindow调用相机相册

    在Android应用开发中,PopupWindow是一个非常实用的组件,它可以在屏幕上的任意位置显示一个浮动窗口,用于提供快捷操作或菜单选项。在这个项目中,"popupwindow调用相机相册"是一个实现用户通过PopupWindow来选择...

    android简单组合控件使用

    String action = intent.getAction(); if (action.equals("your_action")) { // 处理相关事件 } } } ``` 2. 在AndroidManifest.xml中静态注册: ```xml &lt;receiver android:name=".MyBroadcastReceiver"&gt; ...

    Android之来电弹屏实例代码,带关闭按钮_视图效果实现.zip

    if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); if (state.equals(TelephonyManager.EXTRA_STATE_...

    android 实现左滑删除最简单的方式

    switch (event.getAction()) { case MotionEvent.ACTION_DOWN: downX = event.getX(); isDragging = false; break; case MotionEvent.ACTION_MOVE: if (!isDragging && Math.abs(event.getX() - downX) &gt; ...

    Android实现ListView的Item滑动删除

    switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // 记录按下时的位置 mDownX = event.getX(); break; case MotionEvent.ACTION_MOVE: float moveX = event.getX(); float deltaX = moveX - ...

Global site tag (gtag.js) - Google Analytics