Skip to main content
se eliminaron 1049 caracteres en el cuerpo; se eliminaron 33 caracteres en el cuerpo
Origen Enlace
W1ll
  • 537
  • 2
  • 14

Aqui parte del logcat

2020-05-01 00:05:44.306 3384-3384/com.wrs.mygpslocal W/.wrs.mygpsloca: Unsupported class loader

2020-05-01 00:05:44.309 3384-3384/com.wrs.mygpslocal W/.wrs.mygpsloca: Skipping duplicate class check due to unsupported classloader 2020-05-01 00:05:44.837 3384-3384/com.wrs.mygpslocal W/Activity: Can request only one set of permissions at a time 2020-05-01 00:05:44.838 3384-3384/com.wrs.mygpslocal D/AndroidRuntime: Shutting down VM 2020-05-01 00:05:44.840 3384-3384/com.wrs.mygpslocal E/AndroidRuntime: FATAL EXCEPTION: main Process: com.wrs.mygpslocal, PID: 3384 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wrs.mygpslocal/com.wrs.mygpslocal.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3115) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3258) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)parte del logcat

Aqui parte del logcat

2020-05-01 00:05:44.306 3384-3384/com.wrs.mygpslocal W/.wrs.mygpsloca: Unsupported class loader

2020-05-01 00:05:44.309 3384-3384/com.wrs.mygpslocal W/.wrs.mygpsloca: Skipping duplicate class check due to unsupported classloader 2020-05-01 00:05:44.837 3384-3384/com.wrs.mygpslocal W/Activity: Can request only one set of permissions at a time 2020-05-01 00:05:44.838 3384-3384/com.wrs.mygpslocal D/AndroidRuntime: Shutting down VM 2020-05-01 00:05:44.840 3384-3384/com.wrs.mygpslocal E/AndroidRuntime: FATAL EXCEPTION: main Process: com.wrs.mygpslocal, PID: 3384 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wrs.mygpslocal/com.wrs.mygpslocal.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3115) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3258) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)

Aqui parte del logcat: parte del logcat

AquiAquí parte de los permisos en el manifest:

public class MainActivity extends AppCompatActivity {
 
TextView tvMensaje;
String mPhoneNumber;
 
private static final long MIN_TIME = 10000; // 10 segundos Minimo tiempo para updates en Milisegundos
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    tvMensaje = findViewById(R.id.tvMensaje);

    //**************************************************************************************************
    //*     Permission to Read PhoneNumber
    //**************************************************************************************************
    if (ActivityCompat.checkSelfPermission(this, READ_SMS) == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, READ_PHONE_NUMBERS)
            == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,READ_PHONE_STATE)
            == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager tMgr = (TelephonyManager)   this.getSystemService(Context.TELEPHONY_SERVICE);
        String mPhoneNumber = tMgr.getLine1Number();
        return;
    } else {
        requestPermission();
     }
 
    //******************************************************************************************
    //*     Permission to Read GPS
    //******************************************************************************************
    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
 
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);
 
    } else {
        iniciarLocalizacion();
    }
}

private void iniciarLocalizacion() {

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Localizacion local = new Localizacion();
    local.setMainActivity(this, tvMensaje, mPhoneNumber);
    final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    if(!gpsEnabled) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }

    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);
        return;
    }

    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, 0, local);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, 0, local);

    tvMensaje.setText("Inicializando GPS");
}

private void requestPermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestPermissions(new String[]{READ_SMS, READ_PHONE_NUMBERS, READ_PHONE_STATE}, 100);
    }
}
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 100:
            TelephonyManager tMgr = (TelephonyManager)  this.getSystemService(Context.TELEPHONY_SERVICE);
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,Manifest.permission.READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED  && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) !=      PackageManager.PERMISSION_GRANTED) {
                return;
            }
            String mPhoneNumber = tMgr.getLine1Number();
            Log.e( "DEBUG-->", "Nro: " + mPhoneNumber );
            break;

        case 1000:                                                  
            if(grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                iniciarLocalizacion();
                return;
            }
            break;
      }
   }
}

