[笔记]android 版本问题

精準延时呼叫

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);        int offset = 10 * 1000;//间隔时间10s        long triggerAtTime = SystemClock.elapsedRealtime() + offset;        Intent i = new Intent(this, ForegroundService.class);        PendingIntent mPendingIntent = PendingIntent.getService(this, 0, i, 0);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {            alarmManager.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, mPendingIntent);            Log.i(TAG, "API 23+ ");        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {            alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, mPendingIntent);            Log.i(TAG, "API 19+ ");        } else {            alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, offset, mPendingIntent);            Log.i(TAG, "API 19- ");        }

开机启动服务

AndroidManifest加入    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {            context.startForegroundService(i);        }else {            context.startService(i);        }

连结http网页需在AndroidManifest加入

android:usesCleartextTraffic="true"

android 6 以前的webView无法吃ES6的JS


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章