Tapan Saini | Techbirds

Posted on: June 30, 2014 /

Categories: Mobile Applications

Hi Folks,

Refer this code for identifying your 2G network enabled or not.

int enabled = Settings.Secure.getInt(getContentResolver(), “preferred_network_mode”, -1); Log.d(“MYAPP”, “2G only enabled: ” + enabled); Where the “use only 2G networks” setting is specified as: 0 indicates the setting is disabled 1 indicates the setting is enabled -1 indicates the setting is not set (some devices?) How I discovered this? I gathered all the key/value pairs from Settings.Secure using the following: ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(Settings.Secure.CONTENT_URI, null, null, null, null); if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { Log.d(“MYAPP”, “cursor: ” + cursor.getString(0) + “, ” + cursor.getString(1) + “, ” + cursor.getString(2)); cursor.moveToNext(); } }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

int enabled = Settings.Secure.getInt(getContentResolver(),

        “preferred_network_mode”, -1);

Log.d(“MYAPP”, “2G only enabled: ” + enabled);

Where the “use only 2G networks” setting is specified as:

0 indicates the setting is disabled

1 indicates the setting is enabled

-1 indicates the setting is not set (some devices?)

How I discovered this? I gathered all the key/value pairs from Settings.Secure using the following:

ContentResolver cr = getContentResolver();

Cursor cursor = cr.query(Settings.Secure.CONTENT_URI, null, null, null, null);

if (cursor.moveToFirst()) {

    while (!cursor.isAfterLast()) {

        Log.d(“MYAPP”, “cursor: “

                + cursor.getString(0) + “, “

                + cursor.getString(1) + “, “

                + cursor.getString(2));

        cursor.moveToNext();

    }

}

Kind Regards,

Tapan Saini

(Android Developer)

82 total views, no views today

Posted on: June 30, 2014 /

Categories: Mobile Applications

Hi Folks,

TOday i will explain some common tasks that might be helpful while making android apps:

  • Call An Activity form Reciever

Intent i = new Intent(); i.setClassName(“com.example.gamedoc”, “com.example.gamedoc.OpenAppDialogActivity”); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |Intent.FLAG_ACTIVITY_NEW_TASK ); context.startActivity(i)

Intent i = new Intent();

        i.setClassName(“com.example.gamedoc”,

                “com.example.gamedoc.OpenAppDialogActivity”);

        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |Intent.FLAG_ACTIVITY_NEW_TASK );

        context.startActivity(i)

  • On Boot Completing, Starting a service:

public void startService() { try { if (intent == null) { intent = new Intent(Recieved_COntext, Teri_Service.class); } Calendar cal = Calendar.getInstance(); if (pIntent == null) { pIntent = PendingIntent.getService(mContext, 0, intent, 0); } if (alarms == null) { alarms = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); } alarms.setInexactRepeating(AlarmManager.RTC, cal.getTimeInMillis(), 400, pIntent); } catch (Exception e) { e.printStackTrace(); } }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

public void startService() {

        try {

            if (intent == null) {

                intent = new Intent(Recieved_COntext, Teri_Service.class);

            }

            Calendar cal = Calendar.getInstance();

            if (pIntent == null) {

                pIntent = PendingIntent.getService(mContext, 0,

                        intent, 0);

            }

            if (alarms == null) {

                alarms = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);

            }

            alarms.setInexactRepeating(AlarmManager.RTC, cal.getTimeInMillis(),

                    400, pIntent);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

Kind Regards,

Tapan Saini

(Android Developer)

80 total views, no views today

Posted on: June 30, 2014 /

Categories: Mobile Applications

Hi Folks,

Today , i will discuss some very common concepts that some developers think is just a theoretical concept and feel proud to have little practical knowledge, but this is very useful if one wants to be a good biggy developer.

Semaphores are just variables of integer king that  helps code to provide lock and release mechanism  to resources that on module will use at a particular time and protecting mishandling of resources. hence called resource management.

Many are scared of implementing the same concept in other technology and thinks that technologies are different form one to another but the concepts these technologies are lying are basically same. Use Semaphores to use in your threads handling so that one thread cannot interrupt other threads.

int MYSEMAPHORE = 0;    //LOCK

// do tour stuffs

MYSEMAPHORE = 1;       //UNLOCK

between o to 1 it will not allow other threads to use resources ans is a shared variable(s).

This concept is used to handle multi-threading. Use it on Android!! too…

Critical Section:  It is basically that code part that is shared and common interface of executing a code. It is an OS concept that if one process is executing its code that definitely using the CPU, Memory resources and in the mean time some other tasks come into play that wants to execute its part then it will not lock the resources that are occupied by others and  thats why one cannot  go into its critical section until required resources are free/available for use.

Android coders does go through these challenges when APIs Transits (recently being the 18 to 19) so instead of completely relying on OS one should take care the criticality of code by himself.

WHile(UNTIL RELEASE CONDITIONS COMES TRUE)

{   if(TASK FINISHED)

RELEASE LOCK = 0;

else

RELEASE LOCK = 1;

}

Concepts seems useful if one broaden his mind to see possibilities.

Kind Regards,

Tapan Saini

(Android Developer)

178 total views, no views today

Posted on: June 30, 2014 /

Categories: Mobile Applications

Hi Folks,

                    I am wirting this very blog to let my developer friends know the limitation of android devices in order to create a Quality apps. It has been noticed in my practice so far that while developing apps we normally forgets issues concerned with memory.

As  mobile devices are lack in resources and efficient coding must be done in order to avoid phone hangs, crashes !!.

Here i am postulating some tips  that one can use:

1. Restricting you app cache to maximum of 4mb is good practice although if you use the normal code that one can find on internet would clear the cache completely by emptying the cache folder of data/data/com.teri.app/cache. and then deleting it via code but its good practice to write your custom code for deleting the cache upto a specific point like upto 4mb otherwise clean.

2. As caches are used to make your app appear fast . cleaning it upto Omb  size will slow down the process. If we take the example of apple products , iphone etc they never let app die as there is no back press. it caches, store all apps in recents and if necessary it clears otherwise it opens up from recents. There memory releasing might not much issues but in android it will bring a nice usage statics.

3. Clearing recents Background process will be an add on if you are making an app that boosts the memory and performance.

4. Many such apps are there, like boost an open source and other apps that does this memory cleaning tasks.

Long story Short:

  • Clear caches of app
  • Kill Background processes.
  • clear memory at specific level, maintaining fixed size.

Yours,

Tapan Saini

(Android Developer)

37 total views, no views today

Posted on: June 30, 2014 /

Categories: Mobile Applications

Hi folks,
I am writing this to inform all developers who like to create facebook apps that url hitting on facebook must be unversioned because as per rules of facebook now one cannot have friends specific permissions oif used with version 2.0

Proper documentation is on developers.facebook.com.

34 total views, no views today