Wednesday, December 3, 2014

Cycling || Recreation

  Since childhood I have liked cycling, but then it was just for the sake of playing. Lately I have developed inclination towards cycling and decided to take it more seriously. It all started when in my previous company we had this cycling company named cymour come with their bicycles and allow us to cycle for a while, I really liked the bicycles they had got and riding them was pleasure. Post the ride I felt that I should own one of a kind, and had decided to buy one.
    I started inquiring about different bicycle brands and evaluated the different models available, had restricted my budget to 7-8k. I made a list of bicycles that I liked as well in my budget. Unfortunately the models I had listed down turned out to be fancy ones (with dual shocks and dual disc brakes that can give up anytime) that are mostly used by kids, a friend of mine (a cycling enthusiast) explained to me that models I selected were not durable and highly unreliable for long run, and that I should go for bicycles with rigid frames (no shocks) and frame material must be made up of alloy not steel. Bicycles made of alloy frames are much lighter than others.
    Started my research all over again and now the budget had to be almost doubled, since the models that I was now looking for were expensive ones. First choice in my new list (I guess everyone's is) was Btwin Rockrider 5.0 which costs around 9k plus 1k for some important accessories (that are not a part of bicycle), despite the bicycle being great it did not appeal to me much. The bicycle had large frame but the handle was very low so I had to bend a lot and plus it did not have rapid gear shifters from shimano (which is must have).
   My next choice was Hercules Act 110, this ones from BSA an Indian manufacturer and I must say the looks really impressed me, the frame is made of alloy and has rapid gear shifters from shimano. I liked this one so much that unconsciously I had decided to buy it and did not like a single bike that I saw after this one. But the price was a major hindrance for me, the site quotes the price to be 16.5k which was way out of my league, after roaming around a few days I struck a great deal, the guy agreed to 13.2k without a single penny less. Although a bit expensive than what I had planned for a think I have made a prudent decision in the long run. I am really enjoying the ride to and fro home and office (just once a week for now :) ).

Happy Cycling!!!

Sunday, May 19, 2013

Managing Audio Focus - Android

Was just googling around how to manage the media player in an android application when a call or sms arrives, and stumbled upon this very interesting and important concept of managing audio focus...........

I have taken this directly from the documentation available at developer.android.com, as the explanation is very lucid out here.........thus saving me from the trouble of retyping it...:)

With multiple apps potentially playing audio it's important to think about how they should interact. To avoid every music app playing at the same time, Android uses audio focus to moderate audio playback—only apps that hold the audio focus should play audio.
Before your app starts playing audio it should request—and receive—the audio focus. Likewise, it should know how to listen for a loss of audio focus and respond appropriately when that happens.

Request the Audio Focus


Before your app starts playing any audio, it should hold the audio focus for the stream it will be using. This is done with a call to requestAudioFocus() which returns AUDIOFOCUS_REQUEST_GRANTED if your request is successful.
You must specify which stream you're using and whether you expect to require transient or permanent audio focus. Request transient focus when you expect to play audio for only a short time (for example when playing navigation instructions). Request permanent audio focus when you plan to play audio for the foreseeable future (for example, when playing music).
The following snippet requests permanent audio focus on the music audio stream. You should request the audio focus immediately before you begin playback, such as when the user presses play or the background music for the next game level begins.
AudioManager am = mContext.getSystemService(Context.AUDIO_SERVICE);
...
// Request audio focus for playback
int result = am.requestAudioFocus(afChangeListener,
                                 // Use the music stream.
                                 AudioManager.STREAM_MUSIC,
                                 // Request permanent focus.
                                 AudioManager.AUDIOFOCUS_GAIN);
   if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
    am.unregisterMediaButtonEventReceiver(RemoteControlReceiver);
    // Start playback.
}
 

Once you've finished playback be sure to call abandonAudioFocus(). This notifies the system that you no longer require focus and unregisters the associated AudioManager.OnAudioFocusChangeListener. In the case of abandoning transient focus, this allows any interupted app to continue playback.

// Abandon audio focus when playback complete am.abandonAudioFocus(afChangeListener);

When requesting transient audio focus you have an additional option: whether or not you want to enable "ducking." Normally, when a well-behaved audio app loses audio focus it immediately silences its playback. By requesting a transient audio focus that allows ducking you tell other audio apps that it’s acceptable for them to keep playing, provided they lower their volume until the focus returns to them.
// Request audio focus for playback
int result = am.requestAudioFocus(afChangeListener,
                     // Use the music stream.
                      AudioManager.STREAM_MUSIC,
                     // Request permanent focus.
                     AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
   if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
    // Start playback.
}
Ducking is particularly suitable for apps that use the audio stream intermittently, such as for audible driving directions.
Whenever another app requests audio focus as described above, its choice between permanent and transient (with or without support for ducking) audio focus is received by the listener you registered when requesting focus.

