如何设置壁纸使用应用程序服务壁纸和联系人照片?
How to set wallpapers use app-services Wallpaper and Contact photo?
我在下面使用此代码,但它部分有效 - 仅在我的真实设备上设置壁纸 api23 nexus5,在其他设备上绝不会设置。也无法将墙纸设置为联系人图标。
我的操作:
- 点击按钮设置壁纸
- 在打开的windowselect服务中:
如果选择 'Contact photo' - 打开服务,如果选择任何联系人
- 实际结果:只是 return 我的壁纸应用没有设置
- 预期结果:必须打开 'crop picture' 图片,然后点击以将此图片设置为联系人图标。
如果选择了'Wallpaper'
- 实际结果:只是 return 我的壁纸应用程序没有设置和显示消息 'Can not load the image'(仅 api 23 在我的 Nexus5 上工作)
预期结果:打开服务点击设置
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); // attach services
intent.addCategory(Intent.CATEGORY_DEFAULT);
file = new File(getFolderStorageDirectory(), getFileName()); // create temp file
if (isExternalStorageWritable()) { // check whether available external storage
try {
FileOutputStream out = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); // write image
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "File not saved");
}
} else {
showToast(getString(R.string.sd_card));
}
intent.setDataAndType(Uri.parse(file.getAbsolutePath()), "image/*");
intent.putExtra("mimeType", "image/*");
intent.putExtra("jpg", "image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file.getAbsolutePath()));
startActivity(Intent.createChooser(intent, "Select service:"));
为什么不工作?
我解决了这个问题。
相反
intent.setDataAndType(Uri.parse(file.getAbsolutePath()), "image/*");
使用
setAs.setDataAndType(Uri.fromFile(mFile), "image/*");
它会起作用。
所有代码:
private void setAsUseServices() {
onCreateFileListener(); // here will create file e.g. in Picture directory
Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
setAs.addCategory(Intent.CATEGORY_DEFAULT);
Uri sourceUri = Uri.fromFile(mFile);
setAs.setDataAndType(sourceUri, "image/*");
setAs.putExtra("mimeType", "image/*");
setAs.putExtra("save_path", sourceUri);
startActivity(Intent.createChooser(setAs, "Select service:"));
}
我在下面使用此代码,但它部分有效 - 仅在我的真实设备上设置壁纸 api23 nexus5,在其他设备上绝不会设置。也无法将墙纸设置为联系人图标。
我的操作:
- 点击按钮设置壁纸
- 在打开的windowselect服务中:
如果选择 'Contact photo' - 打开服务,如果选择任何联系人
- 实际结果:只是 return 我的壁纸应用没有设置
- 预期结果:必须打开 'crop picture' 图片,然后点击以将此图片设置为联系人图标。
如果选择了'Wallpaper'
- 实际结果:只是 return 我的壁纸应用程序没有设置和显示消息 'Can not load the image'(仅 api 23 在我的 Nexus5 上工作)
预期结果:打开服务点击设置
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); // attach services intent.addCategory(Intent.CATEGORY_DEFAULT); file = new File(getFolderStorageDirectory(), getFileName()); // create temp file if (isExternalStorageWritable()) { // check whether available external storage try { FileOutputStream out = new FileOutputStream(file); mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); // write image out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "File not saved"); } } else { showToast(getString(R.string.sd_card)); } intent.setDataAndType(Uri.parse(file.getAbsolutePath()), "image/*"); intent.putExtra("mimeType", "image/*"); intent.putExtra("jpg", "image/*"); intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file.getAbsolutePath())); startActivity(Intent.createChooser(intent, "Select service:"));
为什么不工作?
我解决了这个问题。
相反
intent.setDataAndType(Uri.parse(file.getAbsolutePath()), "image/*");
使用
setAs.setDataAndType(Uri.fromFile(mFile), "image/*");
它会起作用。
所有代码:
private void setAsUseServices() {
onCreateFileListener(); // here will create file e.g. in Picture directory
Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
setAs.addCategory(Intent.CATEGORY_DEFAULT);
Uri sourceUri = Uri.fromFile(mFile);
setAs.setDataAndType(sourceUri, "image/*");
setAs.putExtra("mimeType", "image/*");
setAs.putExtra("save_path", sourceUri);
startActivity(Intent.createChooser(setAs, "Select service:"));
}