我正在制作一个应用程序,其中包含可以在棉花糖前设备上执行的一部分活动以及棉花糖及以上活动的某些部分。 所以我想要做的是不要让应用程序在运行marshmallow设备支持的活动的pre marshmallow设备上崩溃,只显示你的设备不支持该模块访问的toast。
在这里,我卡在指纹模块上,它会破坏棉花糖前设备上的应用程序。
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
//do something
}
else
showToastMessage();
错误
FATAL EXCEPTION: main
java.lang.VerifyError: com/example/android/fingerprintdialog/MainActivity
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
在我的应用程序中,我有一个需要运行时权限的下载按钮。
这就是我设法做到的方式:
public static int MY_PERMISSIONS_REQUEST_DOWNLOAD_IMAGE = 1;
btnDownLoad.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
urlFromDownload();
}
});
public void urlFromDownload() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermission(getActivity(),
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_DOWNLOAD_IMAGE);
} else {
DowloadFileFromUrl downloadwall = new DowloadFileFromUrl();
if (downloadwall.getStatus() == AsyncTask.Status.RUNNING) {
// My AsyncTask has not started yet
Toast.makeText(getActivity(), "Please wait until download is complete", Toast.LENGTH_SHORT).show();
} else {
downloadwall.execute(imageUrl);
}
}
} else {
DowloadFileFromUrl downloadwall = new DowloadFileFromUrl();
if (downloadwall.getStatus() == AsyncTask.Status.RUNNING) {
// My AsyncTask has not started yet
Toast.makeText(getActivity(), "Please wait until download is complete", Toast.LENGTH_SHORT).show();
} else {
downloadwall.execute(imageUrl);
}
}
}
我希望你理解我的代码。我所做的是写下我的下载代码两次。首先是棉花糖,第二个是低版本。
答案 1 :(得分:0)
将其置于以下条件下
if (Build.VERSION.SDK_INT >= 23) {
// Your code for
} else {
// Code for previous versions
}
答案 2 :(得分:0)
只需检查已安装的应用是否使用marshmallow或以上Android操作系统。
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M)
{
// FingerPrint is supported by Android
// Show the FingerPrint touch screen.
}
else
{
//FingerPrint is not supported by Android
//Don't show the FingerPrint touch screen.
}