Android开发设置锁屏壁纸 40
Android开发设置锁屏壁纸我在以前的项目里通过WallpaperManager更改了桌面壁纸,现在想只更改锁屏壁纸该怎么实现(可以的话给我看一下Java代码谢谢)...
Android开发设置锁屏壁纸我在以前的项目里通过WallpaperManager更改了桌面壁纸,现在想只更改锁屏壁纸该怎么实现(可以的话给我看一下Java代码谢谢)
展开
2017-02-06 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File file = new File("mnt/sdcard2/DCIM/Camera/IMG_20120216_160054.jpg");
Intent intent = createSetAsIntent(Uri.fromFile(file),null);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(intent, "设置壁纸"));
// file:///mnt/sdcard2/DCIM/Camera/IMG_20120216_160054.jpg
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public static Intent createSetAsIntent(Uri uri, String mimeType) {
// Infer MIME type if missing for file URLs.
if (uri.getScheme().equals("file")) {
String path = uri.getPath();
int lastDotIndex = path.lastIndexOf('.');
if (lastDotIndex != -1) {
mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(
uri.getPath().substring(lastDotIndex + 1)
.toLowerCase());
}
}
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(uri, mimeType);
intent.putExtra("mimeType", mimeType);
return intent;
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File file = new File("mnt/sdcard2/DCIM/Camera/IMG_20120216_160054.jpg");
Intent intent = createSetAsIntent(Uri.fromFile(file),null);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(intent, "设置壁纸"));
// file:///mnt/sdcard2/DCIM/Camera/IMG_20120216_160054.jpg
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public static Intent createSetAsIntent(Uri uri, String mimeType) {
// Infer MIME type if missing for file URLs.
if (uri.getScheme().equals("file")) {
String path = uri.getPath();
int lastDotIndex = path.lastIndexOf('.');
if (lastDotIndex != -1) {
mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(
uri.getPath().substring(lastDotIndex + 1)
.toLowerCase());
}
}
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(uri, mimeType);
intent.putExtra("mimeType", mimeType);
return intent;
}
追问
没用到WM方法,另外这个是网上的我试过了......
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询