gpt4 book ai didi

Java 如何通过打开图像来启动 myapp?

转载 作者:行者123 更新时间:2023-12-05 00:17:49 26 4
gpt4 key购买 nike

我正在开发一个图像编辑器应用程序,当用户从文件管理器中单击图像或...时,我希望我的应用程序位于“打开方式...”列表中(就像“照片编辑器”应用程序所做的那样) ) :
Click to see the example (Edited)
问题是我不知道该怎么做。
我在 youtube 上进行了研究,发现是关于 intent filterManifest.xml文件。
我已经尝试添加一些 <action/>随机到我的 Intent 过滤器,但它没有用。

最佳答案

转至Manifest文件并搜索您的 LAUNCHER Activity ,例如 SplashActivity像这样

  <activity
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
//this below code help you to get image from other apps if shared
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*" />
</intent-filter>

</activity>
并在您的 中获取该数据飞溅 Activity 做这个 :
 Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
//this will check that you are getting only image type not text
boolean isImage = Intent.ACTION_SEND.equals(action) && "image/*".equals(type);

if(getIntent().getData() != null && isImage){
// here you got the data and you can send this data or uri
// to your image editor activity
Uri imageUri = intent.getData();
}
您可以通过执行此操作将该图像发送到下一个 Activity
您可以将 URI 存储为字符串
intent.putExtra("imageUri", imageUri.toString());
然后只需将字符串转换回您的( EditorActivity )中的 URI
Uri myUri = Uri.parse(getIntent().getStringExtra("imageUri"));

关于Java 如何通过打开图像来启动 myapp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71317353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com