Play sound on Android

Motivation When writing app you sometimes want to play some sounds e.g. for notifications. In Android this can be accomplished by using the SoundPool class. Resource files Resource files e.g. your wav shall be placed under app\src\main\res\raw Code snippet This is a working example for playing short sound files. If you want to make a…

Android: Fix Unauthorized Devices on macOS

Disconnect USB connection between Mac/MacBook and Android device On the device: Revoke USB debugging authorization in Settings -> Developer Options cd /Users/<user_name>/Library/Android/sdk/platform-tools ./adb kill-server cd ~/.android/ rm -rf adbkey  Reconnect device Re-authorize computer to device cd /Users/<user_name>/Library/Android/sdk/platform-tools check with ./adb devices that device is authorized

Android Asynchronous Http Client

Motivation In Android it is highly inadvisable to do heavy lifting in the UI thread. When you even try to do some networking stuff like fetching images from a web server you might get an android.os.NetworkOnMainThreadException I’ve also written about it here To work around this issue you can use a third party library like…

New Blog Post

Getting Location Info in Android

Manifest <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” /> Activity   public static final int REQUEST_CODE = 123; LocationManager mLocationManager; LocationListener mLocationListener; @Override protected void onResume(){ super.onResume(); getCurrentLocation(); } private void getCurrentLocation() { Log.d(“Clima”, “getWeatherForCurrentLocation”); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mLocationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { Log.d(“Clima”, “onLocationChanged”); String longitude = String.valueOf(location.getLongitude()); String latitude = String.valueOf(location.getLatitude());…

New Blog Post

Passing data between AndroidActivities

Sending data private void openVideoActivity(String video) { Intent newActivity = new Intent(this, PlayerActivity.class); newActivity.putExtra(“videoId”, video); startActivity(newActivity); } Retrieving data final String videoID = getIntent().getExtras().getString(“videoID”);   In Kotlin it looks like this: val intent = Intent(this, NewActivity::class.java).apply { putExtra(“EXTRA_MESSAGE”, “Test 123”) } startActivity(intent) Retrieving val message = intent.getStringExtra(“EXTRA_MESSAGE”) Further Reading Passing data between fragments using SafeArgs…