Pages

Monday, July 23, 2012

How to check SDCard free space in ANDROID?

This is a simple example that shows how many bytes are free in your SDCard.
Inorder to run this example, you have to create an SDCard and start the emulator with the SDCard.
Now create a fresh project and name it “FreeSpaceActivity.java” and copy the following code to it.

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
package pack.coderzheaven.check_space;
 
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.widget.TextView;
 
public class FreeSpaceActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        StatFs stat_fs = new StatFs(Environment.getExternalStorageDirectory().getPath());
        double avail_sd_space = (double)stat_fs.getAvailableBlocks() *(double)stat_fs.getBlockSize();
        double GB_Available = (avail_sd_space / 1073741824);
        System.out.println("Available GB : " + GB_Available);
 
        TextView tv = (TextView)findViewById(R.id.tv);
        tv.setText("Your SD Card is " + GB_Available + " bytes free." );
        tv.setTextColor(Color.GREEN);
        tv.setTextSize(20);
    }
}
The main.xml file
?
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text=""
    android:id="@+id/tv"
    />
</LinearLayout>
AndroidManifest file
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="pack.coderzheaven.check_space"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".FreeSpaceActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Please leave your comments if the post was useful.

Free space in SD Card

34 comments:

  1. Yippeee…dude, I feel like walking over and giving you a big bear hug. Thank you for taking time to tell me all about freelance job opportunities. Can you give some advice on where I can upload my stuff? I am a wannabe music composer and have quite a few original pieces that I am eagerly waiting to sell. I hit upon some cool sites like buy 1000 youtube subscribers,creative flyer design. Do you know of more such places on the internet where there are people to buy my work? Just can’t wait to begin.

    ReplyDelete
  2. Hey, such a useful piece of information you are sharing here. Since a long time, I was badly in search of this information. Thanks for sharing it, dude. Also, I would like to share the information in my blog as well, so that, my visitors will also get such wonderful information.
    Xamarin Developers in Frisco | Hire Xamarin Developer

    ReplyDelete
  3. I must say, this is really an awesome post which you have shared in a simple and easy to grasp way. Surely I will share it in my post as we, to deliver the wonderful and well-researched information to my visitors too.

    online ordering system for restaurants
    Restaurant Website Ordering System
    Online Ordering Restaurant POS System

    ReplyDelete
  4. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job,Keep it up.

    Try Our Love Spells Removal In Toronto Services and Get All the benefits of it in your life, we make All your Personal problems solved in just minutes.

    ReplyDelete





  5. We are dealing in wide range of spy cameras of topmost quality on lowest prices. Contact us at +91 9999332499 Spy Camera in Delhi

    ReplyDelete
  6. Hey, good day
    Thanks for sharing such valuable information.i want more these type of informatiove blogs, really
    seo mississauga

    ReplyDelete
  7. Buy Farm Fresh seasonal Mango Fruits online at best price. Send Mangoes to all Pakistan like Karachi, Lahore, Islamabad, Rawalpindi, Peshawar, Multan, Faisalabad, Hyderabad and Jhelum on door step fruitoyepk.

    ReplyDelete
  8. public static float megabytesAvailable(File f) {
    StatFs stat = new StatFs(f.getPath());
    long bytesAvailable = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)
    bytesAvailable = (long) stat.getBlockSizeLong() * (long) stat.getAvailableBlocksLong();
    else
    bytesAvailable = (long) stat.getBlockSize() * (long) stat.getAvailableBlocks();
    return bytesAvailable / (1024.f * 1024.f);
    }

    Custom Cosmetic Boxes

    ReplyDelete
  9. I find this post very accurate and informative. One topic that always interests me is Web Hosting in Lahore. So when I came across this post, I was excited to find out more about it and I am glad I did.

    ReplyDelete
  10. movers and packers in dubai | noorahmedtransports Noor Ahmad Transport is a Mover and Packer service provider in Dubai Marina. Pickup Truck Rental Dubai 1/3 Ton - 7/10 Ton Truck with Tail Lift. Home/Office Shifting, Man with van service in Dubai. Call: 050 651 2943

    ReplyDelete
  11. The reasons comprise infective contagion, viral infection and, less typically, chemical irritation. Treatment normally includes antibiotics, painkillers and anti-inflammatory treatment. Full retrieval can take place in just a few days. Early Analysis of Epididymitis means early Epididymitis cure. Make sure you get a remedial diagnosis and Natural Remedies for Epididymitis.

    ReplyDelete
  12. Peyronie's disease is where plaques (segments of flat scar tissue) form under the skin of the penis. These plaques can cause the penis to bend or become indented during erections. The plaques can often be felt through the skin and can be painful, use Natural Treatments for Peyronie's Disease relief a painful disorder.

    ReplyDelete
  13. Herbs Solutions by Nature offer Herbal Supplement for Health and Skin Diseases. Natural Herbal Treatment really does help you recover from your health condition.

    ReplyDelete
  14. Natural Treatment for Granuloma Annulare that can help manages this condition naturally. Herbal Supplement can decrease itching and the occurrence of skin lesions.

    ReplyDelete
  15. With the basic ideas out of the way, the next thing that we would certainly like to discuss around is how one can use the Natural Remedies for Burning Mouth Syndrome. If you want to relieve Buy Herbal Product for Burning Mouth Syndrome, eating yogurt is considered one of the best ones in the lot. Read for Valuable Information Herbs Solutions by Nature

    ReplyDelete
  16. Buy Herbal Product for Benign Essential Tremor to treat the voice, head, jaw, lips, and face. Herbal Supplement really takes hold and treats the condition naturally.

    ReplyDelete
  17. We have mentioned some information about each diet plan at the beginning of each diet plan for which you will have to click the diet plan you want more information. You will first find some information on the diet plan and then the healthy diet charts will appear day-wise or week wise. Hope it is of some help to you all! Team “Natural Health News” Healthy Diet Charts Department.

    ReplyDelete
  18. Natural Treatment for Actinic Keratosis is to prevent the lesions from turning into skin cancers. Herbal Supplement used to treat or reduce the symptoms.

    ReplyDelete
  19. A hydrocele is an uncomfortable testicle problem that inconveniences males. In hydrocele, liquid gathers in the scrotum (sac around the testicles). Herbal Products for Hydrocele helps in testicle condition of the collection of liquid in the scrotum, by applying Natural treatment gets assistance from inflamed and seems extended and assist in How to hydrocele treat At Home.

    ReplyDelete
  20. This avocado is probably a good Herbal Supplement for Granuloma Annulare because that works on granuloma annulare which is packed with vitamin E. You can also take a daily tablespoon of apple cider vinegar verbally or apply it to your skin as they are a Granuloma Annulare Natural Treatment. Coconut oil absorbs into the skin and penetrates very effectively - Granuloma Annulare Coconut Oil will help relieve any itching and inflammation from your rash.

    ReplyDelete
  21. Natural Treatment for Granuloma Annulare that can help manages this condition naturally. Herbal Supplement can decrease itching and the occurrence of skin lesions.

    ReplyDelete
  22. You should drink green tea on a regular basis because this can effective in the Natural Remedies for Granuloma Annulare natural recovery. There is another way to use green tea and that is to apply the green tea bags to your skin directly. Green Tea has anti-inflammatory and antioxidant properties which can help in the healing process.

    ReplyDelete
  23. Natural Remedies for Peyronie's Disease aid in the removal of scar tissue caused by Peyronie's Disease, as well as provide relief from penile discomfort. Herbal Supplement for Peyronie's Disease is acceptable and maybe a feasible scar therapy (of the skin). Herbs Solutions by Nature provides the most up-to-date Peyronie's infection treatment options.

    ReplyDelete
  24.  Herbal Supplement for Health and Skin Diseas to help improve the appearanceHome Remedies for Granuloma Annulare, grape seed extract is one of my favorite ingredients. In medical science, grape seed extractNatural Remedies for Granuloma Annulare is Vitamin E oil.— Herbal Supplement for Granuloma Annulare which may help explainHerbal Remedies for Granuloma Annulare for soothing your skin and reducing inflammation.

    ReplyDelete
  25. Herbal Supplement for Actinic Keratosis is highly recommended to all people suffering from these diseases as they offer positive results at an affordable price. Herbal Remedies for Actinic Keratosis, It immediately reduced redness.The extract of olive leaf has been used for thousands of years to treat various skin conditions. Herbal Remedies for Actinic Keratosis, It immediately reduced redness.

    ReplyDelete
  26. The typical symptom of Hydrocele is enlargement or swelling around a testicle.The Natural Remedies for Hydrocele involves surgery to correct any anatomical defect in your child’s scrotum. These additional Herbal Remedies for Hydrocele include herbal medicine like Celdeton Hydrocele.Natural Cure Zone strongly recommends that you consult with your primary healthcare provider before starting any Herbal Supplements.Herbal Supplement for Hydrocele can be treated naturally with herbal supplements.

    ReplyDelete
  27. When it comes to Natural Treatment for Granuloma Annulare, nothing beats garlic. It’s a potent antibacterial agent that can stop symptoms like itching and burning almost instantly. Due to its anti-fungal properties, wormwood can be used as a Natural Remedies for Granuloma Annulare.Anecdotal evidence indicates that taking ginger root can be used as a Granuloma Annulare Natural Treatment.One natural treatment option for granuloma annulare is aloe vera extract. This topical Herbal Supplement for Granuloma Annulare is available in gel or ointment form.

    ReplyDelete
  28. Emphysema is a disease that makes breathing very difficult. It damages your lungs, so they cannot get as much oxygen in and out of your body. It can be excruciating to live when you have emphysema. Hysmeton is an Herbal Supplement for Emphysema to help with symptoms of emphysema and asthma.There are many different symptoms of emphysema. It is often a silent killer because people with severe emphysema may not have any symptoms.

    ReplyDelete
  29. All of that the Natural Remedies for Abdominal Adhesions is the best option to cure from that type of diseases.But first of all must try Herbal Supplement for Abdominal Adhesions,Abdominal adhesions should be treated as soon as possible after being diagnosed with the problem. An herbal pill called sedeton is the best Alternative Treatment for Abdominal Adhesions for it. The pill from Herbs Solutions By Nature is free of any artificial chemicals. It is made up of a combination of well-researched, helpful herbs that have been mixed together to provide the finest Natural Treatment for Abdominal Adhesions.

    ReplyDelete
  30. Ginger is used as Natural Remedies for Abdominal Adhesions,Turmeric is a well-known herb and Natural Treatment for Abdominal Adhesions discomfort, which can be caused by a variety of factors.It has antispasmodic, cardioprotective, and heart muscle strengthening effects, and it is also Alternative Treatment for Abdominal Adhesions.Herbal Supplement for Abdominal Adhesions, you should seek medical attention.

    ReplyDelete
  31. After being diagnosed with the problem, Natural Treatment for Abdominal Adhesions should be started right away. Sedeton, a herbal supplement, is the best treatment for it.But if you are afeared from surgical treatment then must try Herbal Supplement for Abdominal Adhesions.. It's also been shown to help regulate bowel motions and ease stomach pains and cramps, which are signs of partial intestinal obstruction caused by abdominal adhesions. Follow the instructions on the package for the most effective Alternative Treatment for Abdominal Adhesions.

    ReplyDelete

Popular Posts