Chinaunix首页 | 论坛 | 博客
  • 博客访问: 138210
  • 博文数量: 38
  • 博客积分: 1605
  • 博客等级: 上尉
  • 技术积分: 370
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-12 14:59
文章分类

全部博文(38)

文章存档

2013年(3)

2012年(8)

2011年(28)

分类: 嵌入式

2011-06-21 16:44:43

TestActivity1.java
  1. package com.test;

  2. import android.app.Activity;
  3. import android.os.Bundle;

  4. public class TestActivity1 extends Activity {
  5.     /** Called when the activity is first created. */
  6.     @Override
  7.     public void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         setContentView(R.layout.main);    
  10.     }
  11. }
BootReceiver.java
  1. package com.test;

  2. import android.content.BroadcastReceiver;
  3. import android.content.Context;
  4. import android.content.Intent;

  5. public class BootReceiver extends BroadcastReceiver {

  6.     static final String ACTION = "android.intent.action.BOOT_COMPLETED";
  7.     
  8.     @Override
  9.     public void onReceive(Context context, Intent intent) {
  10.         // receive ACTION_BOOT_COMPLETED intent, start your activity, Magic code cool!
  11.         if (intent.getAction().equals(ACTION)) {
  12.             Intent testIntent = new Intent(context, TestActivity1.class);
  13.             testIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  14.             context.startActivity(testIntent);
  15.         }
  16.     }

  17. }

AndroidMainfest.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android=""
  3.     package="com.test" android:versionCode="1" android:versionName="1.0">
  4.     <!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> -->

  5.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  6.         <activity android:name=".TestActivity1" android:label="@string/app_name">
  7.             <intent-filter>
  8.                 <action android:name="android.intent.action.MAIN" />
  9.                 <category android:name="android.intent.category.LAUNCHER" />
  10.             </intent-filter>
  11.         </activity>
  12.         <receiver android:name="BootReceiver"
  13.             android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
  14.             <intent-filter>
  15.                 <action android:name="android.intent.action.BOOT_COMPLETED"></action>
  16.             </intent-filter>
  17.         </receiver>

  18.     </application>
  19. </manifest>
经我试验可以申请权限有两种方法,都可以。另一种在receiver 中加。
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> -->

阅读(2221) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~