Tuesday, November 27, 2012

Android Post a JSON Object to the WEB SERVICE.


Android Post a JSON Object to the WEB SERVICE.

Impotent:
here developer better use the posting with in separate thread, if you want to use in main thread it's getting exception.

(any button click)button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) { 

final int TIMEOUT_MILLISEC = 10000;  // = 10 seconds
Thread t = new Thread(){
       public void run() {
        Looper.prepare(); 
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
    HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
    HttpClient client = new DefaultHttpClient(httpParams);
    HttpPost request = new HttpPost("----- any post url here -----");
    //set post request type
    request.setHeader(HTTP.CONTENT_TYPE, "application/json; charset=utf-8");
    //request result type
    request.setHeader("Accept", "application/json; charset=utf-8");
JSONObject json = new JSONObject();
    try {
json.put("object_key1", "Value1").toString();// Example key, values 
json.put("object_key2", "Value2").toString();
json.put("object_key3", "Value3").toString();
JSONArray mainArr = new JSONArray();
   for(int i = 0; i < 3; i++){      
       JSONObject mainObj = new JSONObject();
       
   mainObj.put("key1", "any Value");
   mainObj.put("key2", "any Value");
       
   JSONArray innerArr = new JSONArray();
       
   for(int k = 0; k < 4 ; k++){        
       JSONObject innerObj = new JSONObject();
       innerObj.put("inner_key1", "any Value");
       
       innerArr.put(innerObj);
    }

  mainObj.put("innerArr", innerArr).toString();        
  mainArr(mainObj);
       }   
       
       json.put("inner_array", mainArr).toString();
Log.i("jason Object", json.toString());
StringEntity se = new StringEntity(json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
request.setEntity(se);      
HttpResponse response = client.execute(request); 
String temp = EntityUtils.toString(response.getEntity());
       Log.i("tag_responce", temp);
} catch (Exception e) {
e.printStackTrace();
}
Looper.loop(); //Loop in the message queue
           }
       };
       t.start();  
       
       }
   });

Thursday, November 15, 2012

ScrollView inside ScrollView Scrolling problem


While designing rich layouts you might need to use two scrollview in your app.
Well ideally its not advised to use two scrollview in a view. So try to avoid it.

Why this problem occurs ? :

When you put two scrollview android just get confused which scroll view is touched. So sometimes it gets unable to deliver touch event.
But even if the requirement forces you to make such layouts. Try this…
Say case is somewhat like this….
<ScrollView android:id=”@+id/parent_scroll” 
            android:layout_width=”fill_parent”
            android:layout_height=”wrap_content”
            android:layout_weight=”1″
            android:background=”@drawable/dotted_bg”
            android:focusableInTouchMode=”false”>
                        <LinearLayout   />
                        <LinearLayout   />
                        <LinearLayout  >
                        <ScrollView android:id=”@+id/child_scroll”  
                        android:layout_width=”fill_parent”
                        android:layout_height=”fill_parent”
                        android:background=”@drawable/text_box_bg”>
                    <TextView android:id=”@+id/text_description”
                        android:layout_width=”fill_parent”
                        android:layout_height=”fill_parent”
                        android:textColor=”@color/gray”
                        android:textSize=”12dip”
                        android:padding=”5dip”
                        android:scrollbars=”vertical”/>
                    <!–ScrollView>
                  </LinearLayout>
</ScrollView>

Step 1 : Provide unique id to both the scrollview.
Step 2 : get reference of that two scrollview in your activity.

     parentScroll=(ScrollView)findViewById(R.id.parent_scroll);
     childScroll=(ScrollView)findViewById(R.id.child_scroll);

Step 3: Now set touch listeners for both.

            parentScroll.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event) {
                    Log.v(TAG,”PARENT TOUCH”);
                    findViewById(R.id.child_scroll).getParent().requestDisallowInterceptTouchEvent(false);
                    return false;
                }
            });
            childScroll.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event) 
                {
                    Log.v(TAG,”CHILD TOUCH”);
                                        // Disallow the touch request for parent scroll on touch of child view
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    return false;
                }
            });
Done …

Wednesday, August 8, 2012

Code for Previous most Activity directly with out re calling the Activity



Code for
FirstActivity   ---> SecondActivity  ---> ThirdActivity

backPress: Thied ---> Second --->  First

When you click the GoToMainActivity button in ThiredActivity it will directly go to MainActivity by finishing the SecondActivity also

MainActivity ;
--------------


public class MainActivity extends Activity {
private Button next;

public static boolean back = false;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        next = (Button) findViewById(R.id.next);
    next.setText("First");
    }
   
    public void nextActivity(View view){
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}  
   
}


SecondActivity :
----------------

public class SecondActivity extends Activity {
private Button next;

public static boolean back = false;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        next = (Button) findViewById(R.id.next);
        next.setText("Second");
    }
   
    public void nextActivity(View view){    
Intent intent = new Intent(SecondActivity.this, ThirdActivity.class);
startActivity(intent);
}
   
