Coding a mobile app directly in Android Studio can seem complicated for several reasons: 1. Steep Learning Curve 2. Complex Project Structure 3. UI Development Challenges 4. Device & OS Fragmentation 5. Emulator & Debugging Issues 6. Permissions & Security 7. Updating SDKs & Dependencies Easier Alternatives? If native Android development feels overwhelming, you can…
Category: Android
Save Android Webview Content as PDF File
Hello everybody! What you are seeing here is an Android app that shows a local html file inside a Web View. Then on top of the web view there is a button to save web view contents as a pdf file. Pdf file is saved localy after you tapped the button and you can open…
Adding html file inside assets folder (Creating HTML5 Android WebApp)
Now we are ready to add our html file inside assets folder. Create a folder named assets and put your html file there. Then build the app. You will see your app is running displaying that html page. This code is for html sample page used in this tutorial:
Edit the MainActivity.java file (Creating HTML5 Android WebApp)
The next step is to edit MainActivity.java file. Copy and paste this code to your MainActivity, but remember keep your package name unchanged, my package name is “com.thirteenov.lightweightnotetaker” so you must your own package name as it is your unique app identifier.
Adding the WebView to activity_main.xml in Android Studio (Creating HTML5 Android WebApp)
The next step is to add WebView to your layout file in Android Studio. Delete everything in your layout before adding WebView. Then after you drag and drop the WebView, you need to make it full screen. Make sure you set the constraint correctly and set the layout-width and layout-height to match constraint. Give it…
Creating New Android Project (Creating HTML5 Android WebApp)
As usual, to create a new project of anything, in this case Android project, we just need to follow the dialog wizard. I named this project LightWeight NoteTaker, a light weight html5 note taking app. The package name of this app is “com.thirteenov.lightweightnotetaker” . So basically we need that package name as a unique identifier…
Let’s create an HTML5 based Android web app
Hi, I’m going to start creating an HTML5 based Android web app. I’ve just Installed Android Studio and it’s getting ready now (it’s currently downloading some updates before I can use it). So basically, the idea behind creating Android WebApp is to have a WebView in the app and we create everything (the content) inside…
How to check is the device connected to internet or not in Android
With this simple snippet, we can check is the device is connected to internet or not: private boolean isConnected(){ ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); } So this “isConnected()” returns true if it’s connected, otherwise it returns false.
Listing image files in a directory and populate a ListView from it in Android
I have a directory in sdcard called “mydir” and there are lot of .png image files with another files. Then I want to list only that .png files and populate a ListView from it. I do it like this: String path = “/sdcard/mydir”; File directory = new File(path); if (!directory.exists()){ directory.mkdir(); } File[] files =…
Simple clickable Android ListView example
Follow this short tutorial to create a ListView in Android. First let’s create the list view element in our layout file: <ListView android:id=”@+id/lblistview” android:layout_width=”match_parent” android:layout_height=”match_parent” android:layout_marginBottom=”8dp” android:layout_marginEnd=”8dp” android:layout_marginStart=”8dp” android:layout_marginTop=”8dp” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” /> Then in your Java file: lblist = (ListView)findViewById(R.id.lblistview); String[] items = new String[3]; items[0] = “First item”; items[1] = “Second item”;…
JSON to Object and Array in Java
Try this snippet to convert JSON text into object and/or array in Java: JSONObject object = new JSONObject(jsontext); JSONArray array = jsonObj.getJSONArray(“somearray”); for (int i = 0; i < somearray.length(); i++) { JSONObject item = somearray.getJSONObject(i); String somevalue = item.getString(“somekey”); } jsontext is your JSON text.
Listing all files in a directory in Android
Let’s say we have a directory in device’s storage called “mydir” and there are files inside it. By using this snippet we can list all names of that files and folders: String path = Environment.getExternalStorageDirectory().getAbsolutePath() + “/maktabamajaziya”; String downloadedbooks = “”; File directory = new File(path); File[] files = directory.listFiles(); for (int i = 0;…
Requesting permission in run time in Android
If we are making an app for Android greater than SDK 23, we need to request some sensitive permissions (for example, to write file in external storage) in run time. Here is a snippet to do so: if (Build.VERSION.SDK_INT >= 23) { if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { } else { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); }…
If a folder (directory) is not existed, create it – Android Java Snippet
With this snippet, we are able to check if a folder existed in device’s storage or not. If not, then we create it. Here is the snippet: File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + “/afolder”); if (! directory.exists()){ directory.mkdir(); }
Picking an Image and Taking Photo in Android – Java source code
This is Java source code for Android, providing you with two functions: to take a photo using camera and to pick an image from gallery.
Getting user’s latitude and longitude in Android – Java source code
In this example, user’s device is showing it’s current latitude and longitude every 5 seconds. Coordinates are displayed inside Android Toast.
Pick an Image from Android device and upload it to server using PHP
To upload an image from Android device to online server using PHP, first we need to create a PHP script to handle “post” request and store the image to a folder. So write this simple script on your server:
How to make Android’s WebView opens a link inside or outside current app?
Initially if we use a WebView in our Android app, if there is a link and we click it, an intent manager is being called and asking how do we want to open that link. But we can manage it to open that link inside current that WebView or regular web browser.
Custom error page for Android’s WebView
When you develop Android Web App, you may want to show loading bar or anything when the web view is still loading a page, so your web app looks nice.
Pick an image from Android gallery and load it on ImageView & Webview together
I’m developing an app that the user should choose an image from Android gallery and then automatically loaded into Android ImageView and WebView together.