Wednesday, June 29, 2011

Check for Debuggable flag in Android

Many a times we as a programmers want to hard code some values in our application for test purpose.

AND MOST OF THE TIMES WE FORGET TO REMOVE THEM WHEN WE RELEASE THE APP.

Well, to overcome this issue, i am posting a small snippet of code. Using this you can remove this issue just by checking for a flag before your hard coded values. ;P

/*
 Copyright [2011] [Abhinava Srivastava]

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */


public static boolean isDebugMode(Activity context){
boolean debug = false;
PackageInfo packageInfo = null;
try {
packageInfo = context.getPackageManager().getPackageInfo(context.getApplication().getPackageName(),
PackageManager.GET_CONFIGURATIONS);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo != null) {
int flags = packageInfo.applicationInfo.flags;
if ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
debug = true;
}else
debug = false;
}
return debug;
}

So now in your application just check for the return value of this function :)

Monday, June 27, 2011

For all my Code thirsty Friends (Twitter Code For Android Applications)

Download Full Source from Here


Hope this will be resolving Most of the queries ....

OPENNESS IS OUR RIGHT :)

Please let me know if anything is required.

package abhinavasblog.blogspot.com;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.twitter.android.TwitterApp;
import com.twitter.android.TwitterApp.TwDialogListener;

/*
 Copyright [2010] [Abhinava Srivastava]

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

public class TwitterForUActivity extends Activity {

private TwitterApp mTwitter;

/** Called when the activity is first created. */
private static final String CONSUMER_KEY = "GPjUBdt9yn3FYTO9RcW2w";// "GPjUBdt9yn3FYTO9RcW2w";
private static final String CONSUMER_SECRET = "M0uxQG8r4f5ogfMDH0phU0FQvaYBOo2Bv6hP98xiag"; //"M0uxQG8r4f5ogfMDH0phU0FQvaYBOo2Bv6hP98xiag";

private enum FROM {
TWITTER_POST, TWITTER_LOGIN
};

private enum MESSAGE {
SUCCESS, DUPLICATE, FAILED, CANCELLED
};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTwitter = new TwitterApp(this, CONSUMER_KEY, CONSUMER_SECRET);
}

/**
* Handling click events of button used to launch
*
* @param v
*/
public void onClick(View v) {
mTwitter.setListener(mTwLoginDialogListener);
mTwitter.resetAccessToken();
if (mTwitter.hasAccessToken() == true) {
try {
mTwitter.updateStatus(TwitterApp.MESSAGE);
postAsToast(FROM.TWITTER_POST, MESSAGE.SUCCESS);
} catch (Exception e) {
if (e.getMessage().toString().contains("duplicate")) {
postAsToast(FROM.TWITTER_POST, MESSAGE.DUPLICATE);
}
e.printStackTrace();
}
mTwitter.resetAccessToken();
} else {
mTwitter.authorize();
}
}

/**
* Show toast messages
*
* @param twitterPost
* @param success
*/
private void postAsToast(FROM twitterPost, MESSAGE success) {
switch (twitterPost) {
case TWITTER_LOGIN:
switch (success) {
case SUCCESS:
Toast.makeText(this, "Login Successful", Toast.LENGTH_LONG)
.show();
break;
case FAILED:
Toast.makeText(this, "Login Failed", Toast.LENGTH_LONG).show();
default:
break;
}
break;
case TWITTER_POST:
switch (success) {
case SUCCESS:
Toast.makeText(this, "Posted Successfully", Toast.LENGTH_LONG)
.show();
break;
case FAILED:
Toast.makeText(this, "Posting Failed", Toast.LENGTH_LONG)
.show();
break;
case DUPLICATE:
Toast.makeText(this,
"Posting Failed because of duplicate message...",
Toast.LENGTH_LONG).show();
default:
break;
}
break;
}
}

