月度归档:2011年02月

android使用ZipInputStream解压缩zip压缩文件

public class unzip extends Activity {
  /** Called when the activity is first created. */
  static final int BUFFER = 2048;
  TextView textView;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    textView = new TextView(this);
    super.onCreate(savedInstanceState);
    textView.setText(“Main Activity”);
    extractZipfile();
    setContentView(textView);
  }
  private void extractZipfile() {
    String extractDir = getApplicationContext().getFilesDir()
            .getAbsolutePath()
            + “/unzip/”;
    try {
      BufferedOutputStream dest = null;
      ZipInputStream zis = new ZipInputStream(getResources()
              .openRawResource(R.raw.book));
      ZipEntry entry;
      while ((entry = zis.getNextEntry()) != null) {
        File file = new File(extractDir + entry.getName());
        if (file.exists()) {
          textView.append(“n” + file.getAbsolutePath() + “texists”);
          continue;
        }
        if (entry.isDirectory()) {
          if (!file.exists())
            file.mkdirs();
          textView.append(“nCreate directory: “
                  + file.getAbsolutePath());
          continue;
        }
        textView.append(“nExtracting:” + entry);
        int count;
        byte data[] = new byte[BUFFER];
        textView.append(” to ” + file.getAbsolutePath());
        FileOutputStream fos = new FileOutputStream(file);
        dest = new BufferedOutputStream(fos, BUFFER);
        while ((count = zis.read(data, 0, BUFFER)) != -1) {
          dest.write(data, 0, count);
        }
        dest.flush();
        dest.close();
      }
      zis.close();
    } catch (Exception e) {
        // TODO: handle exception
      e.printStackTrace();
    }
  }
}

android sdk下载地址

ADT 10.0.0下载地址

http://dl.google.com/android/ADT-10.0.0.zip

 

下载下列文件时加前缀 
https://dl-ssl.google.com/android/repository/

API 2
android-1.1_r1-windows.zip
android-1.1_r1-macosx.zip
android-1.1_r1-linux.zip

API 3
android-1.5_r03-windows.zip
android-1.5_r03-linux_x86.zip
android-1.5_r03-mac_x86.zip
google_apis-3-r03.zip 

API 4
android-1.6_r02-windows.zip
android-1.6_r02-linux.zip
android-1.6_r02-macosx.zip
google_apis-4_r02.zip

API 5
android-2.0_r01-windows.zip
android-2.0_r01-linux.zip
android-2.0_r01-macosx.zip
google_apis-5_r01.zip

API 6
android-2.0.1_r01-linux.zip
android-2.0.1_r01-macosx.zip
android-2.0.1_r01-windows.zip
google_apis-6_r01.zip

API 7
android-2.1_r01-windows.zip
samples-2.1_r01-linux.zip
android-2.1_r01-macosx.zip
google_apis-7_r01.zip

 

API 8

android-2.2_r02-windows.zip

android-2.2_r02-macosx.zip

tools
tools_r05-windows.zip
tools_r05-linux.zip
tools_r05-macosx.zip

usb_d
usb_driver_r03-windows.zip

解决Android屏幕方向变化的问题

作为一个Android开发新手,当我们在开发的时候面对一个大问题

“处理屏幕方向变化“

这个问题的原因是什么?

那么它会导致许多问题如下

   1。只要我们改变方向,它就会创建一个新的Activity
   2。如果在播放音频文件,这将重新载入两次文件,这将同时播放两个同样的歌
   3。导致内存管理问题。
   4。如果你有一个20字段的表单,填写了15个字段,就会丢失15个字段里的内容

那么如何解决这个问题。谷歌在manifest.xml一行代码解决问题

添加这行代码到Activity属性来解决这个问题。
android:configChanges=”orientation”

这样也行
<activityandroid:label=”@string/app_name”android:configChanges=”orientation”

android:name=”.com.androidpeople”>

现在你是完全从这个方向变化问题的自由

Android程序启动画面

public class SplashScreenTest extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    /** set time to splash out */
    final int welcomeScreenDisplay = 3000;
    new Handler().postDelayed(new Runnable(){
       @Override
       public void run() {
           Intent mainIntent = new Intent(SplashScreenTest.this,MainActivity.class);
           startActivity(mainIntent);
           finish();
       }
      }, welcomeScreenDisplay);
    }
}
public class MainActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView textView = new TextView(this);
    textView.setText(“Main Activity”);
    setContentView(textView);
  }
}

svn checkout https://myandroidcode.googlecode.com/svn/trunk/SplashScreenTest

源代码
http://code.google.com/p/myandroidcode/source/browse/trunk/SplashScreenTest