问题一:微信分享
遇到“Only fullscreen opaque activities can request orientation”报错处理
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hengtiansoft.love_security_edu/com.hengtiansoft.love_security_edu.wxapi.WXEntryActivity}: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3173)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3268)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1880)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7358)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:926)
Caused by: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
at android.app.Activity.onCreate(Activity.java:1076)
at cn.sharesdk.wechat.utils.WechatHandlerActivity.onCreate(WechatHandlerActivity.java:30)
at com.hengtiansoft.love_security_edu.wxapi.WXEntryActivity.onCreate(WXEntryActivity.java:36)
at android.app.Activity.performCreate(Activity.java:7340)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3126)
... 9 more
解决:
1、针对分享这个问题,只需在AndroidManifest.xml中去掉activity方向的设置, android:screenOrientation="portrait"
2、其他地方报错,针对报错的activity,设置activity的theme
<!--<style name="NoTranslucent">-->
<!--<item name="android:windowIsTranslucent">false</item>-->
<!--<item name="android:windowDisablePreview">true</item>-->
<!--</style>-->
问题二:应用内apk安装更新,下载完成后app crash,不在执行安装。
原因:Android8.0的变化是,未知应用安装权限的开关被除掉,取而代之的是未知来源应用的管理列表,需要在里面打开每个应用的未知来源的安装权限。Google这么做是为了防止一开始正经的应用后来开始通过升级来做一些不合法的事情,侵犯用户权益。
当你的应用直接适配到Android8之后,内部启动应用安装是会被阻塞的,如果不处理好这个未知来源的权限,会导致应用根本无法更新,只能去应用市场重新下载。
解决:
1、在清单文件中增加请求安装权限
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
2、申请打开未知来源权限。
3、打开未知来源授权列表,开启权限。
/**
* 判断是否是8.0,8.0需要处理未知应用来源权限问题,否则直接安装
*/
private void checkIsAndroidO() {
if (Build.VERSION.SDK_INT >= 26) {
boolean b = getPackageManager().canRequestPackageInstalls();
if (b) {
downloadApk();
} else {
//请求安装未知应用来源的权限
final CommonDialog dialog = new CommonDialog(mContext).builder()
.setContent("安装应用需要打开未知来源权限,请去设置中开启权限?");
dialog.setCanceledOnTouchOutside(false);
dialog.setOnCancelClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.setOnConfirmClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
ActivityCompat.requestPermissions(LaunchActivity.this, new String[]{Manifest.permission.REQUEST_INSTALL_PACKAGES}, 10010);
}
});
dialog.show();
}
} else {
down.downloadApk(LaunchActivity.this, mUrl, folderName,
apkName, apkPath, "");
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 10010:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
downloadApk();
} else {
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
startActivityForResult(intent, 10012);
}
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 10012:
checkIsAndroidO();
break;
default:
break;
}
}
结合android7.0的适配方案https://www.jianshu.com/p/470359cbfb78,完美解决apk安装更新问题。
注意:开启权限之后的更新方式要android7是一样,普通安装方式没用。
参考:http://blog.csdn.net/m18860232520/article/details/78852832
参考:http://blog.csdn.net/changmu175/article/details/78906829
网友评论