您的位置:首页 > 其它

经过验证过的接收系统广播

2015-08-28 11:25 330 查看
1.安装应用后,首先要启动一次。

2.如果签名后,不可以用eclipse安装apk文件,手动安装好后,也要启动一次。

3.添加以下:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<uses-permission android:name="android.permission.RESTART_PACKAGES" />

4.添加以下:

<receiver android:name=".BootBroadcastReceiver" >

<intent-filter>

<action android:name="android.intent.action.BOOT_COMPLETED" />

<category android:name="android.intent.category.HOME" />

</intent-filter>

<intent-filter>

<action android:name="android.intent.action.PACKAGE_ADDED" />

<action android:name="android.intent.action.PACKAGE_REMOVED" />

<action android:name="android.intent.action.PACKAGE_REPLACED" />

<data android:scheme="package" />

</intent-filter>

</receiver>

5.代码部分:

public class BootBroadcastReceiver extends BroadcastReceiver

{

@Override

public void onReceive(Context context, Intent intent)

{

//接收广播:系统启动完成后运行程序

if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))

{

Intent ootStartIntent = new Intent(context, Login_Activity.class);

ootStartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(ootStartIntent);

}

//接收广播:安装更新后,自动启动自己。

if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED) || intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED))

{

Intent ootStartIntent = new Intent(context, Login_Activity.class);

ootStartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(ootStartIntent);

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: