gpt4 book ai didi

android - 设置墙纸时出现弃用错误

转载 作者:搜寻专家 更新时间:2023-11-01 08:37:18 25 4
gpt4 key购买 nike

我正在尝试制作一个墙纸应用程序,但我在通过单击按钮设置墙纸时遇到错误,但我遇到了已弃用的错误这是我的 Java 代码包 com.example.neelaysrivastava.wallpaper;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.content.pm.ActivityInfo;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Switch;
import java.io.IOException;
import java.io.InputStream;


public class MainActivity extends Activity implements OnClickListener {
ImageView display;
int toPhone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
display = (ImageView) findViewById(R.id.imageView);
ImageView image1 = (ImageView) findViewById(R.id.iVmg1);
ImageView image2 = (ImageView) findViewById(R.id.iVmg2);
ImageView image3 = (ImageView) findViewById(R.id.iVmg3);
ImageView image4 = (ImageView) findViewById(R.id.iVmg4);
ImageView image5 = (ImageView) findViewById(R.id.iVmg5);
ImageView image6 = (ImageView) findViewById(R.id.iVmg6);
ImageView image7 = (ImageView) findViewById(R.id.iVmg7);
ImageView image8 = (ImageView) findViewById(R.id.iVmg8);
ImageView image9 = (ImageView) findViewById(R.id.iVmg9);
ImageView image10 = (ImageView) findViewById(R.id.iVmg10);
ImageView image11 = (ImageView) findViewById(R.id.iVmg11);
ImageView image12 = (ImageView) findViewById(R.id.iVmg12);
ImageView image13 = (ImageView) findViewById(R.id.iVmg13);
ImageView image14 = (ImageView) findViewById(R.id.iVmg14);
ImageView image15 = (ImageView) findViewById(R.id.iVmg15);
ImageView image16 = (ImageView) findViewById(R.id.iVmg16);
ImageView image17 = (ImageView) findViewById(R.id.iVmg17);
ImageView image18 = (ImageView) findViewById(R.id.iVmg18);
ImageView image19 = (ImageView) findViewById(R.id.iVmg19);
ImageView image20 = (ImageView) findViewById(R.id.iVmg20);

Button setWall =(Button)findViewById(R.id.button);
image1.setOnClickListener(this);
image2.setOnClickListener(this);
image3.setOnClickListener(this);
image4.setOnClickListener(this);
image5.setOnClickListener(this);
image6.setOnClickListener(this);
image7.setOnClickListener(this);
image8.setOnClickListener(this);
image9.setOnClickListener(this);
image10.setOnClickListener(this);
image11.setOnClickListener(this);
image12.setOnClickListener(this);
image13.setOnClickListener(this);
image14.setOnClickListener(this);
image15.setOnClickListener(this);
image16.setOnClickListener(this);
image17.setOnClickListener(this);
image18.setOnClickListener(this);
image19.setOnClickListener(this);
image20.setOnClickListener(this);
}


@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.iVmg1:
display.setImageResource(R.drawable.img1);
break;
case R.id.iVmg2:
display.setImageResource(R.drawable.img2);
break;
case R.id.iVmg3:
display.setImageResource(R.drawable.img3);
break;
case R.id.iVmg4:
display.setImageResource(R.drawable.img4);
break;
case R.id.iVmg5:
display.setImageResource(R.drawable.img5);
break;
case R.id.iVmg6:
display.setImageResource(R.drawable.img6);
break;
case R.id.iVmg7:
display.setImageResource(R.drawable.img7);
break;
case R.id.iVmg8:
display.setImageResource(R.drawable.img8);
break;
case R.id.iVmg9:
display.setImageResource(R.drawable.img9);
break;
case R.id.iVmg10:
display.setImageResource(R.drawable.img10);
break;
case R.id.iVmg11:
display.setImageResource(R.drawable.img11);
break;
case R.id.iVmg12:
display.setImageResource(R.drawable.img12);
break;
case R.id.iVmg13:
display.setImageResource(R.drawable.img13);
break;
case R.id.iVmg14:
display.setImageResource(R.drawable.img14);
break;
case R.id.iVmg15:
display.setImageResource(R.drawable.img15);
break;
case R.id.iVmg16:
display.setImageResource(R.drawable.img16);
break;
case R.id.iVmg17:
display.setImageResource(R.drawable.img17);
break;
case R.id.iVmg18:
display.setImageResource(R.drawable.img1);
break;
case R.id.iVmg19:
display.setImageResource(R.drawable.img19);
break;
case R.id.iVmg20:
display.setImageResource(R.drawable.img20);
break;
case R.id.button:
InputStream yeaaa =getResources().openRawResource(toPhone);
Bitmap Whatever = BitmapFactory.decodeStream(yeaaa);
try{
getApplicationContext().setWallpaper(Whatever);
} catch (IOException e) {
e.printStackTrace();
}
break;

}
}
}

`我正在使用 API 23,应用程序的最低 API 是 16。那么我应该怎么做才能修复错误

我试过墙纸管理器但出现错误这是代码

 case R.id.button:
InputStream yeaaa =getResources().openRawResource(toPhone);
Bitmap Whatever = BitmapFactory.decodeStream(yeaaa);
WallpaperManager myWallpaper =WallpaperManager.getInstance(this);
try{
myWallpaper.setBitmap(Whatever);
} catch (IOException e) {
e.printStackTrace();
}
break;

LOGCAT 正在展示 03-02 06:37:44.374 9764-9764/? D/AndroidRuntime:调用主入口com.android.commands.pm.Pm03-02 06:38:05.104 9777-9777/? D/AndroidRuntime: CheckJNI 关闭03-02 06:38:05.104 9777-9777/? D/dalvikvm:尝试加载库 libjavacore.so 0x003-02 06:38:05.114 9777-9777/? D/dalvikvm:添加了共享库 libjavacore.so 0x003-02 06:38:05.114 9777-9777/? D/dalvikvm:尝试加载 lib libnativehelper.so 0x003-02 06:38:05.114 9777-9777/? D/dalvikvm:添加了共享库 libnativehelper.so 0x003-02 06:38:05.114 9777-9777/? D/dalvikvm:在 libnativehelper.so 0x0 中找不到 JNI_OnLoad,跳过 init03-02 06:38:05.124 9777-9777/? D/dalvikvm:注:class Landroid/app/ActivityManagerNative;有 179 个未实现的(抽象的)方法03-02 06:38:05.214 9777-9777/? E/memtrack: 无法加载 memtrack 模块(没有那个文件或目录)03-02 06:38:05.214 9777-9777/? E/android.os.Debug: 未能加载 memtrack 模块: -203-02 06:38:05.254 9777-9777/? D/AndroidRuntime: Calling main entry com.android.commands.pm.Pm 作为错误

最佳答案

此方法自 API 5 起已弃用,您应该使用 WallpaperManager.setBitMap()相反。

关于android - 设置墙纸时出现弃用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35738990/

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