TestActivity1.java
- package com.test;
-
- import android.app.Activity;
-
import android.os.Bundle;
-
public class TestActivity1 extends Activity {
-
/** Called when the activity is first created. */
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.main);
-
}
-
}
BootReceiver.java
- package com.test;
-
-
import android.content.BroadcastReceiver;
-
import android.content.Context;
-
import android.content.Intent;
-
-
public class BootReceiver extends BroadcastReceiver {
-
-
static final String ACTION = "android.intent.action.BOOT_COMPLETED";
-
-
@Override
-
public void onReceive(Context context, Intent intent) {
-
// receive ACTION_BOOT_COMPLETED intent, start your activity, Magic code cool!
-
if (intent.getAction().equals(ACTION)) {
-
Intent testIntent = new Intent(context, TestActivity1.class);
-
testIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
context.startActivity(testIntent);
-
}
-
}
-
-
}
AndroidMainfest.xml
- <?xml version="1.0" encoding="utf-8"?>
-
<manifest xmlns:android=""
-
package="com.test" android:versionCode="1" android:versionName="1.0">
-
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> -->
-
<application android:icon="@drawable/icon" android:label="@string/app_name">
-
<activity android:name=".TestActivity1" android:label="@string/app_name">
-
<intent-filter>
-
<action android:name="android.intent.action.MAIN" />
-
<category android:name="android.intent.category.LAUNCHER" />
-
</intent-filter>
-
</activity>
-
<receiver android:name="BootReceiver"
-
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
-
<intent-filter>
-
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
-
</intent-filter>
-
</receiver>
-
-
</application>
-
</manifest>
经我试验可以申请权限有两种方法,都可以。另一种在receiver 中加。
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> -->
阅读(2221) | 评论(0) | 转发(0) |