Handle the Loss of Audio Focus


If your app can request audio focus, it follows that it will in turn lose that focus when another app requests it. How your app responds to a loss of audio focus depends on the manner of that loss.
The onAudioFocusChange() callback method of they audio focus change listener you registered when requesting audio focus receives a parameter that describes the focus change event. Specifically, the possible focus loss events mirror the focus request types from the previous section—permanent loss, transient loss, and transient with ducking permitted.
Generally speaking, a transient (temporary) loss of audio focus should result in your app silencing it’s audio stream, but otherwise maintaining the same state. You should continue to monitor changes in audio focus and be prepared to resume playback where it was paused once you’ve regained the focus.
If the audio focus loss is permanent, it’s assumed that another application is now being used to listen to audio and your app should effectively end itself. In practical terms, that means stopping playback, removing media button listeners—allowing the new audio player to exclusively handle those events—and abandoning your audio focus. At that point, you would expect a user action (pressing play in your app) to be required before you resume playing audio.
In the following code snippet, we pause the playback or our media player object if the audio loss is transient and resume it when we have regained the focus. If the loss is permanent, it unregisters our media button event receiver and stops monitoring audio focus changes.

OnAudioFocusChangeListener afChangeListener = new OnAudioFocusChangeListener() {
    public void onAudioFocusChange(int focusChange) {
        if (focusChange == AUDIOFOCUS_LOSS_TRANSIENT
            // Pause playback
        } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
            // Resume playback 
        } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
            am.unregisterMediaButtonEventReceiver(RemoteControlReceiver);
            am.abandonAudioFocus(afChangeListener);
            // Stop playback
        }
    }
};
In the case of a transient loss of audio focus where ducking is permitted, rather than pausing playback, you can "duck" instead.

Duck!


Ducking is the process of lowering your audio stream output volume to make transient audio from another app easier to hear without totally disrupting the audio from your own application.
In the following code snippet lowers the volume on our media player object when we temporarily lose focus, then returns it to its previous level when we regain focus.
OnAudioFocusChangeListener afChangeListener = new OnAudioFocusChangeListener() {
    public void onAudioFocusChange(int focusChange) {
        if (focusChange == AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
            // Lower the volume
        } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
            // Raise it back to normal
        }
    }
};
A loss of audio focus is the most important broadcast to react to, but not the only one. The system broadcasts a number of intents to alert you to changes in user’s audio experience. The next lesson demonstrates how to monitor them to improve the user’s overall experience.


For more detailed explanation around Managing Audio Playback you can visit http://developer.android.com/training/managing-audio/audio-focus.html  

Android Studio

Getting Started with Android Studio ........ straight from developer.android.com

EARLY ACCESS PREVIEW

Android Studio is a new Android development environment based on IntelliJ IDEA. Similar to Eclipse with the ADT Plugin, Android Studio provides integrated Android developer tools for development and debugging. On top of the capabilities you expect from IntelliJ, Android Studio offers:
  • Gradle-based build support.
  • Android-specific refactoring and quick fixes.
  • Lint tools to catch performance, usability, version compatibility and other problems.
  • ProGuard and app-signing capabilities.
  • Template-based wizards to create common Android designs and components.
  • A rich layout editor that allows you to drag-and-drop UI components, preview layouts on multiple screen configurations, and much more.
Caution: Android Studio is currently available as anearly access preview. Several features are either incomplete or not yet implemented and you may encounter bugs. If you are not comfortable using an unfinished product, you may want to instead download (or continue to use) the ADT Bundle(Eclipse with the ADT Plugin).

For more information about Android Studio or to download the same visit http://developer.android.com/sdk/installing/studio.html 

Thursday, April 25, 2013

Install apk and uninstall an app via Intents

        Currently am working on a project that requires to build an Android application that will download another apps within itself and install the same. I call the main app as parent app and the apps that will be downloaded as child apps (just for simplicity...... :)). Also it is required that the child apps should not be visible to the user and should be used only via the parent app. Finally when the parent app is uninstalled; it is required that the child apps also be uninstalled.

        Initially I thought that the requirements mentioned above were not possible, but after a little bit of reading I came up with a solution.

              1) The first requirement of downloading and installing an app within another app can be achieved by simply downloading an apk (using http) and installing the apk when download finishes. Android does not authorize to install anything without users consent (unless device is rooted), only thing we can do is prompt the user to install the apk. The app will be installed successfully if user clicks 'Install'.

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri apkUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/Download/" + "app.apk")); 
intent.setDataAndType(apkUri, "application/vnd.android.package-archive"); startActivity(intent);

              2) For the child apps not be visible to user, I simply had to remove intent-filter of the launcher activity from the manifest file. When no launcher activity is present in an application, it does not have a launcher icon.



