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...
Category: Android
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...
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...
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...
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...
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...
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...
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 =...
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...
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...
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) ==...
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...
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.
Using okhttp3 to send http request in Android
Just googling around and find useful Java library, okhttp3, to send http request in from Android app.