2016-05-15 4 views
-3

Ich habe die Erlaubnis von android.permission.ACCESS_COARSE_LOCATION in der Manifest.xml und Code ist unten."Weder Benutzer 10046 noch aktueller Prozess hat android.permission.ACCESS_COARSE_LOCATION" aber es ist in meinem Manifest

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 

GsmCellLocation location = (GsmCellLocation) tm.getCellLocation(); 
int cellID = location.getCid(); 
int lac = location.getLac(); 

Toast.makeText(getApplicationContext(), cellID, Toast.LENGTH_LONG).show(); 

Allerdings stürzte es mit der folgenden Fehlermeldung ab. Bitte prüfen Sie, wie Sie diese Art von Problem lösen können.

05-15 23:23:09.844 22602-22602/use.uevision.com.myapplication E/AndroidRuntime: FATAL EXCEPTION: main 
    Process: use.uevision.com.myapplication, PID: 22602 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{cctvkim.truevision.com.myapplication/cctvkim.truevision.com.myapplication.MainActivity}: java.lang.SecurityException: getCellLocation: Neither user 10046 nor current process has android.permission.ACCESS_COARSE_LOCATION. 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
     at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:158) 
     at android.app.ActivityThread.main(ActivityThread.java:7225) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
    Caused by: java.lang.SecurityException: getCellLocation: Neither user 10046 nor current process has android.permission.ACCESS_COARSE_LOCATION.strong text 
     at android.os.Parcel.readException(Parcel.java:1620) 
     at android.os.Parcel.readException(Parcel.java:1573) 
     at com.android.internal.telephony.ITelephony$Stub$Proxy.getCellLocation(ITelephony.java:3311) 
     at android.telephony.TelephonyManager.getCellLocation(TelephonyManager.java:963) 
     at cctvkim.truevision.com.myapplication.MainActivity.onCreate(MainActivity.java:21) 
     at android.app.Activity.performCreate(Activity.java:6876) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
     at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:158) 
     at android.app.ActivityThread.main(ActivityThread.java:7225) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
05-15 23:23:13.804 22602-22602/cctvkim.truevision.com.myapplication I/Process: Sending signal. PID: 22602 SIG: 9 

Antwort

0

Sie sollten RuntimePermissions verwenden. Startins mit Android M müssen Sie bei Runtime nach Berechtigungen fragen. Bitte beachten Sie den Link.

if (ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, MY_PERMISSIONS_REQUEST); 
}else{ 
      //do your job 
} 
+0

E/Android Runtime: fatal EXCEPTION: main Prozess: cctvkim.truevision.com.myapplication, PID: 10696 java.lang.RuntimeException: Kann nicht Aktivität ComponentInfo {cctvkim.truevision.com.myapplication/cctvkim.truevision starten. com.myapplication.MainActivity}: android.content.res.Resources $ NotFoundException: String resource ID # 0x261e60e –

+0

Vielen Dank für Ihre freundliche Antwort. Ich habe getan, wie Sie gesagt haben, aber ich habe die andere Fehlermeldung wie oben. Wenn ich nur "Hallo" anstoße, funktioniert es, aber wenn ich versuche, cellID oder lac zu toasten, ist es abgestürzt. Irgendeine Idee?? –

+0

eine andere Fehlermeldung bedeutet ein anderes Problem. Wenn ich dein Problem gelöst habe - akzeptiere meine Antwort. Die andere Fehlermeldung, die Sie erhalten haben, sieht so aus, als ob Ihr Standort immer noch Null ist und Sie versuchen, Daten von ihm zu erhalten. Umgeben Sie es mit if (location! = Null) –

-1

Sie müssen die Berechtigung READ_PHONE_STATE für die Verwendung von TelephonyManager hinzufügen. fügen Sie diese Berechtigung in Ihrer Menifestdatei hinzu.

+1

Warum wird dies abgelehnt? Das ist die richtige Antwort. – not2qubit

Verwandte Themen