【发布时间】:2018-09-26 16:10:20
【问题描述】:
我为智能手表制作了一个 Android 应用程序,以全屏显示现有的 HTML5 网页,该网页交替使用实时时钟和带有进度条的事件,该事件仍将运行多长时间(可以在www.janvangalen.nl。 然而,智能手表会回到睡眠模式(这是有意的),但我无法让应用程序继续在后台运行。振动(通知新活动)不起作用,激活手表显示时钟仍在运行,但活动仍然是入睡时的活动。
我在 Android Studio 中开发,以下文件是我的应用程序的基础。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.janvangalen.www.imagewatch">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
acitvity.fullscreen.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:background="#0099cc"
tools:context=".FullscreenActivity">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<WebView
android:id="@+id/activity_fullscreen_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
最后:
**FullscreenActivity.java**
package nl.janvangalen.www.imagewatch;
import android.annotation.SuppressLint;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class FullscreenActivity extends AppCompatActivity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
if (getSupportActionBar() != null)
getSupportActionBar().hide();
//Remove notification bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_fullscreen);
mWebView = (WebView) findViewById(R.id.activity_fullscreen_webview);
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("https://www.janvangalen.nl");
}
}
我还找到了如何让应用程序在后台运行并创建一个新的 .java 的方法(第二个公共类)。但是,在下面的代码中,我不知道要输入什么才能使其正常工作。
package nl.janvangalen.www.smartwatch;
import android.app.IntentService;
import android.content.Intent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import nl.janvangalen.www.imagewatch.R;
public class RSSPullService extends IntentService {
@Override
protected void onHandleIntent(Intent workIntent) {
// Gets data from the incoming Intent
String dataString = workIntent.getDataString();
// ...
// Do work here, based on the contents of dataString
}
}
那里需要做什么工作,因为工作已经在全屏脚本中完成。
有人可以帮我吗?
【问题讨论】:
标签: java android html background fullscreen