
SecurityException。
打开前台服务,需要有通知栏体现:
Intent intent = new Intent(this, ForegroundService.class);
ContextCompat.startForegroundService(this, intent);
要请求让服务运行于前台,在ForegroundService.class里需要调用如下方法启动通知栏:
startForeground(NOTIFICATION_ID, notification);
对非Android SDK API的调用做了限制,通常会出现类似NoSuchClassException或NoSuchFieldException异常。
非SDK API包括Android未公开的底层内部实现细节的API反射调用。还有NDK里未公开的方法调用等。
需要排查有哪些非SDK API可以使用如下方法
@TargetApi(Build.VERSION_CODES.P)
@RequiresApi(api = Build.VERSION_CODES.P)
private void setUpStrictMode() {
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()//检测其他所有问题:Detect everything that's potentially suspect.In the Honeycomb release this includes leaks of SQLite cursors, Activities, and other closable objects but will likely expand in future releases.
.detectFileUriExposure()//文件的URI格式为file://协议的错误检测
.detectContentUriWithoutPermission()//URI未授权访问检测
.detectNonSdkApiUsage()//非SDK API使用检测
.build());
}
若要支持安全的密文传输,可按照Google的 网络安全配置 去实现
AndroidManifest.xml添加以下内容:<
android {//build.gradle
useLibrary 'org.apache.http.legacy'
}
解决办法是不设置orientation。或设置值为android:screenOrientation="unspecified"
在 Android 9 中,您不能从非 Activity 环境中启动 Activity,除非您传递 Intent 标志 FLAG_ACTIVITY_NEW_TASK。 如果您尝试在不传递此标志的情况下启动 Activity,则该 Activity 不会启动,系统会在日志中输出一则消息。
注:在 Android 7.0(API 级别 24)之前,标志要求一直是期望的行为并被强制执行。 Android 7.0 中的一个错误会临时阻止实施标志要求。