But in absence of a launcher activity how to launch an application?
Hence, to launch the actiivty we need to provide it a custom action and use it to launch the activity from the parent app.


To launch the above activity the intent call will be as below.

Intent intent = new Intent(); intent.setAction("com.temporary.nolauncher.action.NO_LAUNCHER"); startActivity(intent);

                 3) Finally for uninstalling the child apps when parent app is uninstalled, I had to register a receiver that would catch the event when any app is uninstalled. After the event is caught, I checked which app was uninstalled using the URI. If the parent app is uninstalled then the child app would prompt the user to uninstall itself. Again uninstall can't be achieved without user's consent (unless device is rooted).

The receiver has to be registered in manifest as follows. The action PACKAGE_REMOVED serves the purpose of catching the event when any anpp is uninstalled.


After the event of uinstalling any app is caught in the receiver, we can detect which app was uninstalled (using the intent). The intent returns the package name via the uri. 'intent' reference is avaible from the onReceive method in the receiver.

private String getPackageName(Intent intent) { 
      Uri uri = intent.getData(); 
      String pkg = uri != null ? uri.getSchemeSpecificPart() : null; 
      return pkg; 
}

Finally once the it is detected that the app uninstalled was the parent app then we can fire an intent that will prompt the user to uninstall the child app.

String packToUninstall = "com.temporary.nolauncher"; 
Uri packageURI = Uri.parse("package:" + packToUninstall); 
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,packageURI); uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(uninstallIntent);

 'ctx' reference is avaible from the onReceive method in the receiver.

Tuesday, October 9, 2012

USSD - Mobile Banking

USSD stands for Unstructured Supplementary Services Data 