/**
* Twitter Dialog Listner.
*/
private TwDialogListener mTwLoginDialogListener = new TwDialogListener() {

@Override
public void onError(String value) {
postAsToast(FROM.TWITTER_LOGIN, MESSAGE.FAILED);
Log.e("TWITTER", value);
mTwitter.resetAccessToken();
}

@Override
public void onComplete(String value) {
try {
mTwitter.updateStatus(TwitterApp.MESSAGE);
postAsToast(FROM.TWITTER_POST, MESSAGE.SUCCESS);
} catch (Exception e) {
if (e.getMessage().toString().contains("duplicate")) {
postAsToast(FROM.TWITTER_POST, MESSAGE.DUPLICATE);
}
e.printStackTrace();
}
mTwitter.resetAccessToken();
}
};
}


Call Manager Lite Updated "The Perfect 2"

Hey All,

Updated the Call Manager Lite Application to Version 2.2.2.

Version includes improvement with calling card functionality.
Now you can enable calling card feature to all the outgoing numbers with specific country code.

The basic feature of calling Card List and other functionality still remains the same.

Using the new features:

All you need to do is add the Extension of the countries you want to enable the calling card, in the calling card number field. Comma seperated values (e.g <Calling CardNumber>,<Country code +91>,<Country code +1>,... you can add as many countries you want. :)

Looking forward for your suggestions. :)

Thursday, June 23, 2011

Firefox 5.0 Cool features (Pin It)

MOZILLA IN NEW AVATAR

 
Mozilla Firefox 5.0

Got my hands on with Firefox 5.0 today.

Have to say this.. it has got improved a lot. Much better speed. No sticky browsing and much much more.

The Best part i really liked about this new browser is the ability to Pin your favourite sites on the browser itself. This makes you switch on them quite easily.

The javascript rendering has improved.. well not as good as Chrome but yeah its better than before.

So if you are thinking to try a browser apart from your Chrome. You can certainly go and checkout the Mozilla borwser.



Tuesday, June 21, 2011

Google Body .... Wish we had it before..

Its not quite new but just incase you havent checked it out.
Google body is a site where you can find better picture about your internals... Yeah thats awsome when they show you stripping each and every part of your body out of you :D

NO ITS NOT YOUR BODY THERE... but as long as you consider yourself as humans... you can find yourself simmilar to that..

Check out this link http://bodybrowser.googlelabs.com/body.html


A pic from Google body website...

Its really a graet fun to learn about your body. They have defined each and every part of your body in a spectacular manner.


Well all i can say is that if i had this at the time of my schooling i would have chosen Biology ... 

Monday, June 20, 2011

Your mobile Your wallet..


Day before yesterday in New York City office, along with Citi, MasterCard, First Data and Sprint, Google gave a demo of Google Wallet, an app that will make your phone your wallet. You’ll be able to tap, pay and save using your phone and near field communication (NFC). Google is currently field testing Google Wallet now and plan to release it soon.


Google Wallet is a key part of google's ongoing effort to improve shopping for both businesses and consumers. It’s aimed at making it easier for you to pay for and save on the goods you want, while giving merchants more ways to offer coupons and loyalty programs to customers, as well as bridging the gap between online and offline commerce.

Because Google Wallet is a mobile app, it will do more than a regular wallet ever could. You'll be able to store your credit cards, offers, loyalty cards and gift cards, but without the bulk. When you tap to pay, your phone will also automatically redeem offers and earn loyalty points for you. Someday, even things like boarding passes, tickets, ID and keys could be stored in Google Wallet.

Friday, June 3, 2011

Android Launches MTP/PTP API for its developers

With the Android 3.1 Developers will now be able to use yet another powerful feature of MTP/PTP API.

What is MTP/PTP API??

It let you interact directly with connected cameras and other devices, using the PTP (Picture Transfer Protocol) subset of the MTP (Media Transfer Protocol) specification.
Your application can receive notifications when devices are attached and removed, manage files and storage on those devices, and transfer files and metadata from the devices.

A whole new media exchange possibilty lies ahead...
So developers...
what you gonna do with it..??




More specification about the same can be found on the Android Developer website : http://developer.android.com/sdk/android-3.1.html