2017-11-25 1 views
1

Ich versuche den gps-Chip meines Smartphones programmtechnisch mit der sendExtraCommand() - Methode zu löschen. In meinem Manifest-Datei habe ich die Erlaubnis zusätzliche Befehle wie folgt an:location sendExtraCommands - Methode funktioniert nicht und schaltet die App herunter

<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>

Die Methode selbst nenne ich wie folgt aus:

locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "delete_aiding_data", null)

Wenn ich es auf dem Emulator versuchen oder auf Mein Smartphone stürzt ab. Ich weiß nicht, was ich falsch mache, also würde ich es sehr schätzen, wenn sich jemand mein Problem ansehen könnte.

Meine einzige Aktivität, die MainActivity:

public class MainActivity extends AppCompatActivity { 

     private TextView textView; 
     private Button button; 
     private LocationManager locationManager; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 

      textView = (TextView) findViewById(R.id.txtView1); 
      textView.setText("Gps Reset: "); 

      button = (Button) findViewById(R.id.button); 

      locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); 

      boolean enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
    System.out.println(enabled); 

      button.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        sendXtraCommand(); 
       } 
      }); 

     } 

     private void sendXtraCommand(){ 
      boolean reset = locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "delete_aiding_data", null); 
      if(reset){ 
       textView.append("true"); 
      }else{ 
       textView.append("false"); 
      } 
     } 
    } 

Und hier meine Manifest-Datei:

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.felix.resetgps"> 

     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
     <uses-feature android:name="android.hardware.location.gps" /> 
     <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/> 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
     <uses-permission android:name="android.permission.INTERNET"/> 

     <application 
      android:allowBackup="true" 
      android:icon="@mipmap/ic_launcher" 
      android:label="@string/app_name" 
      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> 

    </manifest> 

Dies ist die Botschaft, die ich auf der Konsole:

11/25 14:32:41: Launching app 
    $ adb shell am start -n   "com.example.felix.resetgps/com.example.felix.resetgps.MainActivity" -a   android.intent.action.MAIN -c android.intent.category.LAUNCHER -D 
    Waiting for application to come online: com.example.felix.resetgps | com.example.felix.resetgps.test 
    Waiting for application to come online: com.example.felix.resetgps | com.example.felix.resetgps.test 
    Connecting to com.example.felix.resetgps 
    I/art: Not late-enabling -Xcheck:jni (already on) 
    W/art: Unexpected CPU variant for X86 using defaults: x86 
    W/ActivityThread: Application com.example.felix.resetgps is waiting for the debugger on port 8100... 
    I/System.out: Sending WAIT chunk 

      [ 11-25 13:32:41.598 1794: 1815 D/   ] 
      HostConnection::get() New Host Connection established 0x8bf7f400, tid 1815 
    I/art: Debugger is active 
    Connected to the target VM, address: 'localhost:8615', transport: 'socket' 
    I/System.out: Debugger has connected 
    I/System.out: waiting for debugger to settle... 
    I/System.out: waiting for debugger to settle... 
    I/System.out: waiting for debugger to settle... 
    I/System.out: waiting for debugger to settle... 
    I/System.out: waiting for debugger to settle... 
    I/System.out: waiting for debugger to settle... 
    I/System.out: waiting for debugger to settle... 
    I/System.out: debugger has settled (1396) 
    W/System: ClassLoader referenced unknown path: /data/app/com.example.felix.resetgps-1/lib/x86 
    I/InstantRun: Instant Run Runtime started. Android package is com.example.felix.resetgps, real application class is null. 
    W/System: ClassLoader referenced unknown path: /data/app/com.example.felix.resetgps-1/lib/x86 
    I/art: Starting a blocking GC Instrumentation 
    W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 
    I/System.out: true 
    I/OpenGLRenderer: Initialized EGL, version 1.4 
    D/OpenGLRenderer: Swap behavior 1 
    D/AndroidRuntime: Shutting down VM 
    E/AndroidRuntime: FATAL EXCEPTION: main 
       Process: com.example.felix.resetgps, PID: 4869 
       java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission. 
        at android.os.Parcel.readException(Parcel.java:1683) 
        at android.os.Parcel.readException(Parcel.java:1636) 
        at android.location.ILocationManager$Stub$Proxy.sendExtraCommand(ILocationManager.java:1274) 
        at android.location.LocationManager.sendExtraCommand(LocationManager.java:2226) 
        at com.example.felix.resetgps.MainActivity.sendXtraCommand(MainActivity.java:51) 
        at com.example.felix.resetgps.MainActivity.access$000(MainActivity.java:16) 
        at com.example.felix.resetgps.MainActivity$1.onClick(MainActivity.java:44) 
        at android.view.View.performClick(View.java:5610) 
        at android.view.View$PerformClick.run(View.java:22265) 
        at android.os.Handler.handleCallback(Handler.java:751) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6077) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
    Disconnected from the target VM, address: 'localhost:8615', transport: 'socket' 

Antwort

1

Wenn Sie schauen die Log-Katze sorgfältig Sie können das

finden
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

fehlt.

Für Android Unter Android 6.0 (API 23) und höher müssen wir eine Laufzeitberechtigung hinzufügen.

Siehe diese Antwort zu ihrer Umsetzung:

ACCESS_FINE_LOCATION permissions

+0

Hallo, Surja, Ihnen für Ihre Antwort danken. Ja, der Fehler sagt das, aber ich habe diese Erlaubnis bereits in meinem Manifest. – Felix

+0

Versuchen Sie, dynamische Berechtigung hinzuzufügen, die Ihr Problem lösen wird, können Sie diesen Link verweisen https://StackOverflow.com/Questions/46915957/access-fine-location-permissions –

+0

Ah ok vielen Dank. Ich werde es versuchen :) – Felix

Verwandte Themen