@Override
    public void onResume(){
        super.onResume();
        /*
         * check the cundition wether user click the recomencer button if click colose this activity else resume the activity
         */
       
        if(back!= false){      
back();
}
    }
   
    public void GoBack(View view){
back();
}
/*
* this ethode is usefull to finish this activity when click recomencer button click
*/
public void back(){
finish();
back = false;
}
   
}



ThirdActivity ;
--------------


public class ThirdActivity extends Activity {
private Button next;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        next = (Button) findViewById(R.id.next);
    next.setText("Go to MainActivity");
    }
   
    public void nextActivity(View view){
    SecondActivity.back = true;
    finish();
}  
   
}

main.xml:
----------


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >
    <Button
        android:id="@+id/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:onClick="nextActivity"
        android:text="first" />

</RelativeLayout>







Wednesday, May 30, 2012

How to play embed you tube video in web view

How to play embed you tube video in web view  

Note: this is applicable in HTML-5 browser supported devices only 

myWebView = (WebView) findViewById( R.id.webview_compontent );

String playVideo= "<html><body>Youtube video .. <br> <iframe class=\"youtube-player\" type=\"text/html\" width=\"640\" height=\"385\" src=\"http://www.youtube.com/embed/bIPcobKMB94\" frameborder=\"0\"></body></html>"

myWebView.loadData(playVideo, "text/html", "utf-8");

Saturday, May 26, 2012

30 helpful Android development Tips/Tricks


30 helpful Android development Tips/Tricks


Hello All,

  1. #AndroidDev #AndroidTip: To resolve this issue “Failed to install *.apk on device timeout Launch canceled! , increase ADB connection timeout
  2. #AndroidDev #AndroidTip: use setError() to display error message for your EditText
  3. #AndroidDev #AndroidTip => To Block the default animation for startActivity() For ex: myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
  4. #AndroidDev #AndroidTip: Android Action Bar Style Generator http://jgilfelt.github.com/android-actionbarstylegenerator
  5. #AndroidDev #AndroidTip create library with reusable code and reference it in future projects.
  6. #AndroidDev #Tip #PureAndroid Don’t use right-pointing carets on line items http://developer.android.com/design/media/migrating_ios_settings.png
  7. #AndroidTip #AndroidDev 10 amazing Android development tips http://www.netmagazine.com/features/10-amazing-android-development-tips
  8. #AndroidDev #Tips => Define these attributes for displaying multiline EditText => android:singleLine=”false”, android:lines=”5″
  9. #AndroidDev #Tip => Follow Dashboard design pattern. Easy to implement and handle Navigation.
  10. #AndroidDev #Tip – Before starting with android app development, should read Android Building Blocks http://developer.android.com/design/building-blocks/index.html
  11. #AndroidDev #Tip => You can create your custom views by extending View class.
  12. #AndroidDev #Tip use android:weight=”1″ and android:layout_width=”0″ to define equal width of widgets inside LinearLayout.
  13. #AndroidDev #Tip => With Android 4.0 you cant use http connection or make web call without using a Thread (with a runnable, AsyncTask )
  14. #AndroidDev #Tips: Tutorial , Tips/Trick for Android http://stackoverflow.com/questions/3405695/tutorial-tips-trick-for-android
  15. AndroidDev #Java #Tip What should be the package name of android app? http://stackoverflow.com/questions/8075162/what-should-be-the-package-name-of-android-app
  16. #AndroidDev #Tip: GraphView Library for Android to programmatically create flexible and nice-looking diagramms http://www.jjoe64.com/p/graphview-library.html?spref=tw
  17. #AndroidDev #Tip => how to limit seekbar http://stackoverflow.com/questions/3490951/how-to-limit-seekbar
  18. #AndroidDev: Do you know? => Android: maximum length of url http://stackoverflow.com/questions/10172566/android-maximum-length-of-url
  19. #AndroidDev #Tips => RT @piyushnp How To Create a Android App With ICS UI That Works With Gingerbread and Froyo? http://stackoverflow.com/questions/9886523/how-to-create-a-android-app-with-ics-ui-that-works-with-gingerbread-and-froyo
  20. #AndroidDev #Tip – Switch widget is available from API 14 http://developer.android.com/reference/android/widget/Switch.html
  21. #AndroidDev #Tip – How to design tab icons? http://developer.android.com/guide/practices/ui_guidelines/icon_design_tab.html
  22. #AndroidDev rating bar padding problem http://code.google.com/p/android/issues/detail?id=2324
  23. #AndroidDev Anyone ever seen this exception when loading bitmaps in Android?… http://developer.android.com/training/displaying-bitmaps/index.html #BitmapVMSizeExceed
  24. #AndroidDev #Tip : To capture screen shot from real android device, simply Press Home button + Back key
  25. #AndroidDev #Tip : use android:installLocation=”auto” to enable move to SD-card feature for Android app http://www.technotalkative.com/android-enable-the-move-to-sd-card-feature/
  26. #AndroidDev #Tip : Use SimpleDateFormat class to change format of date/time.
  27. #AndroidDev #Tip: How to view the SQLite database on your Android Emulator http://blog.kwyps.com/2011/07/how-to-view-sqlite-database-on-your.html
  28. #AndroidDev #Tip: you can check the status of AsyncTask by using getStatus() method, or like AsyncTask.Status.FINISHED
  29. #Android tip: Stop developing countdown algorithms, use the built-in CountDownTimer (http://developer.android.com/reference/android/os/CountDownTimer.html). #android #androiddev
