我买了一部用来测试我的Android应用的手机。手机API级别至少需要16级。我有一个我正在创建的应用程序,其中有一些代码要求API级别为23.当我尝试将最低级别更改为16时,我收到了一个错误代码,表明& #34;调用需要API级别23(当前最小值为16)#tickselfpermission"。这与我的主要活动的底部有关,其中有代码要求用户访问其图像的权限。有没有办法改变它,以便我可以在手机上试试?我想知道更改代码,而不是API。
public class MainActivity extends AppCompatActivity {
EditText editText2;
public void getPhoto() {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent,1);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode ==1){
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED);{
getPhoto();
}
}
}
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText2 = (EditText) findViewById(R.id.editText2);
editText2.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER) && (event.getAction() ==
KeyEvent.ACTION_DOWN)) {
String currentStr = editText2.getText().toString();
String temp[] = currentStr.split("\n");
String result = "";
for (int i = 0; i < temp.length - 1; i++) {
result += temp[i] + "\n";
}
if (temp.length == 1) {
result = result + "\u2022 " + temp[temp.length - 1];
} else {
result = result.substring(0, result.length() - 1);
result = result + "\n\u2022 " + temp[temp.length - 1];
}
editText2.setText(result);
editText2.setSelection(editText2.getText().length());
}
return false;
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode ==1 && resultCode == RESULT_OK && data != null) {
Uri selectedImage = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);
imageView2.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void click(View view) {
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
} else {
getPhoto();
}
}
}
答案 0 :(得分:0)
存储在API级别23及更高级别中需要许可。对于以下API级别23,将自动授予权限。 有关详细信息,请参阅:): 因此您需要按照以下方式管理权限:
<?php
include "db_connection.php";
$locations=array();
$query = $conn->query('SELECT `pg_address` FROM `tbl_master_property` limit 10');
while ($row =$query->fetch_assoc()) {
$list[] = $row;
}
?>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Geocoding service</title>
<style>
html, body, #map-canvas
{
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
var data = <?php echo json_encode($list); ?>;
//console.log(data);
var pglist = (JSON.stringify(data));
//alert(pglist);
function initialize()
{
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(53.3496, -6.3263);
var mapOptions =
{
zoom: 8,
center: latlng
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
codeAddress(pglist);//call the function
}
function codeAddress(address)
{
geocoder.geocode( {address:address}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);//center the map over the result
//place a marker at the location
var marker = new google.maps.Marker(
{
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>