我有一個紮根Android手機,我的客戶端有8個平板電腦(Unrooted)。他們將在明天晚上使用它來從Android平板電腦做一些比賽。我製作了一個應用程序,可以從我的內部存儲器的根文件夾中的自定義文件夾中讀取文件,該文件夾可以在我的根移動設備上運行良好,但無法在客戶端無根內存片上運行。無法從內部根存儲中讀取文件
根據他們所有的文件將高達3GB存儲在內部存儲器。我被卡住了,他們真的需要幫助,並建議我應該怎麼做?
public class MainActivity extends AppCompatActivity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
ImageView welcomeLogo = (ImageView) findViewById(R.id.welcomeLogo);
welcomeLogo.setImageResource(R.drawable.iba);
//Get the text file
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
File file = new File(dir, "lvi/names.txt");
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
//Find the view by its id
TextView tv = (TextView)findViewById(R.id.welcomeJudge);
//Set the text
tv.setText("Welcome " + text.toString());
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//When the enter button is click goto the dashboard activity
button = (Button) findViewById(R.id.btnEnter);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent dashboardIntent = new Intent(MainActivity.this, dashboard.class);
startActivity(dashboardIntent);
}
});
}
}
我艙單權限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
你想從內部存儲讀取文件嗎?你正在使用'Environment.getExternalStorageDirectory()'。 – badjr
@badjr是來自內部存儲器 –
@badjr是正確的,您沒有使用內部存儲,第二件事是如果客戶端平板電腦的API級別爲23或以上,他們可能因爲權限而獲得'SecurityException'。他們是否有任何崩潰或什麼?請詳細說明。 –