网上说的都是 把 <category这一项屏蔽掉
<activity android:name=".PhoneTest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- 我们要屏蔽的地方 <category android:name="android.intent.category.LAUNCHER" /> -->
</intent-filter>
</activity>
经过测试这样开机启动程序就崩溃了。。把这句话加上就正常。public class BootReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
{
Log.d("BootReceiver", "system boot completed");
Intent newIntent = new Intent(context, main.class);
newIntent.setAction("android.intent.action.MAIN"); //MyActivity action defined in AndroidManifest.xml
newIntent.addCategory("android.intent.category.LAUNCHER");//MyActivity category defined in AndroidManifest.xml
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //If activity is not launched in Activity environment, this flag is mandatory to set
context.startActivity(newIntent);
}
}
这样设置开机启动的
<activity android:name=".PhoneTest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- 我们要屏蔽的地方 <category android:name="android.intent.category.LAUNCHER" /> -->
</intent-filter>
</activity>
经过测试这样开机启动程序就崩溃了。。把这句话加上就正常。public class BootReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
{
Log.d("BootReceiver", "system boot completed");
Intent newIntent = new Intent(context, main.class);
newIntent.setAction("android.intent.action.MAIN"); //MyActivity action defined in AndroidManifest.xml
newIntent.addCategory("android.intent.category.LAUNCHER");//MyActivity category defined in AndroidManifest.xml
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //If activity is not launched in Activity environment, this flag is mandatory to set
context.startActivity(newIntent);
}
}
这样设置开机启动的
//newIntent.addCategory("android.intent.category.LAUNCHER");
另外newIntent.setAction("android.intent.action.MAIN");这个作为intent filter应该起不到识别你自己的reciver的作用;换个intent filter;