Posts

Showing posts from 2018

Show Password in EditText

Hi friends, Have a great day. I comeback after long time. Ok,  now will look up to show password option in edit text. Now most of login screens comes up with another cool feature, that's show password. User want to see their password, until they done editing. You can use it with checkbox option. It's simple, but you can make it by your way. @Override     public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {         if(!isChecked){             edit_password.setTransformationMethod(HideReturnsTransformationMethod.getInstance());         }else{             edit_password.setTransformationMethod(PasswordTransformationMethod.getInstance());         }     }

My Map Application

Few days before I created one app, It's a map application. It's not a great application, but simple application. To load the data from the web, data has too be listed, when you select or click particular user data, load the map with marker. I tried with my knowledge, but don't expect too much. But it will be useful for beginners and peoples who are trying the map at first time. Get from the my GITHUB

Store and Get the data from Cache in Android.

It's Interesting, most of peoples thinks about the database, shared preferences and content providers for offline data storage. Some different came like data must be stored in cache, when app offline, retrieve data from the cache. Just try this, It might be useful for you. public String temp_filename = "user_data.txt"; public File tempFile; // To Store the file in Cache public void storeToCache(Context context, String data) {         if (data != null && !data.equals("")) {             FileWriter writer;             try {                 writer = new FileWriter(getCacheFile(context));                 writer.write(data);                 writer.close();                 Log.d(TAG, "stored to cache");             } catch (IOException e) {                 e.printStackTrace();             }         } } // To Check the file is exist or not public boolean isCacheExist(Context context) {         boolean isExist;         isExist =

Validate the URL

