Commit 6c215fe6 by gao.chao

26版本直接跳转允许安装未知应用页面

parent e0c573ad
package com.mayi.demo;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import androidx.annotation.Nullable;
......@@ -14,6 +18,7 @@ import com.gc.call.CallReturnListener;
import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.bean.UserInfo;
import com.mayi.fastdevelop.comnon.Constant;
import com.mayi.fastdevelop.comnon.RequestCode;
import com.mayi.fastdevelop.okhttp.NetWorkBuilder;
import com.mayi.fastdevelop.okhttp.ResultCallback;
import com.mayi.fastdevelop.util.LogUtils;
......@@ -117,6 +122,36 @@ public class FunctionActivity extends BaseActivity {
gotoActivity(PlayerActivity.class);
}
});
findViewById(R.id.b10).setOnClickListener(new OnMultiClickListener() {
@Override
public void onMultiClick(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//开启设置安装未知来源应用权限界面
if (!getPackageManager().canRequestPackageInstalls()) {
Uri packageURI = Uri.parse("package:"+getPackageName());
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,packageURI);
startActivityForResult(intent, RequestCode.REQUEST_CODE_APP_INSTALL);
}else {
showToast("允许应用安装");
}
}else {
showToast("版本小于26,允许应用安装");
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == RequestCode.REQUEST_CODE_APP_INSTALL) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (getPackageManager().canRequestPackageInstalls()) {
showToast("允许应用安装");
} else {
showToast("未允许应用安装");
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}
......@@ -62,6 +62,12 @@
android:layout_height="wrap_content"
android:text="播放视频/音频\n未完成" />
<Button
android:id="@+id/b10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="跳转安装未知应用权限界面" />
</LinearLayout>
......
......@@ -67,7 +67,8 @@ public abstract class UpdateDownLoadAPKActvity extends BaseActivity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//开启设置安装未知来源应用权限界面
if (!context.getPackageManager().canRequestPackageInstalls()) {
Intent intent2 = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
Uri packageURI = Uri.parse("package:"+getPackageName());
Intent intent2 = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,packageURI);
startActivityForResult(intent2, RequestCode.REQUEST_CODE_APP_INSTALL);
ToastUtil.show(context, "请允许安装应用!");
return;
......
......@@ -4,7 +4,6 @@
android:layout_height="match_parent"
android:background="@color/white">
<!--再想想-->
<TextView
android:id="@+id/txt_think"
android:layout_width="wrap_content"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment