我借助http://www.vogella.com的链接和进一步搜索解决了我的问题。
• Android 清单:
<uses-sdk android:minSdkVersion="8" />
<supports-screens android:resizeable="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:process="IPP.EZPadd">
<activity
android:label="@string/app_name"
android:name=".EZPaddActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
• Java 活动:
public void open_on_start()
{
Intent i = getIntent();
Uri data = i.getData();
if (data == null)
{
return;
}
URL url;
String startFile = "";
try
{
url = new URL(data.getScheme(), data.getHost(), data.getPath());
startFile = url.toString().replace("file:", "");
}
catch (Exception ex)
{
Toast.makeText(this, "Error:\n" + ex.getMessage().toString(), Toast.LENGTH_LONG).show();
return;
}
if (startFile == null)
{
return;
}
StringBuilder text = new StringBuilder();
can = false;
sel = false;
try
{
file = new File(CurDir, startFile);
reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null)
{
text.append(line);
text.append('\n');
}
}
catch (Exception e)
{
Toast.makeText(this, "Error:\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show();
}
TextEditor.setText(text);
FileName.setText(startFile);
}
谢谢西蒙的链接,这很有帮助。起初我只是略过它,这就是为什么我遇到了它没有加载文件的问题。