Kha*_*ogo 18 pdf android external
我想创建一个程序,打开没有外部应用程序的文档.我需要这个,因为我想用手机方向滚动文件(Pitch and Roll).我在屏幕底部创建了一个按钮,当我按住按钮时,我也可以滚动文档.如果我松开按钮,我无法滚动它.因此,如果我使用外部应用程序打开文档,我的按钮会消失,而sensorManager也不会工作.
有人有任何想法来解决这个问题.或者有任何想法,如何滚动文档,在外部应用程序中打开,我的手机方向?
(对不起我的英语不好)
这是我的表现:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.orientationscrolling"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.orientationscrolling.MainActivity"
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>
Run Code Online (Sandbox Code Playgroud)
这是我的布局:
<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"
android:orientation="vertical" >
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
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"
android:gravity="bottom"
android:orientation="vertical" >
<Button
android:id="@+id/mybutt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="Scroll!!"
android:layout_gravity="right"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
button = (Button) findViewById( R.id.mybutt );
String pdf = "http://www.pc-hardware.hu/PDF/konfig.pdf";
String doc="<iframe src='http://docs.google.com/gview?embedded=true&url=http://www.pc-hardware.hu/PDF/konfig.pdf' width='100%' height='100%' style='border: none;'></iframe>";
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.loadData( doc , "text/html", "UTF-8");
}
Run Code Online (Sandbox Code Playgroud)
edw*_*win 24
但是有一种方法可以在不调用另一个应用程序的情况下显示PDF
这是一种在Android应用程序中显示PDF的方法,该方法使用来自的支持将PDF文档嵌入到android webview中http://docs.google.com/viewer
伪
String doc="<iframe src='http://docs.google.com/viewer?url=+location to your PDF File+'
width='100%' height='100%'
style='border: none;'></iframe>";
Run Code Online (Sandbox Code Playgroud)
样品如下所示
String doc="<iframe src='http://docs.google.com/viewer?url=http://www.iasted.org/conferences/formatting/presentations-tips.ppt&embedded=true'
width='100%' height='100%'
style='border: none;'></iframe>";
Run Code Online (Sandbox Code Playgroud)
码
WebView wv = (WebView)findViewById(R.id.webView);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginsEnabled(true);
wv.getSettings().setAllowFileAccess(true);
wv.loadUrl(doc);
//wv.loadData( doc, "text/html", "UTF-8");
Run Code Online (Sandbox Code Playgroud)
并在清单中提供
<uses-permission android:name="android.permission.INTERNET"/>
Run Code Online (Sandbox Code Playgroud)
看到这个
警告:我不知道各种Android版本的兼容性问题
在这种方法中,缺点是您需要互联网连接.但我认为它满足您的需求
编辑尝试将其作为iframe的src
src="http://docs.google.com/gview?embedded=true&url=http://www.pc-hardware.hu/PDF/konfig.pdf"
Run Code Online (Sandbox Code Playgroud)
试试wv.loadData( doc , "text/html", "UTF-8");.两者都适合我


| 归档时间: |
|
| 查看次数: |
83413 次 |
| 最近记录: |