android - SDK 级别检查的问题

标签 android sdk logcat

我正在 4.4.2 设备上运行测试,出现奇怪的日志,验证应该可以防止这种情况发生:

日志:

I/dalvikvm: Could not find method android.app.AlarmManager.setAndAllowWhileIdle, referenced from method initTimer

I/dalvikvm: Could not find method requestPermissions, referenced from method MyActivity.requestPermissions

方法类:

void requestPermissions() {

        List<String> permissionsNeeded = new ArrayList<>();

        final List<String> permissionsList = new ArrayList<>();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //verify permission

            return;
        }
        //normal flow

}



void initTimerGetRegions(Context context) { 

    AlarmManager processTimer = Memory.getInstance().getTimer(context);
    Intent intentAlarm = new Intent(context, TimerReceiver.class);
    PendingIntent pendingIntentAlarm = PendingIntent.getBroadcast(context, 1,
            intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        processTimer.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, pendingIntentAlarm);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        processTimer.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, pendingIntentAlarm);
    } else {
        processTimer.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, pendingIntentAlarm);
    }


}   

显然代码适用于较高版本,但较低版本正在抓取这些日志。

最佳答案

strange logs are coming up

它们完全正常。

the verification should prevent this

没有。

这些是来自 Dalvik VM 的消息,表明当它加载到您的类中时,很难找到某些方法。这是因为这些方法仅适用于较新版本的 Android。

不过,关键是日志行的第一个字母:I。这是一条情报信息。这不是错误。只要您不尝试执行任何这些缺失的方法,一切都很好。

关于android - SDK 级别检查的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45505021/

相关文章:

ios - 使用移动应用跟踪 SDK iOS 跟踪应用内事件

android logcat 记录聊天模块行相同的消息

android - UnsatisfiedLinkError : n_Mat while using opencv2. 4.3 与 android 4.0

android - 如何在 Android Studio 的 Logcat 选项卡中增加过滤器输入的大小

android - 使用旧的 sdk 版本创建 Android 应用程序有缺点吗?

android - 使用 HockeyApp SDK 自动更新应用程序

android - 无法理解 android 开发网站上的 viewmodel 示例

Android 的媒体播放器 : Why is an audio loop not staying synced with metronome playing at the same BPM?

android - 应用程序启动、停止和暂停时的事件

Android SDK 管理器获取失败