gpt4 book ai didi

android - 如何让 getCropAndSetWallpaperIntent(Uri imageUri) 工作?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:13:44 33 4
gpt4 key购买 nike

因此,有两个问题与此相同( How to use getCropAndSetWallpaperIntent method in WallpaperManager?How to use getCropAndSetWallpaperIntent?), 但对他们两个都没有答案。希望得到答案,我问这个 - 如何让这个方法起作用。

http://developer.android.com/reference/android/app/WallpaperManager.html#getCropAndSetWallpaperIntent(android.net.Uri)这对我的大脑没有帮助。

这行不通

WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this);
Uri uri = Uri.parse("android.resource://lv.revo.inspicfootballhd/drawable/v1");
Intent intent = new Intent(wallpaperManager.getCropAndSetWallpaperIntent(uri));
startActivity(intent);

logcat 显示这个

5891-5891/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: lv.revo.inspicfootballhd, PID: 5891
java.lang.IllegalArgumentException: Image URI must be of the content scheme type
at android.app.WallpaperManager.getCropAndSetWallpaperIntent(WallpaperManager.java:760)
at lv.revo.inspicfootballhd.MainActivity.onTouch(MainActivity.java:236)
at android.view.View.dispatchTouchEvent(View.java:7701)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2338)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1568)
at android.app.Activity.dispatchTouchEvent(Activity.java:2465)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2285)
at android.view.View.dispatchPointerEvent(View.java:7886)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5532)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5512)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5483)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5612)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:5144)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)

因此,根据文档“将在 Intent 中设置的图像 URI。必须是内容 URI,其提供者必须将其类型解析为“image/*””

图像为.jpg 格式。明天我将继续寻找解决方案。我只是希望有更聪明的人知道我的问题的答案。

编辑/更新 1:所以我设法将uri更改为Content Uri,我相信是这样。是不是用这个 - https://stackoverflow.com/a/23223556/2727408

现在显示这个

java.lang.IllegalArgumentException: Cannot use passed URI to set wallpaper; check that the type returned by ContentProvider matches image/*
at android.app.WallpaperManager.getCropAndSetWallpaperIntent(WallpaperManager.java:792)
at lv.revo.inspicfootballhd.MainActivity.onTouch(MainActivity.java:244)

我尝试使用 ContentResolver getType(contentURI) 检查类型,它返回 null。现在我将尝试找到如何将其更改为 image/*

目前的代码是这样的

Uri uri = ResourceToUri(getApplicationContext(), imageArray[j]);
File wallpaper_file = new File(uri.getPath());
Uri contentURI = getImageContentUri(getApplicationContext(), wallpaper_file.getAbsolutePath());

ContentResolver cr = this.getContentResolver();
Log.d("CONTENT TYPE: ", "IS: " + cr.getType(contentURI));

Intent intent = new Intent(wallpaperManager.getCropAndSetWallpaperIntent(contentURI));
startActivity(intent);

到目前为止谢谢。

编辑/更新 2:在这里创建了关于我的新问题的新问题: How to change type to image/*

最佳答案

如错误所述,您需要一个内容 URI。内容 URI 允许您共享具有临时读写权限的文件。

checkout :Get a Content URI from a File URI?

关于android - 如何让 getCropAndSetWallpaperIntent(Uri imageUri) 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30746196/

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