Have a great day friends. Today will look up validating the URL. How to do this? Most of times, your internet will be working, but sometimes URL to be busy or invalid. In this case, we follow this thing.  public boolean isServerReachable(Context context, String url) {         ConnectivityManager connMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);         NetworkInfo netInfo = connMan.getActiveNetworkInfo();         if (netInfo != null && netInfo.isConnected()) {             try {                 URL urlServer = new URL(url);                 if(url.startsWith("https")){                     HttpsURLConnection urlConn = (HttpsURLConnection) urlServer.openConnection();                     TLSSocketFactory socketFactory = new TLSSocketFactory();                     urlConn.setSSLSocketFactory(socketFactory);                     urlConn.setConnectTimeout(3000); //<- 3Seconds Timeout                     urlConn.connect();

Send the data to one app to another app using intent and broadcast - Part 2

Previous post I explain about the sharing the data using broadcast. This post about to share the data using the intents. By using Intent In First Application Intent intent = new Intent(); intent.setClassName("com.sample.app", "com.sample.app.MainActivity"); intent.putExtra("EXTRA_ORDERID", "#4FGT784"); intent.putExtra("EXTRA_ORDERNOTES", "No warranty for this product"); intent.putExtra("EXTRA_ORDERAMOUNT", "270"); PackageManager packageManager = getPackageManager(); List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); boolean isIntentSafe = activities.size() > 0; if (isIntentSafe) { startActivity(intent); } else { Toast.makeText(MainActivity.this, "Application not installed", Toast.LENGTH_LONG).show(); } In Second Application Bundle vals = getIntent().getExtras(); if (vals != null) { String orderId = vals.getS

Send the data to one app to another app using intent and broadcast - Part 1

Hi Friends, Have a great day. It's my 75th blog. I'm very slow, but I'm post only necessary and important posts only, hope so. This time we'll look some manual broadcast message sending from another application, best way to for testing the notifications. By Using send broadcast. In First Application ComponentName componentName = new ComponentName("com.sample.app", "com.sample.app.receiver.NotificationReceiver"); Intent intent = new Intent(); intent.setComponent(componentName); String message = "Order ID:  #AER46798 "; intent.putExtra("EXTRA_TITLE", "New Order Received"); intent.putExtra("EXTRA_MESSAGE", message); sendBroadcast(intent); In Second Application Receiver public class NotificationReceiver extends BroadcastReceiver {     public static String TAG = "PCM";     @Override     public void onReceive(Context context, Intent intent) {         Log.i(TAG, "message_received");

Patterns and Regular Expressions

In Java usually validate with some specific characters, we should use Regular Expressions. Same way in Android, here we use Patterns. More info about the Patterns: Click here In android EditText, we can use custom input filter to perform this. This is for maximum input digits before and after decimal pointer. CustomInputFilter.Java public class CustomInputFilter implements InputFilter {     int maxDigitsBeforeDecimalPoint;     int maxDigitsAfterDecimalPoint;     public CustomInputFilter(int maxDigitsBeforeDecimalPoint, int maxDigitsAfterDecimalPoint) {         this.maxDigitsBeforeDecimalPoint = maxDigitsBeforeDecimalPoint;         this.maxDigitsAfterDecimalPoint = maxDigitsAfterDecimalPoint;     }     @Override     public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {         StringBuilder builder = new StringBuilder(dest);         builder.replace(dstart, dend, source                 .subSequence(start, end).toStr

Webview Tricks and Tips

To enable back button should be not close the application and web pages navigation only,     @Override     public boolean onKeyDown(int keyCode, KeyEvent event) {         if (keyCode == KeyEvent.KEYCODE_BACK) {                webview.goBack();             return true;         }         return super.onKeyDown(keyCode, event);     } Webview settings:         WebSettings webSetting = sWebview.getSettings();         webSetting.setJavaScriptEnabled(true);         webSetting.setDisplayZoomControls(false);         //Set whether the DOM storage API is enabled.         webSetting.setDomStorageEnabled(true);         sWebview.setWebChromeClient(new WebChromeClient());         sWebview.setWebViewClient(new MyWebViewClient()); To interact between Java and Javascript: WebAppInterface.Java import android.app.Activity; import android.util.Log; import android.webkit.JavascriptInterface; import android.webkit.WebView; public class WebAppInterface {     Activity activity

Get the Local IP address of your device

Have a great day. Set the permission in Manifest.xml <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.INTERNET" /> Then just use below code:  public String getLocalIpAddress() {         String firstIP = "192.168.0.1";         ArrayList<String> ipList = new ArrayList<String>();         try {             for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {                 NetworkInterface intf = en.nextElement();                 for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {                     InetAddress inetAddress = enumIpAddr.nextElement();                     if (!inetAddress.isLoopbackAddress()) {                         Log.d(TAG, inetAddress.getHostAddress().toString());                         ipList.add(inetAdd

Check the service on several time gaps.

Now three... Hope this will be very useful for those who doing time intervals and web services. ServiceChecker.Java  import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class ServiceChecker extends BroadcastReceiver {     ShukranDbHelper dbHelper;     @Override     public void onReceive(Context context, Intent arg1) {         // Just calling your method Log.d("hey", "I'm alive");     } } In AndroidManifest.xml <receiver android:name=".service.DataChecker"></receiver> In your Activity, Just call this. Intent alarmIntent = new Intent(this, ServiceChecker.class); pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0); startAlarm(); public void startAlarm() {     manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);     int interval =600000; // 10 minute //10000     manager.setRepeating(AlarmManager.RTC_WAKEUP, System.current

Check Network Using BroadCastReceiver

Hello friends, Hope you already see this example in lot of websites and blogs. I'm also doing these, because hope my example might be easy and understandable. Let's go. Create the class: ConnectivityReceiver.Java public class ConnectivityReceiver extends BroadcastReceiver {     public static ConnectivityReceiverListener connectivityReceiverListener;     public ConnectivityReceiver() {         super();     }     @Override     public void onReceive(Context context, Intent arg1) {         ConnectivityManager cm = (ConnectivityManager) context                 .getSystemService(Context.CONNECTIVITY_SERVICE);         NetworkInfo activeNetwork = cm.getActiveNetworkInfo();         boolean isConnected = activeNetwork != null                 && activeNetwork.isConnectedOrConnecting();         if (connectivityReceiverListener != null) {             connectivityReceiverListener.onNetworkConnectionChanged(isConnected);         }     }     public static boole

Touch Events in Fragment

Hi friends, Have a great day. Today we're going to look for touch events in fragment. Taps - If you gonna multiple tap to view or do something, this will be more helpful. Just implement TouchListener in your fragment like this, public class FirstFragment extends Fragment implements View.OnTouchListener Then     @Override     public boolean onTouch(View v, MotionEvent event) {         int eventaction = event.getAction();         if (eventaction == MotionEvent.ACTION_UP) {             //get system current milliseconds             long time = System.currentTimeMillis();             //if it is the first time, or if it has been more than 3 seconds since the first tap ( so it is like a new try), we reset everything             if (startMillis == 0 || (time - startMillis > 3000)) {                 startMillis = time;                 count = 1;             }             //it is not the first, and it has been  less than 3 seconds since the first             else { // 

Add Application Name and Version Name in Generated APK

Hi Everyone, Have a great day. Happy Feb. How to add app name, version name in the generated apk?  - It's very interesting question asked by my junior developer. In app.gradle Under the android just add following line: project.archivesBaseName = "IndAppz"; more? add the version information: Put the following code under the buildTypes. applicationVariants.all { variant ->                 variant.outputs.each{ output ->                     output.outputFile = new File(output.outputFile.parent,output.outputFile.name.replace(".apk","-" + defaultConfig.versionName+".apk" ))                 }             } even more? add the app with date information: define the date: def getDate() {     new Date().format('ddMMMyyyy') } And then add the date info into the file name. applicationVariants.all { variant ->                 variant.outputs.each{ output ->                     output.outputFile = new File(out