Problem mit Cell id

Progger

Mitglied
Hallo,
ich habe heute versucht folgendes Programm von dieser Seite
Android Coding: Get location of Cell ID, from opencellid.org using HttpGet(). zu starten, aber es kommt dann beim
Programmstart immer die Meldung, dass es leider stoppen musste.

Liegt es vll. daran, dass es im Emulator nicht funktioniert (kann es momentan nur da testen), oder ist es ev.
doch ein Rechteproblem. Ich habe das hier im Manifest eingetragen:

Java:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    
    
    package="com.cell"
    android:versionCode="1"
    android:versionName="1.0" >
	<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
	<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
	<uses-permission android:name="android.permission.READ_PHONE_STATE" />
	<uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk android:minSdkVersion="8" />
	
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".CellActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
	
</manifest>

Würde gerne bei OpenCellID beitragen ohne einen Client von deren Homepage verwenden zu müssen.

Vielen Dank schon mal...
Lg
 

Progger

Mitglied
Danke schon mal...
Hab den Inhalt von Logcat hier mal gepostet. Könnte es etwas mit den Berechtigungen zu tun haben?

Java:
06-13 17:44:44.266: I/dalvikvm(556): threadid=3: reacting to signal 3
06-13 17:44:44.595: I/dalvikvm(556): Wrote stack traces to '/data/anr/traces.txt'
06-13 17:44:44.765: V/DroidNova(556): mint Value:0
06-13 17:44:44.785: I/dalvikvm(556): threadid=3: reacting to signal 3
06-13 17:44:44.825: D/AndroidRuntime(556): Shutting down VM
06-13 17:44:44.835: W/dalvikvm(556): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
06-13 17:44:44.835: I/dalvikvm(556): Wrote stack traces to '/data/anr/traces.txt'
06-13 17:44:44.875: E/AndroidRuntime(556): FATAL EXCEPTION: main
06-13 17:44:44.875: E/AndroidRuntime(556): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cell/com.cell.CellActivity}: java.lang.NullPointerException
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.os.Handler.dispatchMessage(Handler.java:99)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.os.Looper.loop(Looper.java:137)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at java.lang.reflect.Method.invokeNative(Native Method)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at java.lang.reflect.Method.invoke(Method.java:511)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at dalvik.system.NativeStart.main(Native Method)
06-13 17:44:44.875: E/AndroidRuntime(556): Caused by: java.lang.NullPointerException
06-13 17:44:44.875: E/AndroidRuntime(556): 	at com.cell.CellActivity.onCreate(CellActivity.java:130)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.app.Activity.performCreate(Activity.java:4465)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-13 17:44:44.875: E/AndroidRuntime(556): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-13 17:44:44.875: E/AndroidRuntime(556): 	... 11 more
06-13 17:44:45.286: I/dalvikvm(556): threadid=3: reacting to signal 3
06-13 17:44:45.296: I/dalvikvm(556): Wrote stack traces to '/data/anr/traces.txt'
06-13 17:44:45.455: I/dalvikvm(556): threadid=3: reacting to signal 3
06-13 17:44:45.475: I/dalvikvm(556): Wrote stack traces to '/data/anr/traces.txt'
06-13 17:49:44.946: I/Process(556): Sending signal. PID: 556 SIG: 9
 

schlingel

Gesperrter Benutzer
Der Log sagt, dass du eine NPE im onCreate hast.

Ohne Code vom onCreate kann man nicht viel sagen aber da eh die Zeilennummer dabei steht, kommst du vielleicht so schon weiter.
 

Progger

Mitglied
Danke für den Hinweis...leider hat sich das Problem noch nicht gelöst.

Ich hier den Code von der Seite nochmal gepostet...vll. ist es ja etwas offensichtliches...
Andere Frage: Da es mir ja nur um die Abfrage der Cell Id geht, würde ich gern wissen ob jemand ein Code Beispiel
hat dass bei ihm funktioniert hat, weil sämtliche Beispiele die ich probiert habe hatten dieses Problem.


Java:
package com.cell;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.widget.TextView;

import android.util.Log;

public class CellActivity extends Activity {
	
	public static final String LOG_TAG = "DroidNova";

 public class OpenCellID {
  String mcc;  //Mobile Country Code
  String mnc;  //mobile network code
  String cellid; //Cell ID
  String lac;  //Location Area Code
  
  Boolean error;
  String strURLSent;
  String GetOpenCellID_fullresult;
  
  String latitude;
  String longitude;
  
  public Boolean isError(){
   return error;
  }
  
  public void setMcc(String value){
   mcc = value;
  }
  
  public void setMnc(String value){
   mnc = value;
  }
  
  public void setCallID(int value){
   cellid = String.valueOf(value);
  }
  
  public void setCallLac(int value){
   lac = String.valueOf(value);
  }
  
  public String getLocation(){
   return(latitude + " : " + longitude);
  }
  
  public void groupURLSent(){
   strURLSent =
    "http://www.opencellid.org/cell/get?mcc=" + mcc
    +"&mnc=" + mnc
    +"&cellid=" + cellid
    +"&lac=" + lac
    +"&fmt=txt";
  }
  
  public String getstrURLSent(){
   return strURLSent;
  }
  
  public String getGetOpenCellID_fullresult(){
   return GetOpenCellID_fullresult;
  }
  
  public void GetOpenCellID() throws Exception {
   groupURLSent();
   HttpClient client = new DefaultHttpClient();
   HttpGet request = new HttpGet(strURLSent);
   HttpResponse response = client.execute(request);
   GetOpenCellID_fullresult = EntityUtils.toString(response.getEntity()); 
   spliteResult();
  }
  
  private void spliteResult(){
   if(GetOpenCellID_fullresult.equalsIgnoreCase("err")){
    error = true;
   }else{
    error = false;
    String[] tResult = GetOpenCellID_fullresult.split(",");
    latitude = tResult[0];
    longitude = tResult[1];
   }
    
   
  }
 }

 int myLatitude, myLongitude;
 OpenCellID openCellID;

 
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       
       int mInt = 0;
       Log.v(LOG_TAG, "mint Value:" + mInt);
       
       TextView textGsmCellLocation = (TextView)findViewById(R.id.gsmcelllocation);
       TextView textMCC = (TextView)findViewById(R.id.mcc);
       TextView textMNC = (TextView)findViewById(R.id.mnc);
       TextView textCID = (TextView)findViewById(R.id.cid);
       TextView textLAC = (TextView)findViewById(R.id.lac);
       TextView textGeo = (TextView)findViewById(R.id.geo);
       TextView textRemark = (TextView)findViewById(R.id.remark);
      
       //retrieve a reference to an instance of TelephonyManager
       TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
       GsmCellLocation cellLocation = (GsmCellLocation)telephonyManager.getCellLocation();
      
       String networkOperator = telephonyManager.getNetworkOperator();
       String mcc = networkOperator.substring(0, 3);
       String mnc = networkOperator.substring(3);
       textMCC.setText("mcc: " + mcc);
       textMNC.setText("mnc: " + mnc);
      
       int cid = cellLocation.getCid();
       int lac = cellLocation.getLac();
       textGsmCellLocation.setText(cellLocation.toString());
       textCID.setText("gsm cell id: " + String.valueOf(cid));
       textLAC.setText("gsm location area code: " + String.valueOf(lac));
      
       openCellID = new OpenCellID();
      
       openCellID.setMcc(mcc);
       openCellID.setMnc(mnc);
       openCellID.setCallID(cid);
       openCellID.setCallLac(lac);
       try {
           openCellID.GetOpenCellID();
   
           if(!openCellID.isError()){
               textGeo.setText(openCellID.getLocation());
               textRemark.setText( "\n\n" + "URL sent: \n" + openCellID.getstrURLSent() + "\n\n" + "response: \n" + openCellID.GetOpenCellID_fullresult);
           }else{
               textGeo.setText("Error");
           }
       } 
       catch (Exception e) {
            // TODO Auto-generated catch block
           e.printStackTrace();
           textGeo.setText("Exception: " + e.toString());
       }
   }   
}

Quelle: Android Coding: Get location of Cell ID, from opencellid.org using HttpGet().
 

schlingel

Gesperrter Benutzer
Wieso machst du das nicht mit einem normalen LocationListener anstatt über die Cell-ID?

PS: Kann es sein, dass du auf einem Emulator testest? Denn dort bekommst du wenn dann nur eine Fake-Location die du selbst einstellen musst. Ansonsten ist die Location nicht erreichbar und laut Doku gibt dann der TelephonyManager null zurück.

Das heißt übrigens das der Code nicht defensiv genug programmiert ist, wie du gerade am eigenen Leib erfährst und zum anderen würde es mich interessieren wo der Vorteil davon ist, dass so selbst zu machen wenn's anders bequemer geht.
 
Zuletzt bearbeitet:

Progger

Mitglied
Ah ok, dass war das Problem...
mit einer zusätzlichen if Abfrage funktioniert es jetzt.

Java:
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.widget.TextView;

import android.util.Log;

public class CellActivity extends Activity {
	
	public static final String LOG_TAG = "DroidNova";

 public class OpenCellID {
  String mcc;  //Mobile Country Code
  String mnc;  //mobile network code
  String cellid; //Cell ID
  String lac;  //Location Area Code
  
  Boolean error;
  String strURLSent;
  String GetOpenCellID_fullresult;
  
  String latitude;
  String longitude;
  
  public Boolean isError(){
   return error;
  }
  
  public void setMcc(String value){
   mcc = value;
  }
  
  public void setMnc(String value){
   mnc = value;
  }
  
  public void setCallID(int value){
   cellid = String.valueOf(value);
  }
  
  public void setCallLac(int value){
   lac = String.valueOf(value);
  }
  
  public String getLocation(){
   return(latitude + " : " + longitude);
  }
  
  public void groupURLSent(){
   strURLSent =
    "http://www.opencellid.org/cell/get?mcc=" + mcc
    +"&mnc=" + mnc
    +"&cellid=" + cellid
    +"&lac=" + lac
    +"&fmt=txt";
  }
  
  public String getstrURLSent(){
   return strURLSent;
  }
  
  public String getGetOpenCellID_fullresult(){
   return GetOpenCellID_fullresult;
  }
  
  public void GetOpenCellID() throws Exception {
   groupURLSent();
   HttpClient client = new DefaultHttpClient();
   HttpGet request = new HttpGet(strURLSent);
   HttpResponse response = client.execute(request);
   GetOpenCellID_fullresult = EntityUtils.toString(response.getEntity()); 
   spliteResult();
  }
  
  private void spliteResult(){
   if(GetOpenCellID_fullresult.equalsIgnoreCase("err")){
    error = true;
   }else{
    error = false;
    String[] tResult = GetOpenCellID_fullresult.split(",");
    latitude = tResult[0];
    longitude = tResult[1];
   }
    
   
  }
 }

 int myLatitude, myLongitude;
 OpenCellID openCellID;

 
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       
       int mInt = 0;
       Log.v(LOG_TAG, "mint Value:" + mInt);
       
       TextView textGsmCellLocation = (TextView)findViewById(R.id.gsmcelllocation);
       TextView textMCC = (TextView)findViewById(R.id.mcc);
       TextView textMNC = (TextView)findViewById(R.id.mnc);
       TextView textCID = (TextView)findViewById(R.id.cid);
       TextView textLAC = (TextView)findViewById(R.id.lac);
       TextView textGeo = (TextView)findViewById(R.id.geo);
       TextView textRemark = (TextView)findViewById(R.id.remark);
      
       //retrieve a reference to an instance of TelephonyManager
       TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
       GsmCellLocation cellLocation = (GsmCellLocation)telephonyManager.getCellLocation();
      
