so, ich habs nun doch allein geschafft
eigentlich hab ich nicht groß was geändert, und es wundert micht, warum es plötzlich funktioniert, aber solange es geht ist mir das egal ![]()
hier der funktionierende code, falls es irgendjemanden interessiert:
Code
package de.toolcreator.WindowsRemoteControl;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.widget.EditText;
import de.toolcreator.WindowsRemoteControl.ControlPage;
public class Startseite extends Activity {
private NetworkService.NetworkServiceBinder mNetworkServiceBinder;
private ServiceConnection mNetworkServiceConnection =
new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder binder){
mNetworkServiceBinder = (NetworkService.NetworkServiceBinder) binder;
}
public void onServiceDisconnected(ComponentName className){}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Intent networkServiceIntent = new Intent(this, NetworkService.class);
bindService(networkServiceIntent, mNetworkServiceConnection, Context.BIND_AUTO_CREATE);
}
@Override
public void onResume(){
super.onResume();
final Intent networkServiceIntent = new Intent(this, NetworkService.class);
bindService(networkServiceIntent, mNetworkServiceConnection, Context.BIND_AUTO_CREATE);
}
@Override
public void onPause(){
super.onPause();
unbindService(mNetworkServiceConnection);
}
private boolean isIp(String str){
int anzPunkte = 0;
char[] charStr = str.toCharArray();
for(int i = 0; i < str.length(); i++){
if( charStr[i] == '.')
anzPunkte++;
}
if(anzPunkte == 3){
String[] strParts = str.split("\\.");
for(int i = 0; i < 4; i++){
try{
if (!((Integer.parseInt(strParts[i]) < 255)))
return false;
}
catch(Exception e){
return false;
}
}
return true;
}
else{
return false;
}
}
private void isNoIp(){
AlertDialog noIpAlert = new AlertDialog.Builder(this).create();
noIpAlert.setTitle("keine IP");
noIpAlert.setMessage("Bitte tragen Sie eine IP-Adresse in das entsprechende Feld ein.");
noIpAlert.show();
}
public void onClickVerbinden(final View view){
final EditText ipAdressEingabe = (EditText) findViewById(R.id.ipAdressEingabe);
String text = ipAdressEingabe.getText().toString();
if (text.length() == 0){
isNoIp();
}
else if (isIp(text)){
mNetworkServiceBinder.ConnectToServer(text);
final Intent controlPageIntent = new Intent(this, ControlPage.class);
startActivity(controlPageIntent);
}
else isNoIp();
}
}
Alles anzeigen