3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SDK30以降で"com.android.camera.action.CROP"のintentが機能しない

Last updated at Posted at 2022-11-02

はじめに

  • SDK30以降デフォルトで入っているギャラリーアプリ以外で画像のクロップができなくなった

元のコード

ImageEditActivity.java
    Intent intent = new Intent("com.android.camera.action.CROP");
    //intentに対して色々
    grantPermissions();
    startActivityForResult(intent, requestCode);
PermissionsManager.kt
fun grantPermissions(){
    context.packageManager.queryIntentActivities(
        intent,
        PackageManager.MATCH_DEFAULT_ONLY
    ).forEach { resolveInfo ->
        //権限の付与
    }
}

ちなみにstartActivityForResultはactivityの1.2.0-alpha04からdeprecatedなのでregisterForActivityResult
flagsがint値のqueryIntentActivitiesは、APIレベル33からResolveInfoFlagsを使用したqueryIntentActivitiesを使ってねとなっています。。

解決

api29までは使用できていることから、30でのPackagevisibilityの変更に関係していそうと踏み、

For other scenarios, like opening a specific third party application directly from your UI, developers will have to explicitly list the application package names or intent filter signatures like this:

以下のようにAndroidManifest.xmlにIntentFilterを追加することで解決

AndroidManifest.xml
    <queries>
        <intent>
            <action android:name="com.android.camera.action.CROP" />
            <data android:mimeType="image/*" />
        </intent>
    </queries>
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?