andriod网络权限

我的是andriod7版本(API 24),现在已经在AndroidManifest上添加标签:
<uses-permission android:name="android.permission.INTERNET"/>
但是据说andriod6 以上版本需要添加request permission,还有一个权限回调。

我知道GPS的权限是添加了标签以后,然后在main方法里写上:
ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},123);

然后还要添加权限的回调: 

if(ContextCompat.checkSelfPermission(context,Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
Toast.makeText(context,"Permission not granted",Toast.LENGTH_SHORT).show();
//return null;
}

LocationManager lm=(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
boolean isGPSEnabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
if(isGPSEnabled){
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,6000,10,this);//at least 6000 ms and at least move 10 m, the GPS will update
Location l=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
return l;
}else{
Toast.makeText(context,"Please enable GPS",Toast.LENGTH_LONG).show();//LONG means delay3.5 seconds

}

但是网络权限的request permission和权限回调不知道怎么写,请各位大神帮帮我。

suxiao
浏览 1068回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP