Android Boot auto-start app does not lock screen

Source: Internet
Author: User

Main reference: http://life173.blog.51cto.com/2035365/543916/

Realize the function, start the firstactivity automatically after boot, and do not have to unlock.

Paste out the source code:

This is mainly configured in the configuration file:

  <receiver android:enabled= "true"  android:name= " . Bootupreceiver "            android:permission=" Android.permission.RECEIVE_BOOT_COMPLETED ">             <intent-filter>                     <action android:name= "Android.intent.action.BOOT_ Completed " />                     <category android:name= "Android.intent.category.DEFAULT"  / >            </intent-filter>       </receiver> 
and add Permission:   <uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"  />    whole Source: <manifest xmlns:android= "Http://schemas.android.com/apk/res/android"      package= "Com.example.activitytest"     android:versioncode= "1"      android:versionname= "1.0"  >    <uses-sdk         android:minsdkversion= "8"         android: targetsdkversion= " />   <uses-permission android:name=" Android.permission.RECEIVE_BOOT_COMPLETED " />      <application         android:allowbackup= "true"          android:icon= "@drawable/ic_launcher"         android:label= "@ String/app_name "      &Nbsp; android:theme= "@style/apptheme"  >        < Activity             android:name= ". Firstactivity "             android:label=" This is my first activity " >                 <intent-filter >                  <action android:name= " Android.intent.action.MAIN "/>                  <category android:name= "Android.intent.category.LAUNCHER"/>              </intent-filter>                                  </activity>        <receiver android:enabled = "true"  android:name= ". Bootupreceiver "            android:permission=" Android.permission.RECEIVE_BOOT_COMPLETED ">             <intent-filter>                     <action android:name= "Android.intent.action.BOOT_ Completed " />                     <category android:name= "Android.intent.category.DEFAULT"  / >            </intent-filter>             </receiver>             </application></manifest>

Add Bootupreceiver class, firstactivity is the activity you want to start;

package com.example.activitytest;import android.content.broadcastreceiver;import  Android.content.context;import android.content.intent;public class bootupreceiver extends  BroadcastReceiver {     @Override     public void  OnReceive (context context, intent intent)  {         // TODO Auto-generated method stub          intent i = new intent (Context,firstactivity.class);          i.addflags (Intent.flag_activity_new_task);          context.startactivity (i);     }} The class to start:firstactivity.java package  com.example.activitytest;import android.app.activity;import android.content.intent;import  Android.net.uri;import android.os.bundle;import android.view.menu;import android.view.menuitem;import android.view.view;import  Android.view.view.onclicklistener;import android.widget.button;import android.widget.toast;public  class FirstActivity extends Activity {     @Override      protected void oncreate (bundle savedinstancestate) {         super.oncreate (savedinstancestate);         // Requestwindowfeature (window.feature_no_title);//To use menu  comment out this sentence          getwindow (). SetFlags (windowmanager.layoutparams.flag_dismiss_keyguard,                 windowmanager.layoutparams.flag_dismiss_ Keyguard)//Boot not lock screen   set          setcontentview (R.layout.first_ layout);         button button1 =  (Button) Findviewbyid (r.id.button_1);         button1.setonclicklistener (New onclicklistener () {              @Override              public void onclick (VIEW&NBSP;V) {                 //toast.maketext (Firstactivity.this, "you click  Button1 ",  toast.length_short). Show ();                 intent intent = new intent (Intent.ACTION_VIEW);                 intent.setdata (Uri.parse (" Http://www.baidu.com "));//setdata, set data tag    mostly Tel, this can't be less                    startactivity (Intent);             }        });             }     @Override     public  Boolean oncreateoptionsmenu (Menu menu) {         Getmenuinflater (). Inflate (R.menu.main, menu);        return  true;//allow created menus to be displayed     }     @Override     public  boolean onoptionsitemselected (Menuitem item) {         Switch (Item.getitemid ()) {        case r.id.add_item:             toast.maketext (this,  "You click add ", Toast.length_short). Show ();             break;         case R.id.remove_item:             Toast.maketext (this,  "You click remove",  toast.length_short). Show ();             break;         default: break;        }         return true;    }      }

PS: Start the app, you need to solve the screen after a while to start, to start the app will take some time.

In fact, you can also set the lock screen when booting up.

GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);//boot-lock screen settings are placed in front of this.

Setcontentview (r.layout.first_layout);

This article is from the "7124048" blog, please be sure to keep this source http://7134048.blog.51cto.com/7124048/1833406

Android Boot auto-start app does not lock screen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.