無法安裝更新APK
經(jīng)過搜索發(fā)現(xiàn)我們在AndroidManifest新增一個權(quán)限
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
異常: Only fullscreen opaque activities can request orientation
最近我升級到27之后發(fā)現(xiàn)突然分享界面報錯,類似下面這種
java.lang.IllegalStateException: Only fullscreen activities can request orientation
最后發(fā)現(xiàn)是因?yàn)檎{(diào)用這樣的代碼
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
經(jīng)過搜索發(fā)現(xiàn)26的增加設(shè)置方向的判斷
public static boolean isTranslucentOrFloating(TypedArray attributes) {
final boolean isTranslucent = attributes.getBoolean(com.android.internal.R.styleable.Window_windowIsTranslucent, false);
final boolean isSwipeToDismiss = !attributes.hasValue( com.android.internal.R.styleable.Window_windowIsTranslucent)
&& attributes.getBoolean( com.android.internal.R.styleable.Window_windowSwipeToDismiss, false);
final boolean isFloating = attributes.getBoolean(com.android.internal.R.styleable.Window_windowIsFloating, false);
return isFloating || isTranslucent || isSwipeToDismiss;
}
根據(jù)上面的定義崎弃,如果一個Activity的Style符合下面三個條件之一惶桐,認(rèn)為不是“fullscreen”:
- “windowIsTranslucent”為true;
- “windowIsTranslucent”為false淀歇,但“windowSwipeToDismiss”為true易核;
- “windowIsFloating“為true;
綜上可見房匆,這個改動的目的是想阻止非全屏的Activity鎖定屏幕旋轉(zhuǎn)耸成,因?yàn)楫?dāng)前Activity是透明的报亩,浮動的或可滑動取消的,是否鎖屏應(yīng)該由全屏的Activity決定井氢,而不是并沒有全部占據(jù)屏幕的Activity決定弦追。
解決方法:
只要你設(shè)置不符合上面三個條件即可,而且這個坑27已經(jīng)沒有了花竞。
定位相關(guān)
為降低功耗劲件,無論應(yīng)用的目標(biāo) SDK 版本為何,Android 8.0 都會對后臺應(yīng)用檢索用戶當(dāng)前位置的頻率進(jìn)行限制约急。
如果您的應(yīng)用在后臺運(yùn)行時依賴實(shí)時提醒或運(yùn)動檢測零远,這一位置檢索行為就顯得特別重要,必須緊記厌蔽。
重要說明:作為起點(diǎn)牵辣,我們只允許后臺應(yīng)用每小時接收幾次位置更新。我們將在整個預(yù)覽版階段繼續(xù)根據(jù)系統(tǒng)影響和開發(fā)者的反饋優(yōu)化位置更新間隔奴饮。
詳細(xì)可以點(diǎn)開這個官方說明
也就是如果持續(xù)的定位需求纬向,必須通過一個通知開啟一個前臺服務(wù)
解決方法:
我是如此寫的(語言為Kotlin)戴卜,其實(shí)就是很簡單的開啟一個前臺服務(wù)
class LocationForegoundService : Service() {
private val mBinder = LocalBinder()
private var channel:NotificationChannel ?= null
inner class LocalBinder : Binder() {
fun getService(): LocationForegoundService = this@LocationForegoundService
}
override fun onBind(intent: Intent): IBinder {
return mBinder
}
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
//Android O上才顯示通知欄
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
showNotify()
}
return super.onStartCommand(intent, flags, startId)
}
//顯示通知欄
private fun showNotify() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (channel == null){
channel = createNotificationChannel()
}
val builder = NotificationCompat.Builder(applicationContext, packageName)
val nfIntent = Intent(this, MainActivity::class.java)
builder.setContentIntent(PendingIntent.getActivity(this, 0, nfIntent, 0))
.setLargeIcon(BitmapFactory.decodeResource(this.resources, R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.push_notification_icon)
.setContentTitle("正在后臺定位")
.setContentText("定位進(jìn)行中")
.setWhen(System.currentTimeMillis())
val notification = builder.build()
//調(diào)用這個方法把服務(wù)設(shè)置成前臺服務(wù)
startForeground(110, notification)
}
}
@TargetApi(Build.VERSION_CODES.O)
private fun createNotificationChannel(): NotificationChannel {
val channel = NotificationChannel(packageName,
"",
NotificationManager.IMPORTANCE_HIGH)
// 獲取NotificationManager
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE)
as NotificationManager
// 創(chuàng)建通知渠道
notificationManager.createNotificationChannel(channel)
return channel
}
}