2013-12-22 53 views
1

我的应用程序是一个简单的图库应用程序,任何用户都可以制作图像并将其保存到SdCard。 我有一个活动,其中用户创建的所有图像都将显示在GridView中。允许其他应用程序从我的应用程序中选择图片,如图库

现在我想要的是我的应用程序显示在图像选择器列表中,其中显示图库和其他应用程序。

我已经实现被显示在列表我的应用程序意图过滤,

但我应该写什么代码,使用户可以从我的 gridview的

挑一个图像... .. enter image description here

<intent-filter> 
      <action android:name="android.intent.action.PICK" /> 

      <category android:name="android.intent.category.DEFAULT" /> 

      <data android:mimeType="image/*" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.intent.action.GET_CONTENT" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.OPENABLE" /> 

      <data android:mimeType="image/*" /> 
     </intent-filter> 

回答

1

但我要写诗什么码e,以便用户可以从我的网格视图中挑选一个图像

您会编写一个Activity,其中包含GridView。当用户做出选择时,您可以拨打电话setResult()提供带有返回值的Uri,其中包含用于触发您的活动的Intent操作记录的信息。然后,您可以拨打finish(),关闭您的活动并将控制权返回给您发起的任何活动。

的文档ACTION_GET_CONTENT具有:

输出:该被选中的项目的URI。这必须是一个content:URI,以便任何接收者都可以访问它。

Uri进去,你传递给setResult()Intent

的文档ACTION_PICK具有:

输出:该被选中的项目的URI。

因此,您可以使用相同的代码用于填充IntentsetResult()两个ACTION_GET_CONTENTACTION_PICK

+0

但是怎么写呢? Intent intent = new Intent(); intent.setResult? 如何? –

+0

@ Dr.aNdRO:'setResult()'是'Activity'上的一个方法。 'finish()'是'Activity'上的一个方法。 http://developer.android.com/reference/android/app/Activity.html和http://developer.android.com/training/basics/intents也介绍了这一点。 – CommonsWare

0

其实我想是这样的:

Intent result = new Intent("com.example.RESULT_ACTION", Uri.parse("content://result_uri"); 
setResult(Activity.RESULT_OK, result); 
finish(); 

通过使用这样的setResult我们可以发送数据。

相关问题