0
我有一個非常簡單的webview佈局。Android在特定時間或日期定期更改webview內容
我想每1小時更換一次webview內容。
儘量選用
Uri uri = Uri.parse("http://www.yahoo.com");
Intent in = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(in);
在廣播接收機
,但未能.....
任何sugguestions?謝謝!!!!
主要活動代碼:
public class MainActivity extends Activity implements OnClickListener {
private int page;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout layout = (RelativeLayout)
findViewById(R.id.RelativeLayout1);
layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
showeb("http://www.google.com");
Intent intent =new Intent(MainActivity.this, Alarm.class);
intent.setAction("repeating");
PendingIntent sender=PendingIntent
.getBroadcast(MainActivity.this, 0, intent, 0);
long firstime=SystemClock.elapsedRealtime();
AlarmManager am=(AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP
, firstime, 3600*1000, sender);
}
private void showeb(String string) {
WebView engine = (WebView) (findViewById(R.id.webView1));
engine.setWebViewClient(new WebViewClient());
engine.loadUrl(string);
}
和接收機類
public class Alarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "short alarm", Toast.LENGTH_LONG).show();
Uri uri = Uri.parse("http://www.yahoo.com");
Intent in = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(in);
}
對不起,bu我應該在哪裏放這些代碼?我可以設置webview在特定的日期和時間更改嗎? (例如週一下午5點)非常感謝!!!!! – 2013-03-07 02:05:39
你只需要重寫Activity的onResume()方法。可以在代碼中定期檢查,然後與您的Mon,5PM比較並在必要時重新加載。 – MartinC 2014-02-28 09:08:00