PopupWindow $BadTokenException: Unable to add window — token null is not valid

Same problem happened with me when I try to show a popup menu in an activity. I also got the same exception but I encountered problems and resolved it by providing the right context. // at this line Dialog dialog = new Dialog(getApplicationContext()); Use YourActivityName.this instead of getApplicationContext() and yes it worked for me may … Read more

Flutter: Gradle build failed to produce an .apk file. It’s likely that this file was generated under \build, but the tool couldn’t find it

in my case I have a multi flavor app like this: update 04/15/2021: { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 “version”: “0.2.0”, “configurations”: [ { “name”: “YOUR_PROJECT_NAME”, “program”: “lib/main.dart”, “request”: “launch”, “type”: “dart”, “args”: [ “–flavor”, “ADD_YOUR_FLAVOR_NAME_HERE” //development or … Read more

Failed to load libGL.so on Android

I have the Android SDK installed into ~/android-sdk-linux_x86, so I did: ln -s /usr/lib/libGL.so.1 ~/android-sdk-linux_x86/tools/lib/libGL.so This solves errors just like linking to /usr/lib does, but it doesn’t require root and doesn’t mess with core system directories.

Get SSID when WIFI is connected

I listen for WifiManager.NETWORK_STATE_CHANGED_ACTION in a broadcast receiver if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { NetworkInfo netInfo = intent.getParcelableExtra (WifiManager.EXTRA_NETWORK_INFO); if (ConnectivityManager.TYPE_WIFI == netInfo.getType ()) { … } } I check for netInfo.isConnected(). Then I am able to use WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifiManager.getConnectionInfo(); String ssid = info.getSSID(); UPDATE From android 8.0 onwards we wont … Read more

How to set Id of dynamic created layout?

You create an ids.xml file and place all your required ids in it as below <?xml version=”1.0″ encoding=”utf-8″?> <resources> <item type=”id” name=”layout1″ /> <item type=”id” name=”layout2″ /> <item type=”id” name=”layout3″ /> </resources> Now for your dynamically created layouts or views you can use these ids as below new_layout1.setId(R.id.layout1); new_view2.setId(R.id.layout2); new_layout3.setId(R.id.layout3); I hope it may help … Read more

How to add a Dropdown item on the action bar

First option: menu/options.xml: <item android:icon=”@drawable/ic_menu_sort” android:showAsAction=”ifRoom”> <menu> <item android:id=”@+id/menuSortNewest” android:title=”Sort by newest” /> <item android:id=”@+id/menuSortRating” android:title=”Sort by rating” /> </menu> </item> Second option: menu/options.xml: <menu xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:id=”@+id/menuSort” android:showAsAction=”ifRoom” android:actionLayout=”@layout/action_sort” /> </menu> layout/action_sort.xml: <Spinner xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@drawable/ic_menu_refresh” android:entries=”@array/order” /> Docs for menu resources – http://developer.android.com/guide/topics/resources/menu-resource.html