Posts

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     ...

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.isConn...

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)) {     ...

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...

Using TypeFace in Android

In android, when you using the custom fonts. You need to create the assets folder in the main, then paste your .ttf or .otf format fonts. Here some methods will be very useful for you, Set the typeface     public Typeface setTypeFace(Context context) {         Typeface typeface = Typeface.createFromAsset(context.getAssets(),                 "fonts/MyriadPro_Regular.otf");         return typeface;     } txt_username.setTypeface(setTypeFace(getActivity())); Like you can set the EditText, Spinner and other widgets. Using the spannable text view in android, Spannable span = new SpannableString("Hello Android, Have a great day!");         span.setSpan(new ForegroundColorSpan(Color.BLUE), 0, 13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);     span.setSpan(new ForegroundColorSpan(Color.RED), 13, 25, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);    ...