權限的開放,在AndroidManifest.xml加入

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

文章標籤

痞客興 發表在 痞客邦 留言(0) 人氣()

MainActivity.java

package tw.idv.charleslin74.sdcardreadwritetest;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    @Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView showerror = (TextView) findViewById(R.id.showerror);
        String aaa = Environment.<em>getExternalStorageDirectory</em>().getPath();
        showerror.setText(aaa);
    }
}

activity_main.xml

文章標籤

痞客興 發表在 痞客邦 留言(0) 人氣()

寫入資料

FileOutputStream fout = openFileOutput("myfile.txt",MODE_PRIVATE);
BufferedOutputStream buffout = new BufferedOutputStream(fout);
buffout.write("這是測試".getBytes());
buffout.close();

讀取資料

文章標籤

痞客興 發表在 痞客邦 留言(0) 人氣()

寫入資料

SharedPreferences spToDo = getSharedPreferences("prefile",MODE_PRIVATE);
spToDo.edit().putString("username","superman").commit();

放進資料的方式有putBoolean,putFloat,putInt,putLong,putString,依需求自已改變.

文章標籤

痞客興 發表在 痞客邦 留言(0) 人氣()

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
文章標籤

痞客興 發表在 痞客邦 留言(0) 人氣()

package com.example.charleslin.keybackalarm;

文章標籤

痞客興 發表在 痞客邦 留言(0) 人氣()

有時我們在頁面裡放的內容,有可能會超過頁面所能承載,這時就必須用到第二個頁面來顯示.

但你可以試試,android就只顯示第一個頁面,其他的內容你是看不到的.

文章標籤

痞客興 發表在 痞客邦 留言(0) 人氣()

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
文章標籤

痞客興 發表在 痞客邦 留言(0) 人氣()

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.charleslin.playlivevideo" >
    <uses-permission android:name="android.permission.INTERNET" >
    </uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|screenSize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".VideoViewActivity"
            android:configChanges="orientation|screenSize" >
        </activity>
    </application>
</manifest>

MainActivity.java

文章標籤

痞客興 發表在 痞客邦 留言(0) 人氣()

如果你的APP是一個靜態頁面的話,它想刷新就讓它刷新,但是如果你頁面的資料是來自網路上或者你正在看影片聽音樂,轉個螢幕就重新看重新聽,你不被使用者打死才怪.

那為什麼轉個螢幕就必須重新開始呢??

痞客興 發表在 痞客邦 留言(0) 人氣()