Aqui parte del logcat

2020-05-01 00:05:44.306 3384-3384/com.wrs.mygpslocal W/.wrs.mygpsloca: Unsupported class loader

2020-05-01 00:05:44.309 3384-3384/com.wrs.mygpslocal W/.wrs.mygpsloca: Skipping duplicate class check due to unsupported classloader 2020-05-01 00:05:44.837 3384-3384/com.wrs.mygpslocal W/Activity: Can request only one set of permissions at a time 2020-05-01 00:05:44.838 3384-3384/com.wrs.mygpslocal D/AndroidRuntime: Shutting down VM 2020-05-01 00:05:44.840 3384-3384/com.wrs.mygpslocal E/AndroidRuntime: FATAL EXCEPTION: main Process: com.wrs.mygpslocal, PID: 3384 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wrs.mygpslocal/com.wrs.mygpslocal.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3115) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3258) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)

Aqui parte de los permisos en el manifest:

public class MainActivity extends AppCompatActivity {
 
TextView tvMensaje;
String mPhoneNumber;
 
private static final long MIN_TIME = 10000; // 10 segundos Minimo tiempo para updates en Milisegundos
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tvMensaje = findViewById(R.id.tvMensaje);

    //**************************************************************************************************
    //*     Permission to Read PhoneNumber
    //**************************************************************************************************
    if (ActivityCompat.checkSelfPermission(this, READ_SMS) == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, READ_PHONE_NUMBERS)
            == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,READ_PHONE_STATE)
            == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager tMgr = (TelephonyManager)   this.getSystemService(Context.TELEPHONY_SERVICE);
        String mPhoneNumber = tMgr.getLine1Number();
        return;
    } else {
        requestPermission();
     }
 
    //******************************************************************************************
    //*     Permission to Read GPS
    //******************************************************************************************
    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
 
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);
 
    } else {
        iniciarLocalizacion();
    }
}

private void iniciarLocalizacion() {

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Localizacion local = new Localizacion();
    local.setMainActivity(this, tvMensaje, mPhoneNumber);
    final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    if(!gpsEnabled) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }

    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);
        return;
    }

    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, 0, local);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, 0, local);

    tvMensaje.setText("Inicializando GPS");
}

private void requestPermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestPermissions(new String[]{READ_SMS, READ_PHONE_NUMBERS, READ_PHONE_STATE}, 100);
    }
}
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 100:
            TelephonyManager tMgr = (TelephonyManager)  this.getSystemService(Context.TELEPHONY_SERVICE);
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,Manifest.permission.READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED  && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) !=      PackageManager.PERMISSION_GRANTED) {
                return;
            }
            String mPhoneNumber = tMgr.getLine1Number();
            Log.e( "DEBUG-->", "Nro: " + mPhoneNumber );
            break;

        case 1000:                                                  
            if(grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                iniciarLocalizacion();
                return;
            }
            break;
      }
   }
}

Aquí parte de los permisos en el manifest:

public class MainActivity extends AppCompatActivity {
TextView tvMensaje;
String mPhoneNumber;
private static final long MIN_TIME = 10000; // 10 segundos Minimo tiempo para updates en Milisegundos
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    tvMensaje = findViewById(R.id.tvMensaje);
    //*     Permission to Read PhoneNumber
    if (ActivityCompat.checkSelfPermission(this, READ_SMS) == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, READ_PHONE_NUMBERS)
            == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,READ_PHONE_STATE)
            == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager tMgr = (TelephonyManager)   this.getSystemService(Context.TELEPHONY_SERVICE);
        String mPhoneNumber = tMgr.getLine1Number();
        return;
    } else {
        requestPermission();
     }

    //*     Permission to Read GPS
    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);
    } else {
        iniciarLocalizacion();
    }
}

private void iniciarLocalizacion() {

    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);
        return;
    }

    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, 0, local);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, 0, local);

    tvMensaje.setText("Inicializando GPS");
}

