在应用程序启动时播放.swf [英] playing .swf on application startup
问题描述
我希望当android用户点击应用程序图标并启动应用程序时播放.swf文件,之后我想启动应用程序的活动。这是我的想法和我迄今为止所做的。
import android.app.Activity;
导入android.content.Intent;
导入android.os.Bundle;
导入android.os.Handler;
导入android.webkit.WebView;
导入android.webkit.WebSettings.PluginState;
public class Splash_Screen extends Activity {
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState){
// TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.startup);
新的Handler()。postDelayed(新的Runnable(){
$ b $ * / b
*用计时器显示启动画面。 $ b *要显示您的应用徽标/公司
* /
@Override
public void run(){
//此方法将被执行一次计时器超过
//开始你的应用程序的主要活动
字符串localUrl =file:///android_asset/Kiss-o-meter.swf;
WebView wv = (WebView)findViewById(R.id.webview);
wv.getSettings()。setPluginState(PluginState.ON);
wv.loadUrl(localUrl);
Intent yes_krao = new Intent(Splash_Screen.this,KissingMeter.class);
startActivity(yes_krao);
finish();
}
},SPLASH_TIME_OUT);
$ b $ / code $ / pre
$ b $ p 这是我的xml文件:
<?xml version =1.0encoding =utf-8?>
< LinearLayout xmlns:android =http://schemas.android.com/apk/res/android
android:orientation =vertical
android:layout_width =fill_parent
android:layout_height =fill_parent>
< WebView android:id =@ + id / webview
android:layout_width =fill_parent
android:layout_height =fill_parent/>
< / LinearLayout>
有什么问题吗?好像代码不工作!其次是 setPluginsEnabled(true); 也不会被eclipse拾取!
解决方案 startActivity(yes_krao)
会在您加载 WebView
之后立即调用,因此应用程序将在您的.swf有机会之前切换活动玩。一个解决方案是实现一个处理程序,并切换活动后的持续时间你的.swf文件。
例如:
import android.app 。活动;
导入android.content.Intent;
导入android.os.Bundle;
导入android.os.Handler;
导入android.webkit.WebView;
导入android.webkit.WebSettings.PluginState;
public class Splash_Screen extends Activity {
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState){
// TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.startup);
String localUrl =file:///android_asset/Kiss-o-meter.swf;
WebView wv =(WebView)findViewById(R.id.webview);
wv.getSettings()。setPluginState(PluginState.ON);
wv.loadUrl(localUrl);
新的Handler()。postDelayed(新的Runnable(){
$ b $ * / b
*用计时器显示启动画面。 $ b *要显示您的应用徽标/公司
* /
@Override
public void run(){
//此方法将被执行一次定时器超过
//开始你的应用程序的主要活动
Intent yes_krao = new Intent(Splash_Screen.this,KissingMeter.class);
startActivity(yes_krao);
finish() ;
}
},SPLASH_TIME_OUT);
请注意 setPluginsEnabled()已被弃用,因此您应该使用 setPluginState():
WebSettings webSettings = yourWebView.getSettings ();
webSettings.setPluginState(PluginState.ON);
I want that i play .swf file when the android user clicks on the application icon and the application starts and after that i want to start the application's activity. Here is what i thought and what i have done until now.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebView;
import android.webkit.WebSettings.PluginState;
public class Splash_Screen extends Activity {
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.startup);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
String localUrl ="file:///android_asset/Kiss-o-meter.swf";
WebView wv=(WebView) findViewById(R.id.webview);
wv.getSettings().setPluginState(PluginState.ON);
wv.loadUrl(localUrl);
Intent yes_krao = new Intent(Splash_Screen.this, KissingMeter.class);
startActivity(yes_krao);
finish();
}
}, SPLASH_TIME_OUT);
}
}
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Is there anything wrong with it?? seems like the code is not working! secondly setPluginsEnabled(true); is also not being picked up by eclipse!
解决方案 startActivity(yes_krao)
is called immediately after you have loaded the WebView
so the application will switch Activities before your .swf has a chance to play. One solution would be to implement a Handler and switch Activities after the duration of your .swf file.
E.g.:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebView;
import android.webkit.WebSettings.PluginState;
public class Splash_Screen extends Activity {
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.startup);
String localUrl ="file:///android_asset/Kiss-o-meter.swf";
WebView wv=(WebView) findViewById(R.id.webview);
wv.getSettings().setPluginState(PluginState.ON);
wv.loadUrl(localUrl);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent yes_krao = new Intent(Splash_Screen.this, KissingMeter.class);
startActivity(yes_krao);
finish();
}
}, SPLASH_TIME_OUT);
}
}
Note that setPluginsEnabled() has been deprecated, so you should use setPluginState():
WebSettings webSettings = yourWebView.getSettings();
webSettings.setPluginState(PluginState.ON);
这篇关于在应用程序启动时播放.swf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!