Popular Posts

Apr 29, 2012

Remove white space and delete one character in android

            String k = guessTextView.getText().toString();

            sum  = k.replaceAll(" ", "%20");
            StringBuilder stringBuilder=new StringBuilder(80);
           
            stringBuilder.append(sum);
                      
            sum = stringBuilder.deleteCharAt(stringBuilder.length()-1).toString();
           
            guessTextView.setText(sum);

Apr 27, 2012

Create sub-folder in SD Card using Java code (Android)


First  in AndroidManifest.xml add the permission  "android.permission.WRITE_EXTERNAL_STORAGE"
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

The java code:
 String subDir = "/myFolderName";
      String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
      File myNewFolder = new File(extStorageDirectory + subDir);
      myNewFolder.mkdir();

Apr 24, 2012

Using Alert in Android

AlertDialog.Builder builder = new AlertDialog.Builder(Alert_DialogActivity.this);
                builder.setMessage("Are You Sure you want to exit");
                builder.setCancelable(false);
                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        Alert_DialogActivity.this.finish();
                    }
                 });
                builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                   
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        dialog.cancel();
                    }
                });
               
                builder.setNeutralButton("Jubayer", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        //Toast.makeText(context, text, duration);
                        Log.w("Jub", "Jubayer Clicked");
                    }
                });
               
                AlertDialog alert = builder.create();
                alert.show();

Apr 23, 2012

Send Email in Android


                Intent intentEmail = new Intent(android.content.Intent.ACTION_SEND); 
                 
                String emailList[] = { "user@fakehost.com","user2@fakehost.com" }; 
                String emailCCList[] = { "user3@fakehost.com","user4@fakehost.com"}; 
                String emailBCCList[] = { "user5@fakehost.com" }; 
                 
                intentEmail.putExtra(android.content.Intent.EXTRA_EMAIL, emailList); 
                intentEmail.putExtra(android.content.Intent.EXTRA_CC, emailCCList); 
                intentEmail.putExtra(android.content.Intent.EXTRA_BCC, emailBCCList); 
                 
                intentEmail.putExtra(android.content.Intent.EXTRA_SUBJECT, "My subject"); 
                 
                intentEmail.setType("plain/text"); 
                intentEmail.putExtra(android.content.Intent.EXTRA_TEXT, "My message body."); 
                 
                startActivity(intentEmail);
           

Apr 22, 2012

Android Gods frown upon me!!


You can close your android app with this Code


      android.os.Process.killProcess(android.os.Process.myPid());
                                    System.exit(0);

 

But Android always discourages this. Android handles the memory and close the apps atomically if needed.

Apr 9, 2012

Adding an External Library (.jar) using Eclipse(Android)

You can use a third party JAR in your application by adding it to your Eclipse project as follows:
  1. In the Package Explorer panel, right-click on your project and select Properties.
  2. Select Java Build Path, then the tab Libraries.
  3. Press the Add External JARs... button and select the JAR file.
Alternatively, if you want to include third party JARs with your package, create a new directory for them within your project and select Add Library... instead.
It is not necessary to put external JARs in the assets folder.

Lifetime of the new screen(Android)

An activity can remove itself from the history stack by calling Activity.finish() on itself, or the activity that opened the screen can call Activity.finishActivity() on any screens that it opens to close them.

Print Messages to a Log File(Android)

To write log messages from your application:
  1. Import android.util.Log.
  2. Use Log.v(), Log.d(), Log.i(), Log.w(), or Log.e() to log messages.
    E.g., Log.e(this.toString(), "error: " + err.toString())
  3. Launch DDMS from a terminal by executing ddms in your Android SDK /tools path.
  4. Run your application in the Android emulator.
  5. From the DDMS application, select the emulator (e.g., "emulator-5554") and click Device > Run logcat... to view all the log data.
MORE http://developer.android.com/resources/faq/commontasks.html#newandroidprojectnoeclipse