Assistant
THEME IS CLOSED |
The problem with Android 6.0 and above. The manifest contains uses-permission, but when installing says "The application does not require permissions" | Galaxy J2 prime (Android 6.0) and Honor 9 Lite (Android 6.0) |
Message#1 25.02.19, 14:25 | |
a guest [offline] Group: Users Messages 7 Check in: 26.04.12 Reputation: 0 | �������� � Android 6.0 � ����. �������� �������� uses-permission , �� ��� ��������� ������� " ���������� �� ������� ����������" downloadDevice or OS, firmware:Galaxy J2 prime (Android 6.0) and Honor 9 Lite (Android 8.0) Actually the question in the title ... On Android 4.4.2, the application requests permissions and is installed ... On new androids, it says that you do not need permissions, and then, when you need it during work, a crash occurs. Or not at all .... Permission one - location determination. The program simply has to output the location coordinates and time interval from Greenwich on request (that is, in fact, the time zone of the location. It is not large, help to understand. manifesto <? xml version = "1.0" encoding = "utf-8"?> <manifest xmlns: android = "http://schemas.android.com/apk/res/android" package = "com.sukaba.gpswork"> <application android: allowBackup = "true" android: icon = "@ mipmap / ic_launcher" android: label = "@ string / app_name" android: roundIcon = "@ mipmap / ic_launcher_round" android: supportsRtl = "true" android: theme = "@ style / AppTheme"> <activity android: name = ". MainActivity"> <intent-filter> <action android: name = "android.intent.action.MAIN" /> <category android: name = "android.intent.category.LAUNCHER" /> </ intent-filter> </ activity> </ application> <uses-permission android: name = "android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android: name = "android.permission.ACCESS_COARSE_LOCATION" /> </ manifest> Activity code package com.sukaba.gpswork; import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Toast; import java.util.Locale; import java.util.TimeZone; import static android.location.LocationManager.GPS_PROVIDER; public class MainActivity extends AppCompatActivity { EditText editText3; EditText editText4; EditText editText5; CheckBox checkBox4; private LocationManager locationManager; @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); editText3 = (EditText) findViewById (R.id.editText3); editText4 = (EditText) findViewById (R.id.editText4); editText5 = (EditText) findViewById (R.id.editText5); checkBox4 = (CheckBox) findViewById (R.id.checkbox4); // request permission to enable gps locationManager = (LocationManager) getSystemService (LOCATION_SERVICE); } @Override protected void onResume () { super.onResume (); checkBox4.setOnClickListener (new View.OnClickListener () { @Override public void onClick (View v) { if (checkBox4.isChecked ()) { // if gps is disabled then enable in settings. if (! locationManager.isProviderEnabled (GPS_PROVIDER)) { startActivity (new Intent (android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); Toast toast = Toast.makeText (MainActivity.this, “You need to enable GPS!”, Toast.LENGTH_SHORT); toast.show (); } SeekGPS (); // determine the coordinates } else { if (locationManager.isProviderEnabled (GPS_PROVIDER)) {// if gps is turned on then disable in the settings .. startActivity (new Intent (android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); Toast toast = Toast.makeText (MainActivity.this, "You can turn off GPS!", Toast.LENGTH_SHORT); toast.show (); } editText3.setText (""); // latitude editText4.setText (""); // longitude editText5.setText (""); // Timezone } } }); // for something we repeat the code .... Scheise .... warum Code wiederholen? if (checkBox4.isChecked ()) { SeekGPS (); // determine the coordinates } } // end onResume @Override protected void onPause () { super.onPause (); locationManager.removeUpdates (locationListener); // data is deleted } // zusätzliche Methoden .... // this method searches for coordinates if GPS is on private void SeekGPS () { // some kind of crap about the revocation of permission received earlier, in new versions of Android (the studio itself wrote) final int PERMISSION_REQUEST = 1; if (ContextCompat.checkSelfPermission (this, Manifest.permission.ACCESS_FINE_LOCATION)! = PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions (this, new String [] {Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST); } // then catch the coordinates if the GPS is on if (locationManager.isProviderEnabled (GPS_PROVIDER)) { Toast toast = Toast.makeText (MainActivity.this, "Search for coordinates by GPS!", Toast.LENGTH_LONG); toast.show (); locationManager.requestLocationUpdates (GPS_PROVIDER, 5000, 100, locationListener); } } // this method monitors the GPS module and, when it receives coordinates, displays them as strings final LocationListener locationListener = new LocationListener () { @Override public void onLocationChanged (Location location) {// receipt of new coordinate data - they can be displayed if (location == null) { return; } if (location.getProvider (). equals (LocationManager.GPS_PROVIDER)) { editText3.setText (String.valueOf (String.format (Locale.US, "%. 4f", location.getLatitude ()))); editText4.setText (String.valueOf (String.format (Locale.US, "%. 4f", location.getLongitude ()))); editText5.setText (String.valueOf (String.format (Locale.US, "% 3d", (TimeZone.getDefault (). getRawOffset ()) / 3600000))); } } @Override public void onStatusChanged (String provider, int status, Bundle extras) {// status change is not interested } @Override public void onProviderDisabled (String provider) {// gps disabled by user } @Override public void onProviderEnabled (String provider) {// gps enabled by user } }; } // end of activation class And the source is not a pity ... under Android Studio Files: gpsWork.rar(8.11 MB) Post has been editedqorbobo70 - 25.02.19, 14:34 |
Message#2 25.02.19, 15:41 | |
Guru [offline] Group: Moderators Messages 2600 Check in: 18.04.16 Lenovo A7000 Reputation: 512 | M The rules of the section "Android - Development and Programming" 2.2.Before creating a theme, usesearch the forumPerhaps such a topic already exists. You can ask about your question here. Programming Questions Editing framework-res.apk Discuss ways to edit system resources Locked! Post has been editedderak1129 - 25.02.19, 16:53 Reason for editing: links |
mobile version | Now: 03/30/19, 23:31 |