

●程式參考(GitHub):利用HttpURLConnection、InputStream、BufferReader存取網路資源
●程式參考(GitHub):利用HttpURLConnection、InputStream、BufferReader存取網路資源
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
int permission = ActivityCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE); if (permission != PackageManager.PERMISSION_GRANTED) { //未取得權限,向使用者要求允許權 //因為要辨別使用者允許的是寫入還是讀取所以這邊的string只放write ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_STORAGE); }else{ //已有權限,可進行檔案存取 sdwrite(); } } @Override public void onRequestPermissionsResult (int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if(requestCode==REQUEST_EXTERNAL_STORAGE){ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { //取得權限,進行檔案存取 String str=permissions[0]; //這邊用if判斷時要用equals(),不能用== if(str.equals("android.permission.WRITE_EXTERNAL_STORAGE") ){ sdwrite(); }else { sdread(); } } else { //使用者拒絕權限,停用檔案存取功能 } } } private void sdwrite(){ File f = Environment.getExternalStorageDirectory(); Log.d("FNAME","read"+f.getAbsolutePath()); File f2 = new File(f.getAbsolutePath() + File.separator + "mydata"); f2.mkdir(); File txtFile = new File(f2.getAbsolutePath() + File.separator + "data5.txt"); try { FileWriter fw = new FileWriter(txtFile); BufferedWriter bw = new BufferedWriter(fw); bw.write("this is test"); bw.newLine(); bw.write("This is test2"); bw.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } public void nolimitread(View view) { int permission = ActivityCompat.checkSelfPermission(this, READ_EXTERNAL_STORAGE); if (permission != PackageManager.PERMISSION_GRANTED) { //未取得權限,向使用者要求允許權 ActivityCompat.requestPermissions(this, new String[]{READ_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_STORAGE); }else{ //已有權限,可進行檔案存取 sdread(); } } private void sdread(){ File f = Environment.getExternalStorageDirectory(); Log.d("FNAME", f.getAbsolutePath()); File f2 = new File(f.getAbsolutePath() + File.separator + "mydata"); File txtFile = new File(f2.getAbsolutePath() + File.separator + "data5.txt"); try { FileReader fr = new FileReader(txtFile); BufferedReader br = new BufferedReader(fr); String str; while ((str=br.readLine()) != null) { Log.d("FNAME", "Read:" + str); } br.close(); fr.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
●程式參考(GitHub):讀寫外部資料與設定讀寫外部資料權限
●補充說明和程式說明
(一) 檔案的讀取使用FileReader比較不好用,因為讀出來會是字元陣列,一般會使用BufferedReader和BufferedWriter=>可以直接處理字串
想在痞客邦部落格的側欄產生自訂的圖片或文字連結其實不難,
因為痞客邦側邊欄位是支援HTML語法的
以上圖為例,我放了兩個自訂圖片連結,作法如下:
(一)到痞客邦部落格後台,開啟側欄管理功能
(二)在最右邊版位站存區,點新增版位
就會跳出新增自訂欄位對話框
(三)在標題輸入想要顯示的標題,內容則要將HTML語法貼入,
關於語法的說明,請參照最下方
(四)完成以後,將自訂的側邊欄位拖曳到想要放置的位置就完成囉!
HTML語法教學
1.插入圖片與連結
範例:
<a target="_blank" href="https://play.google.com/store/apps/details?id=com.maggie.flashcard_sql"><img border="0" width="150" height="150" src="https://pic.pimg.tw/muchone/1557887451-1848048953.jpg"></a>
說明:
如果覺得太複雜,直接用下面的方式就可以
<a target="_blank" href="要開啟的網站連結位址"><img src="圖片來源位址"></a>
下面是可自行選擇要不要加入的html語法:
target="_blank":這是要把連結另開新視窗的意思
border="0" :這是設定圖片不要有框
width="150" :設定圖片寬度為150
height="150":設定圖片高度為150
2.加入文字的一些小變化:
範例:
<div><FONT SIZE="3" COLOR="#007FFF">OCR文字辨識掃描與翻譯</FONT></div>
如果覺得太複雜,直接用下面的方式就可以
<div>"文字內容"</div>
=>使用<div></div>包住文字,可以讓文字換行
下面是可自行選擇要不要加入的html語法
FONT SIZE="3":設定文字大小
COLOCR="#007FFF":設定文字顏色
*如果想要做更多變化可以參考下列HTML語法網址
http://www.w3school.com.cn/html/index.asp
https://www.w3schools.com/html/
*顏色的16進位碼不知道,可以參考下面網站有一些列表
https://www.ebaomonthly.com/window/photo/lesson/colorList.htm
6/1
Today's Taekwondo class starting time is changed to the 7:00 pm.
We can finally do everything we want to do on Saturday and don't have to be in a hurry to the class.
We made origame, played catch, read books and watch the Captain Marvel.
6/2
My husband's going to Germany on business for a week.
On the way driving to the bus stop, my son kept talking 'I don't want to let you go, Dad'.
And now, I start to miss my husband, too.
6/3
Again, I didn't sleep well last night and I thought that might becasue I was not used to my husband not by my side.
I've thought my boss and my supervisor don't communicate well with each other.
Therefore, I usually don't know whose decisions shold I obey.
6/4
We had a new coworker join our team yesterday.
I feel a little bit happy and worried.
I worry that I can't get along with him.
6/5
I stayed up late reading a novel last night.
I didn't sleep util 2:40 am and I could barely keep my eyes open this morning.
My son cried because he didn't get ready as fast as usual this morning.
6/6
I received the tv box bought from pchome this morning and finally could test my app.
And after that, my supervisor gave me a source code of face recognition and told me I was charge of maintaining and developing it.
I think I'm going to be very busy soon.
6/7
I found my son's watch was gone again this morning and my son didn't remember where his watch was.
I felt very angry and helpless at that moment.
I want to know is there anything could help him understand he should cherish his possessions.
6/8
My husband came back from Germany yesterday afternoon.
His luggage was almost overweight because I gave a long shopping list of what I wanted him to buy for me.
Only two items of my shopping list he couldn't buy and I really appreciated it.
6/9
The Dragon Boat Festival long weekend is over, but I still can't get back into the work mode.
Sometimes I really want to take a day off to sleep all day long at home.
However, my job tenure is less than one year and I don't have enought annual leave.
6/10
My ex-coworker had a fight with our HR specialist last Thursday
After a long weekend, our HR specialist is still not over it.
She was as mad as a wet hen because she thought we all spoke ill of her behind her back.
*be in a hurry to:趕著做..
* make origame:摺紙
*play catch:玩丟接球
*Captain Marvel:驚奇隊長
*go to somewhere on business:去somewhere出差
*it might because:可能因為
*obey:遵守
*get along with sb:和sb相處得很好
*stay up late:熬夜
*helpless:無助,無奈
*my luggage is overweight:我的行李超重
*shopping list:購物清單
*Dragon Boat Festival:端午節
*long weekend:包含周末的連假
*get back into the work mode:收心
*take a day off:請假
*job tenure:工作年資
*annual leave:特休
*be still not over it:耿耿於懷
*be as mad as a wet hen:氣得哇哇大叫
*speak ill of someone behind someone's head:在背後說someone的壞話
●補充說明和程式說明---檔案存取
●程式參考(GitHub):使用FileWriter和FileReader做檔案(File)的讀取與寫入
●程式參考(GitHub):檔案存取(四)SettingsActivity與PreferenceActivity
●畫面預覽:
●補充說明:
Key
|
Value
|
username
|
John
|
tel
|
123
|
Key |
Value
|
TPE
TC
KH
|
02
04
07
|
Key
|
Value
|
city
code
|
台北
02
|
Key
|
Value
|
city
code
|
台中
04
|
Key
|
Value
|
city
code
|
高雄
07
|
●程式與說明--java code
●程式參考(GitHub):檔案存取(三)HashMap與SimpleAadapter
5/22
I heard a piece of very good news this morning and I was so happy that I almost cried.
My son won the second prize of the English story-telling contest held by his school.
Today was really my son's day and I believed he would be happy all day long.
5/23
Today is a busy day.
I thought my boss would be in office this morning and be absent in the afternoon.
However, he was out of office this morning and came in office afternoon and that ruined my plan.
5/24
Every time my period is coming, I feel tired and have a headache.
More than that, I have cramps on my period almost every time.
At that moment, I always wish that I was a man.
5/25
My son lent his friend his Garmin watch on Friday and I didn't knew that until Saturday morning.
I was very angry at my son for his not cherishing his possessions.
Both my husband and I thought his watch might not be returned anyway.
5/26
My son always get up early on the weekend.
I feel very confused that he always looks tired on weekdays.
Why doesn't he sleep a bit longer on the weekend?
5/27
We went to see the Pokémon Detective Pikachu yesterday and that movie was really funny.
However, my son was still terrified of the bad guy in the movie.
He had a nightmare last night and I didn't want to take him to see movies in the movie theater anymore.
5/28
As I expected, my son's watch wasn't returned by his classmate yesterday.
It has been cold one day and hot the next recently.
That makes me can't have good night's sleep.
5/29
My son's watch was returned by the woman who takes care of children on the school bus.
At that moment, I realized my son lied to me again.
He forgot ask his classmate to return his watch and he was afraid I gave him a piece of my mind.
5/30
It became so cold last night that I didn't sleep well.
I have had some difficulty developing app recently.
However, my boss wants me to demo the app everyday and that is a bit annoying.
5/31
Finally, I solved the problem of playing the rtsp on my Android application.
Hope today is a happy Friday and that means my boss will be out of office all day long.
I've been too busy to keep writing my blog posts recently.
*win the second prize:贏得第二名
*on one's period:生理期
*have cramps:生理痛
*be angry at sb. for sth.:為了某事對某人生氣
*cherish one's possessions:珍惜某人的財物
*on the weekend:在周末
*on weekdays:在平日
*be terrified of:很害怕
*It's cold one day and hot the next:天氣忽冷忽熱
*have good night's sleep:晚上睡得好
*give sb a piece of your mind:教訓sb.
*have some difficulty (in) Ving:在做...遇到一些困難
*write a blog post:寫部落格
●畫面預覽:
●補充說明:
AdapterView
and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View
for each item in the data set.
●程式與說明--java code
lv = (ListView) findViewById(R.id.lv);
adp=new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, ar);
registerForContextMenu(lv);
lv.setAdapter(adp);
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick
(AdapterView<?> adapterView, View view, int i, long l) {
index=i;
//如果定return true就不會跳出contextmenu
//true if the callback consumed the long click, false otherwise
return false;
}
});
●程式參考(GitHub):檔案存取(二)Adapter與ListView