Have you ever typed a code starting with an asterisk (*), number set, and hash (#) on your mobile?
If yes, then, knowingly or unknowingly, you have already been using USSD service. USSD is a communication protocol used to send text messages between a mobile phone and applications running on the network. It is a messaging service used in Global System for Mobile Communications (GSM) networks similar to SMS, where it sends data utilizing the signaling channel. However, unlike SMS which follows a store-and-forward oriented message transaction; USSD provides session-based connections. Because of its real-time and instant messaging service capability, USSD service is up to seven times faster and much cheaper than SMS for two-way transactions. It is a technology unique to GSM networks and is the standard for transmitting information over GSM Signaling Channels. USSD is as similar to speaking to someone on a phone as SMS is to sending a letter.

NEED FOR USSD

USSD is a highly cost effective and fast technology and is seven times faster in operating speed than SMS. USSD has several advantages as a bearer technology, such as:
  1. USSD provides a cost-effective and flexible mechanism for offering various interactive and non-interactive mobile services to a wide subscriber base.
  2. USSD supports menu-based applications facilitating more user interactions.
  3. USSD is neither a phone-based nor a SIM-based feature. It works on almost all GSM mobile phones (from old handsets to new smartphones)
  4. With USSD, messages can even be initiated during calls, allowing simultaneous voice and data communication.
  5. USSD allows faster communication between users and network applications because messages are sent directly to the receiver allowing an instant response.
  6. USSD services available on the home network are also accessible while roaming. Unlike SMS, there are no charges for this.
ADVANTAGES OF USSD

USSD is a highly cost effective and fast technology and is seven times faster in operating speed than SMS. USSD has several advantages as a bearer technology, such as:
  1. Cost efficient - Significantly less investment is required in the network as USSD uses existing SS7 protocols.
  2. Fast and responsive – Real-time and instant messaging service capability allows operators to provide easy to use, responsive and fast menu-driven content provision services.
  3. Interactive navigation – USSD is increasingly being adopted to develop interactive applications like mobile chatting, roaming with prepaid service, callback service, prepaid recharge, mobile banking, etc. 
  4. Reduced marketing cost – Operators can use USSD as a cost-effective way to cross-and up-sell additional services.

ELEMENTS OF USSD MOBILE NETWORK
 


 The mobile network comprises components that carry data messages between the handset and the  corresponding USSD application. Figure 2 explains the elements of the mobile network and the communication protocols they use. USSD services reside as applications in the mobile network. These applications can reside in MSC, VLR, HLR, or an independent application server that is connected through a USSD Gateway (using SMPP). If a USSD message is not destined for an application in the MSC, VLR, or HLR, a USSD handler in these nodes routes the message to the USSD Gateway using the MAP protocol based on the service code. The gateway interprets the code and routes it to the specific USSD application server to fetch the necessary information requested by the user. In response, the application sends the relevant information to the USSD Gateway, which in turn converts the message to MAP format, and then sends to the mobile terminal. Applications under the mobile operator’s control will typically reside in the GSM network (MSC, VLR, HLR), while third-party applications may reside elsewhere such as on the internet. The application can also be a hyperlink to an internet site or information stored locally in the Service Application System. In a mobile-initiated service request, a session is created between the network and the mobile terminal. This session is used for all information transfers and must be released before another session can be started. Additionally, an application in the network (residing in the MSC, VLR, HLR, or external application server) may at any time send a message to a mobile terminal. This can be a request for  information or a notification. Again, the session must be released upon completion.
 

Figure 3 shows the message flow for a network-initiated (HLR, VLR, and MSC) USSD request for a single operation.



Figure 6 shows the message flow for a mobile-initiated USSD request that failed at MSC, VLR, and HLR. It also depicts a case where an MS clears the transaction before it receives a response to the initiated USSD request.

Data security with SMS banking

SMS service is deemed to be the least secured of the technologies suggested for mobile banking because of the number of points where the SMS data is available to others in a clear or unencrypted format. The diagram below shows the entities involved across the GSM channel in SMS banking.


A customer initiates a transaction by sending an SMS to the bank using the bank’s SMS short code. The SMS is stored on the handset and is available to anyone who looks at the customer’s phone; hence, making it unsecure at the very first step. The SMS then passes through the encrypted GSM communication channel through the base stations and terminates at the mobile network operator’s SMSC. There, it is typically stored in an unencrypted form, making it unsecure at also the second step. The SMSC passes the message onto the bank’s wireless application processor or mobile banking processor (which may be a third party), where it is stored either in encrypted or unencrypted form. The third party then passes the message to the bank across an encrypted fixed line to the bank, where it is typically stored in a secured environment. In all, there are three highly susceptive points of exposure during the transaction where the data is stored, making the SMS service far less secure.

Data security with USSD banking

Unlike SMS, USSD message is not stored on customers’ mobile, making it secure at the first level. USSD opens a single session between the device and the supporting application at the network operator/processor/bank.

The data is also encrypted at the USSD gateway sitting at the network operator/processor/bank, preventing any misuse of the data. This makes it secure at the second step. The end-to-end transaction flow occurs across the encrypted GSM communication layer while the subscriber identity is also hidden. Hence, USSD service is safer than to SMS and other GSM technologies. However, there is one risk. If the GSM encryption (which is used to carry the data within the communication layer by secured means) is broken, the data can be accessed–which can actually happen with all GSM technologies (e.g., SMS, USSD, etc.). To avoid this, the GSM encryption needs to be made more robust, much like how internet banking has evolved over the years. Excluding this generic threat, USSD appears to be the most suited technology for mobile banking application.

I have referred the above information from a white paper published by Aricent Inc. You can find more information on the topic by referring to this link http://www.aricent.com/sites/www.aricent.com/files/pdf/Aricent_WhitePaper_USSD_0911.pdf.

Monday, October 1, 2012

Xperia Neo V IceCreamSandwich Review

   Updated my Xperia Neo V to Android 4.0.4 IceCream Sandwich, and would like to post the reviews about the same.........

 - Starting with the UI, I must say that the new UI is awesome, its very very swift and there is remarkable improvement in the agility of the screen flow.

 - There are small changes like the ones related to the font and appearance of icons is very crisp and clear which make it look even more graceful.

 - Browser has undergone impressive changes too. Different browser window management is made very simple now, navigation between the tabs has become very easy, also there is option provided in the menu wherein you can request the original desktop site in case the mobile website is offered.

 - The Notifications area has underwent a complete makeover with the much missing addition of settings menu. Now controlling Wi-Fi, Bluetooth and Data On/Off has become much easier.

 - I always missed the functionality of creating groups in Contacts, but with ICS its there. You can create groups in the new ICS Contacts application,  the new dial pad is very elegant and while dialling the number it will auto search in the existing contacts.

 - There are new better Ring tones and Notification tones.

 - The Power Off/On is quicker than GingerBread.

 - The Gallery app is not much revamped but I feel the performance IS. Swiping through pictures is much faster than before, the images load very quickly and before I forget to mention, also add the Screen Orientation which is improved as well.

   There are many more minute and major changes made with the new ICS which you will notice only after updating. I have just presented my views on the update. Overall I am satisfied wth the performance of ICS and love it.

   I had waited for long to update my phone, because I did not find any good or useful reviews.Hope this review helps someone awaiting to update his phone.

Monday, August 13, 2012

South African Voyage

        Hello Everyone.......................Lots and Lots of Time, so am back here again .......... :P

       This time am here to describe my venture to South Africa, yes I had been to South Africa in June for a project work, and must tell you it was an amazing experience. First time in my life I was out of home and directly got a chance to go out of the country. Am a travel freak, I like travelling very much and so the opportunity came in as a pleasant surprise for me.

       The trip was a mixed bag of feelings for me, initially I was very excited about it, but as the date of travel came closer I was getting a bit nervous, after all I was travelling alone for the first time in my life that too to a foreign nation and it is rumoured (not completely true) that South Africa is not a safe place. Yes the crime rate in South Africa was high, but that is the thing of the past now. The Law and order is good enough presently and much safer than before.

      The Client I had to work for was located in Johannesburg. My flight was at 2:35 am from Mumbai International Airport. I left my place at 5 pm to reach the Airport well before time. My parents had come to see me off, as I started to go inside the Terminal for check In my mother felt uneasy and so did I, she was continuously telling me to take care of myself, somehow I didn't feel happy, all the excitement I had before had zeroed down, after all there is nothing important in this world more than your parents. I went inside did my check In and all security checks and finally approached the Gate where the flight was supposed to attach. At around 2.20 a.m. I got on board and to my surprise I had a window seat, but bad luck, a guy asked me to exchange and I agreed (don't know why).

      As the flight took off, the view below was superb, Mumbai was glittering in lights and the whole Marine drive appeared exceptional. Then, it was nine and half hours of journey to reach JNB's Tango International Airport. An hour or so later the dinner was served after having that everyone went into deep slumber including me. South Africa is 3.5 hours behind India, at about 6 a.m. South African local time, the breakfast was served and finally the flight landed at Tambo International Airport at 8.30 a.m. I forgot to mention there were 15 other guys from our company who were travelling with me, we all got together after collecting the baggage, I got some South African currency from the exchange counters available. There was a man standing with our company's name at the arrival, there were 2 vans for our disposal, we got into the vans and went to company's office. It was cold and the breeze was making it more prominent.

      After completing all the formalities at company's office, I was left at my accommodation, it was a guest house, not bad though but it was very lonely. Everything was so quiet and very new for me, I went in and got ready, I had to report at the client's place the same day, fortunately it was nearby from my accommodation. Despite it being nearby I could not go there walking because it's not recommended here to walk alone. Somehow reached the office premises and started the searching the person and the building whom I had to report. Amidst a jungle of similar looking buildings it proved a nightmare for me to search the correct building where I had to report. After reaching the office I met the team whom I had to work with and got acquainted with them. Hence forth the work flowed smoothly with no major issues.

      The main issues I faced were not not technical or related to my work, but were related to my accommodation. Commuting to the office daily I faced a lot of problems since I had no car of my own, second thing I did not like was the silence, it was killing me, I just didn't not like the place without a second thought. I complained about the issues I faced to the accommodation team, but there was no positive reply. I kept on mailing them and left no stone unturned. At the same time I was missing my family very badly, I used to be all alone after returning to my room from office, the loneliness accompanied with nostalgia was making me feel like crying. I had a chat with my manager regarding change in accommodation but still no result.

      Finally after a week of turmoil, I unofficially went to my friend's room which was located in an upmarket place. I started staying there without any official consent and I felt a little better, here at least I could see a few people moving on the road along with lots of cars. The new place was fun, I made new friends over there who were very very helpful unlike ..................
I along with my roommate and his one more friend used to cook dinner together, I did not know to cook anything but wasn't a problem, I used to just wash and cut the vegetables and put rice in oven for cooking rest everything was handled by the other 2. Later after a few days I tried my luck at making chapatis and I was successful to a great extent ....:)

     I stayed in JNB for a month, it was a great experience for me. Although the initial week was gruesome,  the latter weeks I enjoyed visiting a few places. Among the places I visited were Sharjah Restaurant(Woodmead mall), Fortesburg, Monte Casino............I liked South Africa and I wanted to stay for some more time, but had to return as my work had finished. The people there are very very polite and very hard working. Given a chance I would like to visit the place again....................Goodbye.