fix: 修改四指点击为打开系统相册
- 四指点击不再尝试直接设置壁纸 - 改为使用系统相册应用打开固定壁纸 - 用户可以在相册中将图片设置为壁纸 - 打开相册后将 app 状态改为禁用 - 添加 FLAG_ACTIVITY_NEW_TASK 确保正确启动 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
75ecc00c77
commit
1d20e9e745
1 file changed
+11
-57
@@ -1001,75 +1001,29 @@ public class AutoWallpaperService extends WallpaperService {
|
||||
String fixedWallpaperUri = config.getFixedWallpaperUri();
|
||||
|
||||
if (fixedWallpaperUri != null && !fixedWallpaperUri.isEmpty()) {
|
||||
// 有固定壁纸,调用系统壁纸设置
|
||||
fileLogger.log(TAG, "Launching system wallpaper picker with fixed wallpaper: " + fixedWallpaperUri);
|
||||
// 有固定壁纸,使用系统相册打开
|
||||
fileLogger.log(TAG, "Opening fixed wallpaper in system gallery: " + fixedWallpaperUri);
|
||||
|
||||
Uri uri = Uri.parse(fixedWallpaperUri);
|
||||
|
||||
try {
|
||||
// 方法1:使用 ACTION_SET_WALLPAPER(Android 7.0+)
|
||||
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
|
||||
// 使用系统相册应用打开固定壁纸
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, "image/*");
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
|
||||
// 设置完成后,将 app 状态改为禁用
|
||||
// 打开相册后,将 app 状态改为禁用
|
||||
config.setFixedWallpaperEnabled(true);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
fileLogger.log(TAG, "Fixed wallpaper set to system, app disabled");
|
||||
android.widget.Toast.makeText(AutoWallpaperService.this, "已将固定壁纸设置为系统壁纸,自动更新已禁用", android.widget.Toast.LENGTH_LONG).show();
|
||||
fileLogger.log(TAG, "Opened gallery for fixed wallpaper, app disabled");
|
||||
android.widget.Toast.makeText(AutoWallpaperService.this, "已在相册中打开固定壁纸,请设置为壁纸", android.widget.Toast.LENGTH_LONG).show();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to launch wallpaper picker with ACTION_SET_WALLPAPER", e);
|
||||
fileLogger.error(TAG, "ACTION_SET_WALLPAPER failed: " + e.getMessage(), e);
|
||||
|
||||
// 方法2:尝试直接设置壁纸(需要权限)
|
||||
try {
|
||||
android.app.WallpaperManager wallpaperManager =
|
||||
(android.app.WallpaperManager) getSystemService(Context.WALLPAPER_SERVICE);
|
||||
if (wallpaperManager != null && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
||||
// Android 7.0+ 可以直接设置壁纸
|
||||
java.io.InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||
if (inputStream != null) {
|
||||
android.graphics.BitmapFactory.Options options = new android.graphics.BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
android.graphics.BitmapFactory.decodeStream(inputStream, null, options);
|
||||
inputStream.close();
|
||||
|
||||
// 计算采样率
|
||||
int sampleSize = 1;
|
||||
if (options.outHeight > 2048 || options.outWidth > 2048) {
|
||||
sampleSize = Math.max(options.outHeight, options.outWidth) / 2048;
|
||||
}
|
||||
options.inJustDecodeBounds = false;
|
||||
options.inSampleSize = sampleSize;
|
||||
|
||||
inputStream = getContentResolver().openInputStream(uri);
|
||||
android.graphics.Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(inputStream, null, options);
|
||||
inputStream.close();
|
||||
|
||||
if (bitmap != null) {
|
||||
wallpaperManager.setBitmap(bitmap);
|
||||
bitmap.recycle();
|
||||
|
||||
// 设置完成后,将 app 状态改为禁用
|
||||
config.setFixedWallpaperEnabled(true);
|
||||
prefs.saveConfig(config);
|
||||
|
||||
fileLogger.log(TAG, "Fixed wallpaper set directly, app disabled");
|
||||
android.widget.Toast.makeText(AutoWallpaperService.this, "已将固定壁纸设置为系统壁纸,自动更新已禁用", android.widget.Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
throw new Exception("Failed to decode bitmap");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Exception("WallpaperManager not available or SDK too old");
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
Log.e(TAG, "Failed to set wallpaper directly", e2);
|
||||
fileLogger.error(TAG, "Direct wallpaper set failed: " + e2.getMessage(), e2);
|
||||
android.widget.Toast.makeText(AutoWallpaperService.this, "打开壁纸设置失败,请手动设置", android.widget.Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
Log.e(TAG, "Failed to open gallery", e);
|
||||
fileLogger.error(TAG, "Failed to open gallery: " + e.getMessage(), e);
|
||||
android.widget.Toast.makeText(AutoWallpaperService.this, "打开相册失败", android.widget.Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
// 没有设置固定壁纸,提示用户
|
||||
|
||||
Reference in new issue
Block a user