點擊我有一個簡單的Android屏幕,該屏幕由一個按鈕,如下圖所示打開本地的HTML文件時,按鍵上的Android
我也有一個本地webpage
命名存儲在我的assets
文件夾中的android上webpage.html
工作室。
當Android的屏幕上button
被點擊,我要開,我已經存儲在本地的網頁。如果我嘗試打開http://www.google.com
,它工作得很好。但是現在打開任何本地頁面似乎都有問題。以下是我的MainActivity.java
代碼片段 -
//click this button to open a web page
public void onOpenWebBrowser(View v)
{
Intent webPageIntent = new Intent(Intent.ACTION_VIEW);
webPageIntent.setData(Uri.parse("/Users/user/AndroidStudioProjects/ProjectName/app/src/main/assets/webpage.html"));
try {
startActivity(webPageIntent);
} catch (ActivityNotFoundException ex) {
// can do something about the exception.
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
這裏是我的activity_main.xml
文件的內容 -
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="onOpenWebBrowser"
android:text="Open Web Browser" />
</RelativeLayout>
PS - 該網頁能正常工作時,如果我從外面打開它,在一個br owser。請幫忙!
你試圖打開一個默認的Web瀏覽本地頁面你的手機應用程序正確嗎?不在WebView上? – user1506104
是的,我正在嘗試使用手機的默認網頁瀏覽器,但是我已經使用了一個webView,在我已經拉出了很多我的頭髮之後! @ user1506104 – TheLuminor
可能的[從資產文件夾中打開HTML文件]的重複(http://stackoverflow.com/questions/29939174/open-html-file-from-assets-folder) – user1506104