activity上延时操作以及一次性启动

来源:互联网 发布:巨人网络私有化 编辑:程序博客网 时间:2024/04/29 15:59

package com.huawei.setupdata;

import java.util.Timer; 
import java.util.TimerTask; 

import android.app.Activity;
import android.os.Bundle;
import android.content.pm.PackageManager;
import android.content.Intent;
import android.content.ComponentName;
import android.util.Log;

public class SetupDataConnectionActivity extends Activity {
    private static final String RequestMobileData_IS_FIRST_RUN = "RequestMobileFirstRun";

    @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  Timer timer = new Timer();
  TimerTask tast = new TimerTask() {

   public void run() {
    Intent mIntent = new Intent("com.android.net.wifi.SETUP_WIFI_NETWORK");
          mIntent.putExtra(RequestMobileData_IS_FIRST_RUN, true);
    startActivity(mIntent);
          finish();
   }
  };
  timer.schedule(tast, 11000);
 }
   
    @Override
    protected void onDestroy() {
        super.onDestroy();
        PackageManager pm = getPackageManager();
        ComponentName cn = new ComponentName(this, SetupDataConnectionActivity.class);
        pm.setComponentEnabledSetting(cn, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
    }
}

 

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.huawei.setupdata"
    android:versionCode="1"
    android:versionName="1.0" >
   
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <receiver android:name=".myReceive">
            <intent-filter android:priority="100" >
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.SIM_STATE_CHANGED" />
            </intent-filter>
        </receiver>
        <activity android:name=".SetupDataConnectionActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >  // 全屏显示  不显示信号栏
            
            <intent-filter android:priority="8">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
 
       
    </application>

</manifest>