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

发布于 2025-01-10 21:25:19 字数 365 浏览 0 评论 0原文

我正在开发一个图像编辑器应用程序,当用户单击文件管理器中的图像或...时,我希望我的应用程序位于“打开方式...”列表中(就像“照片编辑器”应用程序所做的那样) ) :

点击查看示例(已编辑)

问题是我不知道怎么做这样的事。

我在 youtube 上进行了研究,发现它与 Manifest.xml 文件中的 intent filter 有关。

我已经尝试随机添加一些 到我的意图过滤器中,但没有成功。

I'm working on an image editor app and I want to have my app being in the 'Open With ...' list when the user clicks on an image from file manager or ... (Like how 'Photo Editor' app did) :

Click to see the example (Edited)

And the problem is that I don't know how to do such a thing.

I have researched in youtube and I found that it's about the intent filter in the Manifest.xml file.

I already tried adding some <action/> to my intent filter by random but it didn't worked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷爱 2025-01-17 21:25:19

转到 Manifest 文件并搜索您的 LAUNCHER 活动,例如

像这样的

  <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>

SplashActivity并在您的 SplashActivity 中获取该数据执行此操作:

 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();
}

您可以将该图像发送到下一个活动,通过执行此操作,

您可以将 URI 存储为字符串

Intent nextIntent = new Intent(this, EditorActivity.java);
nextIntent.putExtra("imageUri", imageUri.toString());
startActivity(nextIntent)

,然后将字符串转换回 URI,如下所示(EditorActivity

Uri myUri = Uri.parse(getIntent().getStringExtra("imageUri"));

Go to the Manifest file and search for your LAUNCHER activity for example SplashActivity

like this

  <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>

And To get that data in your SplashActivity do this :

 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();
}

And you can send that image to the next activity by doing this

you can store the URI as a string

Intent nextIntent = new Intent(this, EditorActivity.java);
nextIntent.putExtra("imageUri", imageUri.toString());
startActivity(nextIntent)

and then just convert the string back to URI like this in your (EditorActivity)

Uri myUri = Uri.parse(getIntent().getStringExtra("imageUri"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文