       if (cellLocation instanceof GsmCellLocation){
       
    	   String networkOperator = telephonyManager.getNetworkOperator();
    	   String mcc = networkOperator.substring(0, 3);
    	   String mnc = networkOperator.substring(3);
    	   textMCC.setText("mcc: " + mcc);
    	   textMNC.setText("mnc: " + mnc);
      
    	   int cid = cellLocation.getCid();
    	   int lac = cellLocation.getLac();
    	   textGsmCellLocation.setText(cellLocation.toString());
    	   textCID.setText("gsm cell id: " + String.valueOf(cid));
    	   textLAC.setText("gsm location area code: " + String.valueOf(lac));
      
       
       
       
    	   openCellID = new OpenCellID();
      
    	   openCellID.setMcc(mcc);
    	   openCellID.setMnc(mnc);
    	   openCellID.setCallID(cid);
    	   openCellID.setCallLac(lac);
    	   try {
    		   openCellID.GetOpenCellID();
   
    		   if(!openCellID.isError()){
    			   textGeo.setText(openCellID.getLocation());
    			   textRemark.setText( "\n\n"
    				   + "URL sent: \n" + openCellID.getstrURLSent() + "\n\n"
    				   + "response: \n" + openCellID.GetOpenCellID_fullresult);
    		   }else{
    			   textGeo.setText("Error");
    		   }
    	   } 
    	   catch (Exception e) {
    		   // TODO Auto-generated catch block
    		   e.printStackTrace();
    		   textGeo.setText("Exception: " + e.toString());
    	   }
       
       }   
   }
}

Quelle: Android Coding: Get location of Cell ID, from opencellid.org using HttpGet().

Hab aus Interesse an der Android Api die Clients nicht von dort genommen...

