• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

GooglePhoto设置壁纸----壁纸裁剪界面配置

武飞扬头像
纵容_伊人倩影
帮助1

背景描述:

Google photo打开一张图片,点击设为、弹出提示框里选择photo,提示“发生错误,无法加载媒体”。

error,could not load media

问题分析

1、对比机同样操作,可以打开壁纸应用设置壁纸

2、其它对比机,打开Google photo自己的编辑图片界面,点击可以正常设置壁纸。

Log分析

  1.  
    Google相册里点击设为:
  2.  
    START u0 \{act=android.intent.action.CHOOSER flg=0x1 cmp=android/com.android.internal.app.ChooserActivity clip=\{image/jpeg \{...}} (has extras)} from uid 10211
  3.  
     
  4.  
    弹出选择框后点击相册:
  5.  
    START u0 \{act=android.intent.action.ATTACH_DATA dat=content://com.谷歌.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/50/ORIGINAL/JPG/image/jpeg/380847275 typ=image/jpeg flg=0x3000001 cmp=com.谷歌.android.apps.photos/.setwallpaper.SetWallpaperActivity (has extras)} from uid 10211
  6.  
     
  7.  
    START u0 \{act=android.service.wallpaper.CROP_AND_SET_WALLPAPER dat=content://com.谷歌.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/50/ORIGINAL/JPG/image/jpeg/380847275 flg=0x1 pkg=com.谷歌.android.apps.wallpaper cmp=com.谷歌.android.apps.wallpaper/com.android.wallpaper.picker.StandalonePreviewActivity} from uid 10211
  8.  
     
  9.  
    ActivityManager: Start proc 3437:com.谷歌.android.apps.wallpaper/u0a241 for pre-top-activity \{com.谷歌.android.apps.wallpaper/com.android.wallpaper.picker.StandalonePreviewActivity}

        以上为Google pixel机器的log,如log显示,最终打开了com.谷歌.android.apps.wallpaper Google自己的壁纸应用。

1、选择器界面为系统界面:android/com.android.internal.app.ChooserActivity

2、选择相册之后,可以看到一个action,裁剪并且设置壁纸 android.service.wallpaper.CROP_AND_SET_WALLPAPER可以看出是根据action和包类名去启动的界面

3.1、熟悉原生壁纸代码的话,可以很快意识到这个action是用来启动壁纸裁剪界面的

  1.  
    <activity android:name="com.android.wallpaper.picker.StandalonePreviewActivity"
  2.  
    android:resizeableActivity="false"
  3.  
    android:theme="@style/WallpaperTheme.Preview">
  4.  
    <intent-filter>
  5.  
    <action android:name="android.service.wallpaper.CROP_AND_SET_WALLPAPER" />
  6.  
    <category android:name="android.intent.category.DEFAULT" />
  7.  
    <data android:mimeType="image/*" />
  8.  
    </intent-filter>
  9.  
    </activity>

3.2、设置壁纸的action

  1.  
    <activity android:name="com.android.wallpaper.picker.TopLevelPickerActivity"
  2.  
    android:label="@string/app_name"
  3.  
    android:theme="@style/WallpaperTheme.NoBackground"
  4.  
    android:resizeableActivity="false">
  5.  
    <intent-filter>
  6.  
    <action android:name="android.intent.action.SET_WALLPAPER"/>
  7.  
    <category android:name="android.intent.category.DEFAULT"/>
  8.  
    </intent-filter>
  9.  
    </activity>

3.3、附加数据的action

  1.  
    Used to indicate that some piece of data should be attached to some other place. For example, image data could be attached to a contact. It is up to the recipient to decide where the data should be attached; the intent does not specify the ultimate destination.
  2.  
    Input: getData is URI of data to be attached.
  3.  
    Output: nothing
  4.  
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
  5.  
    public static final String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";

4、framework/base下面搜索CROP_AND_SET_WALLPAPER找到相关逻辑代码

frameworks/base/core/java/android/app/WallpaperManager.java

  1.  
    /**
  2.  
    * Gets an Intent that will launch an activity that crops the given
  3.  
    * image and sets the device's wallpaper. If there is a default HOME activity
  4.  
    * that supports cropping wallpapers, it will be preferred as the default.
  5.  
    * Use this method instead of directly creating a {@link #ACTION_CROP_AND_SET_WALLPAPER}
  6.  
    * intent.
  7.  
    *
  8.  
    * @param imageUri The image URI that will be set in the intent. The must be a content
  9.  
    * URI and its provider must resolve its type to "image/*"
  10.  
    *
  11.  
    * @throws IllegalArgumentException if the URI is not a content URI or its MIME type is
  12.  
    * not "image/*"
  13.  
    */
  14.  
    public Intent getCropAndSetWallpaperIntent(Uri imageUri) {
  15.  
    if (imageUri == null) {
  16.  
    throw new IllegalArgumentException("Image URI must not be null");
  17.  
    }
  18.  
     
  19.  
    if (!ContentResolver.SCHEME_CONTENT.equals(imageUri.getScheme())) {
  20.  
    throw new IllegalArgumentException("Image URI must be of the "
  21.  
    ContentResolver.SCHEME_CONTENT " scheme type");
  22.  
    }
  23.  
     
  24.  
    final PackageManager packageManager = mContext.getPackageManager();
  25.  
    Intent cropAndSetWallpaperIntent =
  26.  
    new Intent(ACTION_CROP_AND_SET_WALLPAPER, imageUri);
  27.  
    Log.d(TAG, "imageUri 111 : " imageUri);
  28.  
    cropAndSetWallpaperIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  29.  
     
  30.  
    // Find out if the default HOME activity supports CROP_AND_SET_WALLPAPER
  31.  
    Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);
  32.  
    ResolveInfo resolvedHome = packageManager.resolveActivity(homeIntent,
  33.  
    PackageManager.MATCH_DEFAULT_ONLY);
  34.  
    if (resolvedHome != null) {
  35.  
    cropAndSetWallpaperIntent.setPackage(resolvedHome.activityInfo.packageName);
  36.  
     
  37.  
    List<ResolveInfo> cropAppList = packageManager.queryIntentActivities(
  38.  
    cropAndSetWallpaperIntent, 0);
  39.  
    if (cropAppList.size() > 0) {
  40.  
    Log.w(TAG, "cropAndSetWallpaperIntent 111 : " cropAndSetWallpaperIntent);
  41.  
    return cropAndSetWallpaperIntent;
  42.  
    }
  43.  
    }
  44.  
     
  45.  
    // fallback crop activity
  46.  
    final String cropperPackage = mContext.getString(
  47.  
    com.android.internal.R.string.config_wallpaperCropperPackage);
  48.  
    cropAndSetWallpaperIntent.setPackage(cropperPackage);
  49.  
    List<ResolveInfo> cropAppList = packageManager.queryIntentActivities(
  50.  
    cropAndSetWallpaperIntent, 0);
  51.  
    if (cropAppList.size() > 0) {
  52.  
    Log.w(TAG, "cropAndSetWallpaperIntent 222 : " cropAndSetWallpaperIntent);
  53.  
    return cropAndSetWallpaperIntent;
  54.  
    }
  55.  
    // If the URI is not of the right type, or for some reason the system wallpaper
  56.  
    // cropper doesn't exist, return null
  57.  
    throw new IllegalArgumentException("Cannot use passed URI to set wallpaper; "
  58.  
    "check that the type returned by ContentProvider matches image/*");
  59.  
    }

原生的逻辑还是比较清晰的,

        1、先看看homeIntent能否匹配到这个action(也就是看看launcher是否注册了这个action)

        2、然后判断默认配置config_wallpaperCropperPackage的包名对应的应用是否有注册这个action(我们希望它走这里正常打开我们自己的壁纸界面,配置自己的壁纸应用包名即可)

        3、如果都没有,最后Google photo会打开自己的壁纸编辑界面

5、配置路径和其它壁纸相关的配置

frameworks/base/core/res/res/values/config.xml

  1.  
    <!-- Component name of the built in wallpaper used to display bitmap wallpapers. This must not be null. -->
  2.  
    <string name="image_wallpaper_component" translatable="false">com.android.systemui/com.android.systemui.ImageWallpaper</string>
  3.  
     
  4.  
    <!-- Class name of WallpaperManagerService. -->
  5.  
    <string name="config_wallpaperManagerServiceName" translatable="false">com.android.server.wallpaper.WallpaperManagerService</string>
  6.  
     
  7.  
    <!-- If AOD can show an ambient version of the wallpaper -->
  8.  
    <bool name="config_dozeSupportsAodWallpaper">true</bool>
  9.  
     
  10.  
    <!-- Wallpaper cropper package. Used as the default cropper if the active launcher doesn't
  11.  
    handle wallpaper cropping.
  12.  
    -->
  13.  
    <string name="config_wallpaperCropperPackage" translatable="false">com.android.wallpaperpicker</string>
  14.  
     
  15.  
    <!-- The max scale for the wallpaper when it's zoomed in -->
  16.  
    <item name="config_wallpaperMaxScale" format="float" type="dimen">1.10</item>

6、如果是mtk平台,会有覆盖路径

device/mediatek/common/overlay/wallpaper/frameworks/base/core/res/res/values/config.xml

device/mediatek/system/common/overlay/wallpaper/frameworks/base/core/res/res/values/config.xml

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfiagfa
系列文章
更多 icon
同类精品
更多 icon
继续加载