Skip to main content

Posts

All about Android extension libraries (AndroidX)

Nowadays we commonly get this type of error in gradle when we use third party library : Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0-rc02] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0-rc01] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override. we get this types of error when library is updated and providing use of AndroidX but we are using old one. To solve this error we have to migrate our project into AndroidX .if you still don't want to use AndroidX use have to do lots of stuff and also downgrade your googlePlayServices and firebase version. So in this Article we will discuss about what is AndroidX, How to Migrate to AndroidX and when ...

Connection type HTTP not supported in Android Pie(9)

Sometimes we face the error that same application which support http not working in some mobile devices specially in android pie and above devices and even some websites not showing in WebView with http connection type url . The error is something like this: Exception: IOException java.io.IOException: Cleartext HTTP traffic to * not permitted and same error in Web View like: so in this post we will learn about how to solve this problem and make our app support for all devices. So lets start - As per the Android Documentation  From Android 9 Pie now, requests without encryption will never work. And by default, the System will expect you to use TLS by default. Starting with Android 9 (API level 28), cleartext support is disabled by default. Android 9 adds built-in support for DNS over TLS, automatically upgrading DNS queries to TLS if a network's DNS server supports it. so from android pie we can say that the default http is not supported and by default connecti...

How to Create Image Slider with Page Indicator

Image slider are used in almost every Android Application .In this post we will Learn about Creating Image Slider with page Indicator.So lets start with Coding part:- First of all we need to add this library in our build.gradle file compile 'com.squareup.picasso:picasso:2.3.3' Step 1: activity_main.xml <RelativeLayout android:layout_width="match_parent" android:layout_height="200dp"> <android.support.v4.view.ViewPager android:id="@+id/vp_slider" android:layout_width="match_parent" android:layout_height="match_parent" /> <LinearLayout android:id="@+id/ll_dots" android:layout_width="match_parent" android:layout_height="30dp" android:layout_alignParentBottom="true" android:layout_marginBottom="20dp" android:gravity="center" android:orientation="horizontal"></LinearLayout> </Rel...

How to Download Apk file from Url and Install Programmatically

In this post we learn about download apk file from server or website and then install it Programmatically in Phone. Sometimes we have to download external apk file from server and then install if downloading successfully finished.For this we use AsyncTask class  for background process. So here is Code Snippet for this task.Lets Start :- Before this we have to add these Permissions in Manifest.xml file : <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> DownloadNewVersion.java class DownloadNewVersion extends AsyncTask<String,Integer,Boolean> { @Override protected void onPreExecute() { super.onPreExecute(); bar = new ProgressDialog(getActivity()); bar.setCancelable(false); bar.setMessage("Downl...

How to Take Screenshot of Current activity and Share Options

Sometimes we have to share the Report or Final receipt Screen  from the Current Application  .In this scenario we take screenshot of Current activity and then share this as image file using sharing Options . So lets move to the Coding Part without wasting time . 1: public class MainActivity extends AppCompatActivity { 2: File imagePath; 3: @Override 4: protected void onCreate(Bundle savedInstanceState) { 5: super.onCreate(savedInstanceState); 6: setContentView(R.layout.activity_main); 7: getSupportActionBar().setDisplayHomeAsUpEnabled(true); 8: ImageView imageView=(ImageView)findViewById(R.id.share); 9: imageView.setOnClickListener(new View.OnClickListener() { 10: @Override 11: public void onClick(View v) { 12: Bitmap bitmap = takeScreenshot(); 13: saveBitmap(bitmap); 14: shareIt(); 15: } 16: }); 17: } 18: public Bitmap takeScreenshot(...

Android Multi Select Dialog Box

Making Multi Select Dialog box is Pretty Simple and it can be achieved by few lines of coding . So lets move to the Coding Part . Steps: 1.    Create an String Array named "items" 2.   Initialize ArrayList itemsSelected and add if item is selected or remove if not selected . 3.   Get values of selected Items in itemsSelected and use it where ever you want . 1: import android.app.AlertDialog; 2: import android.app.Dialog; 3: import android.content.DialogInterface; 4: import android.os.Bundle; 5: import android.support.v7.app.ActionBarActivity; 6: import java.util.ArrayList; 7: public class MainActivity extends ActionBarActivity { 8: @Override 9: protected void onCreate(Bundle savedInstanceState) { 10: super.onCreate(savedInstanceState); 11: setContentView(R.layout.activity_main); 12: Dialog dialog; 13: final String[] items = {" C", " JAVA", " Kotlin", " Python", ...

How to Find specific App Installed in Mobile or Not

In Android sometimes we have to determine that the Specific app is installed in mobile or Not .So here is Code snippet to find the specific package name application installed or not . public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Add respective layout setContentView(R.layout.main_activity); // Use package name which we want to check boolean isAppInstalled = appInstalledOrNot("com.check.application"); // App package here if(isAppInstalled) { //This intent will help you to launch if the package is already installed Intent LaunchIntent = getPackageManager() .getLaunchIntentForPackage("com.check.application"); startActivity(LaunchIntent); Log.i("Application is already installed."); } else { // Do whatever we want to do if applicatio...

how to parse XML Programmatically in Android

In Android some times we have to parse XML data to use in Application .So here the example for Parsing the XML data . Step 1: Create XMLParser.java Class and paste the code like :- import android.util.Log; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import java.io.IOException; import java.io.StringReader; import java.io.UnsupportedEncodingException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; public class XMLPa...

Auto Close Dialog Using Timer In Android

Here i will show you how to use auto close dialog after a particular time using timer class in android .So lets start with coding part :- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Auto-closing Dialog"); builder.setMessage("After 7 second, this dialog will be closed automatically!"); builder.setCancelable(true); final AlertDialog dlg = builder.create(); dlg.show(); final Timer t = new Timer(); t.schedule(new TimerTask() { public void run() { dlg.dismiss(); // when the task active then close the dialog t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report } }, 7000); // after 7 second (or 7000 miliseconds), the task will be active.                 

How to use SQLite Database to perform database operations in Android

We all know that the SQLite is use in Android to Local Storage .SQLite is an opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. Lets Understand this using Code Snippets :- First Create a Class named DatabaseHelper.Java  which extends SQLiteOpenHelper Class  public class DatabaseHelper extends SQLiteOpenHelper { public static final String DB_NAME = "AnyNameDB"; public static final String TABLE_NAME = "Key"; public static final String COLUMN_ID = "id"; public static final String COLUMN_NAME ="keyword"; public static final String COLUMN_ADD = "url"; private static final int DB_VERSION = 1; public DatabaseHelper(Context context) { super(context,DB_NAME,null,DB_VERSION); } @Override public void onCreate(SQLiteDatabase db) { String sql =...