Vielen Dank nochmal für die Hilfe.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W Prüfen, ob App auf Gerät installiert ist Problem S10 Android & Cross-Platform Mobile Apps 11
W In App Purchase Problem? Android & Cross-Platform Mobile Apps 36
W Problem mit Android Studio Android & Cross-Platform Mobile Apps 0
T Android R.string.test+i Problem Android & Cross-Platform Mobile Apps 2
K Android to Pi | Websocket Problem Android & Cross-Platform Mobile Apps 3
N Intent und finish() Problem Android & Cross-Platform Mobile Apps 5
B Android App Programmierung Einsteiger Problem Android & Cross-Platform Mobile Apps 4
emeraldo Android Problem mit Bottomnavmenu Android & Cross-Platform Mobile Apps 10
I Das Problem mit der Tastatur... android:windowSoftInputMode="adjustPan" Android & Cross-Platform Mobile Apps 1
M Android App → Problem mit dem Speichern von einem Bitmap–Objekt. Android & Cross-Platform Mobile Apps 1
A Android Android Studio Emulator Problem Android & Cross-Platform Mobile Apps 1
S Android Studio Bluetooth App Problem Android & Cross-Platform Mobile Apps 6
J TicTacToe Problem bei kontrolle Android & Cross-Platform Mobile Apps 7
J Button array ID Problem Android & Cross-Platform Mobile Apps 2
M Problem bei Werteübergabe, MSQL verbindung Android & Cross-Platform Mobile Apps 3
S Android Problem mit Android Virtual Device erstellung. Android & Cross-Platform Mobile Apps 2
Anfänger2011 Text to Speech Problem Android & Cross-Platform Mobile Apps 1
S Android Android java onclick listener Problem Android & Cross-Platform Mobile Apps 9
A Android Problem mit ListView und OnItemClickListener.. Android & Cross-Platform Mobile Apps 10
K Problem mit arraylist und button Android & Cross-Platform Mobile Apps 16
R W-Lan Problem über Sockets Android & Cross-Platform Mobile Apps 1
P ViewPager Problem Android & Cross-Platform Mobile Apps 1
A Android Problem mit Video von Youtube abspielen Android & Cross-Platform Mobile Apps 4
A Android Problem mit Zurücktaste und ausgabe der Aktuellen Seite Android & Cross-Platform Mobile Apps 6
B Android Problem mit Soundwiedergabe Android & Cross-Platform Mobile Apps 2
T Android Android Sensor: Java Problem Android & Cross-Platform Mobile Apps 1
G Problem beim Rendern von 3D-Objekt Android & Cross-Platform Mobile Apps 0
L Android Gyroscope Sensor Problem Android & Cross-Platform Mobile Apps 2
S Android GPS Problem Android & Cross-Platform Mobile Apps 24
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 1
J Eclipse Emulator Problem Android & Cross-Platform Mobile Apps 0
B Android Problem mit Rückgabewert Android & Cross-Platform Mobile Apps 13
L Android komisches Bitmap-Größe-Problem Android & Cross-Platform Mobile Apps 8
D Android Layout Problem Android & Cross-Platform Mobile Apps 2
R Problem mit View in ScrollView Android & Cross-Platform Mobile Apps 6
R Eclipse + AndroidSDK - Problem mit Referenzen Android & Cross-Platform Mobile Apps 6
M Problem mit setOnClickListener Android & Cross-Platform Mobile Apps 4
DaniSahne96 Problem beim Appdebuggen auf Smartphone Android & Cross-Platform Mobile Apps 3
P Android Problem beim Widget - Denkfehler ? Android & Cross-Platform Mobile Apps 2
M GCM IntentService Problem Android & Cross-Platform Mobile Apps 3
D Android Gallery Problem Android & Cross-Platform Mobile Apps 5
L Android Problem mit "spinner" Android & Cross-Platform Mobile Apps 10
D Android problem mit geschwindigkeitsberechnung app Android & Cross-Platform Mobile Apps 2
E Android Problem mit Contact Provider Android & Cross-Platform Mobile Apps 1
H Android Problem mit ListActivity Android & Cross-Platform Mobile Apps 3
S Android Layout Problem mit fill_parent Android & Cross-Platform Mobile Apps 5
F Android ExpandableList, SimpleCursorTreeAdapter, Cursor Problem Android & Cross-Platform Mobile Apps 2
A Android Problem mit Long.getLong() bzw. Integer.getInteger() Android & Cross-Platform Mobile Apps 2
A Problem mit HTTP- Verbindung Android & Cross-Platform Mobile Apps 4
V [Java] und [JavaME] ClientServer StreamConnection . Problem beim lesen / schreiben Android & Cross-Platform Mobile Apps 2
F Eclipse JAD File erzeugen -- Problem Android & Cross-Platform Mobile Apps 10
R Ein Problem beim ausführen von folgendem Quelltext Android & Cross-Platform Mobile Apps 11
M Problem mit dem Auslesen von System Properties Android & Cross-Platform Mobile Apps 7
P wtk problem Android & Cross-Platform Mobile Apps 3
G Math exp() Problem Android & Cross-Platform Mobile Apps 4
G S40 Problem Android & Cross-Platform Mobile Apps 8
A Problem beim Subtrahieren eines Double von einem Double Android & Cross-Platform Mobile Apps 5
C Problem Device/Emulator wird nicht erkannt Android & Cross-Platform Mobile Apps 3
S Image Problem Android & Cross-Platform Mobile Apps 11
M Problem mit den Softkeys Android & Cross-Platform Mobile Apps 4
G J2ME jar-problem Android & Cross-Platform Mobile Apps 10
S Komisches Problem Android & Cross-Platform Mobile Apps 3
F Problem beim Erstellen der Jar File Android & Cross-Platform Mobile Apps 4
A Problem: Canvas-Grösse Motorola RAZR v3r Android & Cross-Platform Mobile Apps 8
S Problem mit Einbindung einer externer Bibliothek Android & Cross-Platform Mobile Apps 2
G Random - Problem Android & Cross-Platform Mobile Apps 5
E problem mit den resourcen Android & Cross-Platform Mobile Apps 2
O Problem mit Datagramconnection Android & Cross-Platform Mobile Apps 2
P Problem mit der Uhrzeit Android & Cross-Platform Mobile Apps 2
S Problem auf dem Handy Android & Cross-Platform Mobile Apps 3
B Android Erkennen von Cell-Towers (RF-Track) Android & Cross-Platform Mobile Apps 0

Ähnliche Java Themen

Neue Themen


Oben