private void requestPermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestPermissions(new String[]{READ_SMS, READ_PHONE_NUMBERS, READ_PHONE_STATE}, 100);
    }
}
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 100:
            TelephonyManager tMgr = (TelephonyManager)  this.getSystemService(Context.TELEPHONY_SERVICE);
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,Manifest.permission.READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED  && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) !=      PackageManager.PERMISSION_GRANTED) {
                return;
            }
            String mPhoneNumber = tMgr.getLine1Number();
            Log.e( "DEBUG-->", "Nro: " + mPhoneNumber );
            break;

        case 1000:
            if(grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                iniciarLocalizacion();
                return;
            }
            break;
      }
   }
}

Aqui parte del logcat

2020-05-01 00:05:44.306 3384-3384/com.wrs.mygpslocal W/.wrs.mygpsloca: Unsupported class loader

2020-05-01 00:05:44.309 3384-3384/com.wrs.mygpslocal W/.wrs.mygpsloca: Skipping duplicate class check due to unsupported classloader 2020-05-01 00:05:44.837 3384-3384/com.wrs.mygpslocal W/Activity: Can request only one set of permissions at a time 2020-05-01 00:05:44.838 3384-3384/com.wrs.mygpslocal D/AndroidRuntime: Shutting down VM 2020-05-01 00:05:44.840 3384-3384/com.wrs.mygpslocal E/AndroidRuntime: FATAL EXCEPTION: main Process: com.wrs.mygpslocal, PID: 3384 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wrs.mygpslocal/com.wrs.mygpslocal.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3115) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3258) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)

Origen Enlace
W1ll
  • 537
  • 2
  • 14

Conflicto entre permiso para leer gps y numero de telefono

Tengo un conflicto que ocasiona que mi dispositivo quede colgado cuando coloco ambos permisos para leer gps y nro de teléfono en una sola actividad, pero cuando pruebo los permisos en dos actividades diferentes todo funciona correctamente.

Aqui parte de los permisos en el manifest:

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

Aqui el MainActivity:

public class MainActivity extends AppCompatActivity {

TextView tvMensaje;
String mPhoneNumber;

private static final long MIN_TIME = 10000; // 10 segundos Minimo tiempo para updates en Milisegundos

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

    tvMensaje = findViewById(R.id.tvMensaje);

    //**************************************************************************************************
    //*     Permission to Read PhoneNumber
    //**************************************************************************************************
    if (ActivityCompat.checkSelfPermission(this, READ_SMS) == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, READ_PHONE_NUMBERS)
            == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,READ_PHONE_STATE)
            == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager tMgr = (TelephonyManager)   this.getSystemService(Context.TELEPHONY_SERVICE);
        String mPhoneNumber = tMgr.getLine1Number();
        return;
    } else {
        requestPermission();
     }

    //******************************************************************************************
    //*     Permission to Read GPS
    //******************************************************************************************
    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);

    } else {
        iniciarLocalizacion();
    }
}

private void iniciarLocalizacion() {

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Localizacion local = new Localizacion();
    local.setMainActivity(this, tvMensaje, mPhoneNumber);
    final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    if(!gpsEnabled) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }

    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, 1000);
        return;
    }

    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, 0, local);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, 0, local);

    tvMensaje.setText("Inicializando GPS");
}

private void requestPermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestPermissions(new String[]{READ_SMS, READ_PHONE_NUMBERS, READ_PHONE_STATE}, 100);
    }
}
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 100:
            TelephonyManager tMgr = (TelephonyManager)  this.getSystemService(Context.TELEPHONY_SERVICE);
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,Manifest.permission.READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED  && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) !=      PackageManager.PERMISSION_GRANTED) {
                return;
            }
            String mPhoneNumber = tMgr.getLine1Number();
            Log.e( "DEBUG-->", "Nro: " + mPhoneNumber );
            break;

        case 1000:                                                  
            if(grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                iniciarLocalizacion();
                return;
            }
            break;
      }
   }
}

Pueden decirme cual es mi error?