十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
分以下幾個步驟:
南陵網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,南陵網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為南陵上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的南陵做網(wǎng)站的公司定做!
首先對manifest注冊SD卡讀寫權(quán)限
AndroidManifest.xml?
?xml?version="1.0"?encoding="utf-8"??
manifest?xmlns:android="
package="com.tes.textsd"?
android:versionCode="1"?
android:versionName="1.0"??
uses-sdk?
android:minSdkVersion="8"?
android:targetSdkVersion="16"?/?
uses-permission?android:name="android.permission.WRITE_EXTERNAL_STORAGE"/?
application?
android:allowBackup="true"?
android:icon="@drawable/ic_launcher"?
android:label="@string/app_name"?
android:theme="@style/AppTheme"??
activity?
android:name="com.tes.textsd.FileOperateActivity"?
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
創(chuàng)建一個對SD卡中文件讀寫的類
FileHelper.java?
/**?
*?@Title:?FileHelper.java?
*?@Package?com.tes.textsd?
*?@Description:?TODO(用一句話描述該文件做什么)?
*?@author?Alex.Z?
*?@date?2013-2-26?下午5:45:40?
*?@version?V1.0?
*/?
package?com.tes.textsd;?
import?java.io.DataOutputStream;?
import?java.io.File;?
import?java.io.FileOutputStream;?
import?java.io.FileWriter;?
import?java.io.FileInputStream;?
import?java.io.FileNotFoundException;?
import?java.io.IOException;?
import?android.content.Context;?
import?android.os.Environment;?
public?class?FileHelper?{?
private?Context?context;?
/**?SD卡是否存在**/?
private?boolean?hasSD?=?false;?
/**?SD卡的路徑**/?
private?String?SDPATH;?
/**?當(dāng)前程序包的路徑**/?
private?String?FILESPATH;?
public?FileHelper(Context?context)?{?
this.context?=?context;?
hasSD?=?Environment.getExternalStorageState().equals(?
android.os.Environment.MEDIA_MOUNTED);?
SDPATH?=?Environment.getExternalStorageDirectory().getPath();?
FILESPATH?=?this.context.getFilesDir().getPath();?
}?
/**?
*?在SD卡上創(chuàng)建文件?
*?
*?@throws?IOException?
*/?
public?File?createSDFile(String?fileName)?throws?IOException?{?
File?file?=?new?File(SDPATH?+?"http://"?+?fileName);?
if?(!file.exists())?{?
file.createNewFile();?
}?
return?file;?
}?
/**?
*?刪除SD卡上的文件?
*?
*?@param?fileName?
*/?
public?boolean?deleteSDFile(String?fileName)?{?
File?file?=?new?File(SDPATH?+?"http://"?+?fileName);?
if?(file?==?null?||?!file.exists()?||?file.isDirectory())?
return?false;?
return?file.delete();?
}?
/**?
*?寫入內(nèi)容到SD卡中的txt文本中?
*?str為內(nèi)容?
*/?
public?void?writeSDFile(String?str,String?fileName)?
{?
try?{?
FileWriter?fw?=?new?FileWriter(SDPATH?+?"http://"?+?fileName);?
File?f?=?new?File(SDPATH?+?"http://"?+?fileName);?
fw.write(str);?
FileOutputStream?os?=?new?FileOutputStream(f);?
DataOutputStream?out?=?new?DataOutputStream(os);?
out.writeShort(2);?
out.writeUTF("");?
System.out.println(out);?
fw.flush();?
fw.close();?
System.out.println(fw);?
}?catch?(Exception?e)?{?
}?
}?
/**?
*?讀取SD卡中文本文件?
*?
*?@param?fileName?
*?@return?
*/?
public?String?readSDFile(String?fileName)?{?
StringBuffer?sb?=?new?StringBuffer();?
File?file?=?new?File(SDPATH?+?"http://"?+?fileName);?
try?{?
FileInputStream?fis?=?new?FileInputStream(file);?
int?c;?
while?((c?=?fis.read())?!=?-1)?{?
sb.append((char)?c);?
}?
fis.close();?
}?catch?(FileNotFoundException?e)?{?
e.printStackTrace();?
}?catch?(IOException?e)?{?
e.printStackTrace();?
}?
return?sb.toString();?
}?
public?String?getFILESPATH()?{?
return?FILESPATH;?
}?
public?String?getSDPATH()?{?
return?SDPATH;?
}?
public?boolean?hasSD()?{?
return?hasSD;?
}?
}
寫一個用于檢測讀寫功能的的布局
main.xml?
?xml?version="1.0"?encoding="utf-8"??
LinearLayout?xmlns:android="
android:layout_width="fill_parent"?
android:layout_height="fill_parent"?
android:orientation="vertical"??
TextView?
android:id="@+id/hasSDTextView"?
android:layout_width="fill_parent"?
android:layout_height="wrap_content"?
android:text="hello"?/?
TextView?
android:id="@+id/SDPathTextView"?
android:layout_width="fill_parent"?
android:layout_height="wrap_content"?
android:text="hello"?/?
TextView?
android:id="@+id/FILESpathTextView"?
android:layout_width="fill_parent"?
android:layout_height="wrap_content"?
android:text="hello"?/?
TextView?
android:id="@+id/createFileTextView"?
android:layout_width="fill_parent"?
android:layout_height="wrap_content"?
android:text="false"?/?
TextView?
android:id="@+id/readFileTextView"?
android:layout_width="fill_parent"?
android:layout_height="wrap_content"?
android:text="false"?/?
TextView?
android:id="@+id/deleteFileTextView"?
android:layout_width="fill_parent"?
android:layout_height="wrap_content"?
android:text="false"?/?
/LinearLayout
就是UI的類了
FileOperateActivity.class?
/**?
*?@Title:?FileOperateActivity.java?
*?@Package?com.tes.textsd?
*?@Description:?TODO(用一句話描述該文件做什么)?
*?@author?Alex.Z?
*?@date?2013-2-26?下午5:47:28?
*?@version?V1.0?
*/?
package?com.tes.textsd;?
import?java.io.IOException;?
import?android.app.Activity;?
import?android.os.Bundle;?
import?android.widget.TextView;?
public?class?FileOperateActivity?extends?Activity?{?
private?TextView?hasSDTextView;?
private?TextView?SDPathTextView;?
private?TextView?FILESpathTextView;?
private?TextView?createFileTextView;?
private?TextView?readFileTextView;?
private?TextView?deleteFileTextView;?
private?FileHelper?helper;?
@Override?
public?void?onCreate(Bundle?savedInstanceState)?{?
super.onCreate(savedInstanceState);?
setContentView(R.layout.main);?
hasSDTextView?=?(TextView)?findViewById(R.id.hasSDTextView);?
SDPathTextView?=?(TextView)?findViewById(R.id.SDPathTextView);?
FILESpathTextView?=?(TextView)?findViewById(R.id.FILESpathTextView);?
createFileTextView?=?(TextView)?findViewById(R.id.createFileTextView);?
readFileTextView?=?(TextView)?findViewById(R.id.readFileTextView);?
deleteFileTextView?=?(TextView)?findViewById(R.id.deleteFileTextView);?
helper?=?new?FileHelper(getApplicationContext());?
hasSDTextView.setText("SD卡是否存在:"?+?helper.hasSD());?
SDPathTextView.setText("SD卡路徑:"?+?helper.getSDPATH());?
FILESpathTextView.setText("包路徑:"?+?helper.getFILESPATH());?
try?{?
createFileTextView.setText("創(chuàng)建文件:"?
+?helper.createSDFile("test.txt").getAbsolutePath());?
}?catch?(IOException?e)?{?
e.printStackTrace();?
}?
deleteFileTextView.setText("刪除文件是否成功:"?
+?helper.deleteSDFile("xx.txt"));?
helper.writeSDFile("1213212",?"test.txt");?
readFileTextView.setText("讀取文件:"?+?helper.readSDFile("test.txt"));?
}?
}
安卓手機把軟件寫入系統(tǒng)變?yōu)橄到y(tǒng)軟件的方法:
ROOT安卓手機:可使用360手機助手獲取root權(quán)限
下載安卓RE管理器,然后下載要刷進系統(tǒng)的軟件。
打開RE管理器,把下載好的軟件移動到根目錄,然后再移動到system目錄下。
以百度輸入法為例,修改軟件的權(quán)限然后移動到當(dāng)前目錄下的app目錄中:
長按百度輸入法這個應(yīng)用的apk,會彈出多個選項,找到權(quán)限,修改成如下的方式(修改權(quán)限這個一定要做)。如果下載的RE管理器是英文版的,只要按照下圖的順序就行了。
修改好權(quán)限后,點擊確認(rèn)
然后把軟件的apk移動到這個目錄的APP文件夾里。百度輸入法就算很成功的刷進手機系統(tǒng)里了。
注意:有的手機可能刷入后軟件打不開,或者秒退沒這事因為手機系統(tǒng)的原因,沒有辦法
@Override
public?void?onClick(View?view)?{
String?state?=?Environment.getExternalStorageState();//獲取外部設(shè)備狀態(tài)
//檢測外部設(shè)備是否可用
if(!state.equals(Environment.MEDIA_MOUNTED))?{
Toast.makeText(this,?"外部設(shè)備不可用",?Toast.LENGTH_SHORT).show();
return;
}
//創(chuàng)建文件
File?sdCard?=?Environment.getExternalStorageDirectory();//獲取外部設(shè)備的目錄
File?file?=?new?File(sdCard,"文件名.txt");//文件位置
try?{
FileOutputStream?outputStream?=?new?FileOutputStream(file);//打開文件輸出流
BufferedWriter?writer?=?new?BufferedWriter(new?OutputStreamWriter(outputStream));//寫入到緩存流
writer.write("這里是要寫入到文件的數(shù)據(jù)");//從從緩存流寫入
writer.close();//關(guān)閉流
Toast.makeText(this,?"輸出成功",?Toast.LENGTH_SHORT).show();
}
catch(Exception?exception)?{
Toast.makeText(this,?"輸出失敗",?Toast.LENGTH_SHORT).show();
}
}
寫入到文件管理時需要權(quán)限
uses-permission?android:name="android.permission.WRITE_EXTERNAL_STORAGE"/
[img]