please share your feedbacks/reviews 

Tuesday, May 15, 2012

Taking Android to Work


Taking Android to Work

Fred Chung, Andrew Stadler, Gabriel Cohen
More and more people are bringing Android devices into enterprise environments. This talk will cover general enterprise adoption considerations and related Android features. We will also provide an overview of security issues, managed internal app development, corporate app directories, and an in-depth look at a sample implementation of device management policies.
Level: 201
Track: Android
Time: May 11, 04:15PM – 05:15PM
Room: Room 11

Memory management for Android Apps


Memory management for Android Apps

Patrick Dubroy
Android apps have more memory available to them than ever before, but are you sure you're using it wisely? This talk will cover the memory management changes in Gingerbread and Honeycomb (concurrent GC, heap-allocated bitmaps, "largeHeap" option) and explore tools and techniques for profiling the memory usage of Android apps.
Level: 301
Track: Android
Time: May 11, 04:15PM – 05:15PM
Room: Room 9

Honeycomb Highlights


Honeycomb Highlights

Romain Guy, Chet Haase
Android's "Honeycomb" release includes a large number of new features, capabilities, and APIs to access them. This session gives a high-level view of everything that's new, with special focus on how this affects developers' lives and what they should be paying attention to.
Level: 101
Track: Android
Time: May 10, 10:15AM – 11:15AM
Room: Room 11

Don’t just build a mobile app. Build a business.


Don’t just build a mobile app. Build a business.

Wayne Pan
Learn how to build a business on mobile apps so you can quit your day job. Walk away with an understanding of app business basics and how to use house ads for app promotion, mediation to optimize in-app advertising revenues and analytics to measure real ROI.
Level: 201
Track: Android
Time: May 10, 01:15PM – 02:15PM
Room: Room 11

Designing and Implementing Android UIs for Phones and Tablets


Designing and Implementing Android UIs for Phones and Tablets

Roman Nurik, Adam Powell, Richard Fulcher, Christian Robertson, Matias Duarte
There are a large number of Android tablet devices starting to ship. This session discusses the new APIs and tools available to developers for use in constructing apps that work well on them, and provides guidance on creating good user experience for users of these devices.
Level: 201
Track: Android
Time: May 11, 12:30PM – 01:30PM
Room: Room 11

Best Practices for Accessing Google APIs on Android


Best Practices for Accessing Google APIs on Android

Integration with Google APIs (such as Buzz, Latitude and Translate) can enrich many Android applications. In this session, we will demonstrate how to do so easily, efficiently and securely using the Google API Client for Java. We’ll walk you through how to authenticate for the APIs using AccountManager, how to reduce the client library size and several other Android-specific optimizations.
Level: 201
Track: Android
Time: May 10, 11:30AM – 12:30PM
Room: Room 9

Android Protips: Advanced Topics for Expert Android App Developers


Android Protips: Advanced Topics for Expert Android App Developers

Writing an app is easy, but with 100k competitors you need to do better than launch and cross your fingers. I'll demonstrate how to use advanced Android techniques to take a good app and transform it into a polished product. Features advanced coding tips & tricks, design and implementation patterns, and insight into some of the lesser known API features. This is an advanced session designed to help experienced developers.
Level: 301
Track: Android
Time: May 10, 11:30AM – 12:30PM
Room: Room 11

Android Market for Developers


Android Market for Developers

There are few things developers care more about than Android Market and, during the year since Google IO 2010, we have been investing huge amounts of efforts in expanding and improving it. This presentation walks through what's new, with a particular focus on where developers can take action to improve their apps' Market performance.
Level: 101
Track: Android
Time: May 11, 10:45AM – 11:45AM
Room: Room 11

Google Chrome: Day 2 Keynote from Google I/O


Google Chrome: Day 2 Keynote from Google I/O

Day kicked off with the announcement that Chrome is now at 160M active users, up from 70M last year. Watch for more announcements from the Chrome Web Store, Angry Birds, Chromebooks and Chrome In-App Payments.
Level: 101
Track: Keynote
Time: May 11, 09:30AM – 10:30AM
Room:

3D Graphics on Android: Lessons learned from Google Body


3D Graphics on Android: Lessons learned from Google Body

Google originally built Google Body, a 3D application that renders the human body in incredible detail, for WebGL-capable browsers running on high-end bPCs. To bring the app to Android at a high resolution and frame rate, Nico Weber and Won Chun had a close encounter with Android's graphics stack. In this session Nico will present their findings as best practices for high-end 3D graphics using OpenGL ES 2.0 on Android. The covered topics range from getting accelerated pixels on the screen to fast resource loading, performance guidelines, texture compression, mipmapping, recommended vertex attribute formats, and shader handling. The talk also touches on related topics such as SDK vs NDK, picking, and resource loading.
Level: 101
Track: Android
Time: May 11, 04:15PM – 05:15PM
Room: Room 8