android 判断读写权限,android7.1 获取内部写入权限

android studio版本:3.4.1

build.gradle: 必须按照以下版本写,否则api25以上无法获取权限

apply plugin: 'com.android.application'

android {

compileSdkVersion 25 //这里提示要26以上,会红色报错,不管他

defaultConfig {

applicationId "com.example.evan.test"

minSdkVersion 25

targetSdkVersion 26

versionCode 1

versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {

release {

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}

}

}

dependencies {

implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation 'com.android.support:appcompat-v7:25.0.0' //这里跟上面一样

implementation 'com.android.support.constraint:constraint-layout:1.1.3'

testImplementation 'junit:junit:4.12'

androidTestImplementation 'com.android.support.test:runner:1.0.2'

androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation files('libs/commons-io-2.6.jar')

implementation 'org.jetbrains:annotations-java5:15.0'

implementation 'com.android.support:support-annotations:28.0.0'

}

androidmanifest

roundIcon

main

String macString=""; //mac地址

private static String[]PERMISSIONS_STORAGE={ //需要的權限數組

Manifest.permission.WRITE_EXTERNAL_STORAGE,

Manifest.permission.READ_EXTERNAL_STORAGE,

Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS,

Manifest.permission.INTERNET,

Manifest.permission.INSTALL_PACKAGES,

};

//请求状态码

private static int REQUEST_PERMISSION_CODE = 1;

private TextView textView;

// private String sdcardPath; //内存路径

Reader reader = null;

File file=null;

String tvShowString="";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

textView = (TextView) findViewById(R.id.tv_show);

textView.setMovementMethod(ScrollingMovementMethod.getInstance());

//单独获取权限

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP) { //判断是否android6.0以上

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, REQUEST_PERMISSION_CODE);

}

for(int i=0;i

输出:

2013-01-18 18:28:27.075 4687-4687/? I/wp----->: 执行完android.permission.WRITE_EXTERNAL_STORAGE权限为--》0

2013-01-18 18:28:27.076 4687-4687/? I/wp----->: 执行完android.permission.READ_EXTERNAL_STORAGE权限为--》0

2013-01-18 18:28:27.076 4687-4687/? I/wp----->: 执行完android.permission.MOUNT_UNMOUNT_FILESYSTEMS权限为--》-1

2013-01-18 18:28:27.077 4687-4687/? I/wp----->: 执行完android.permission.INTERNET权限为--》0

2013-01-18 18:28:27.077 4687-4687/? I/wp----->: 执行完android.permission.INSTALL_PACKAGES权限为--》-1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值