App Status Monitor broadcast

Source: Internet
Author: User

Apps in your phone send broadcasts when they're installed, updated, and uninstalled

Manifest file
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Xidian.dy.com.chujia">    <uses-permissionAndroid:name= "Android.permission.RECEIVE_SMS"/>    <ApplicationAndroid:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme">        <ActivityAndroid:name=". Mainactivity "Android:label= "Main interface">            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>        <receiverAndroid:name=". Sdstatusreceiver ">            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.PACKAGE_ADDED"/>                <ActionAndroid:name= "Android.intent.action.PACKAGE_CHANGED"/>                <ActionAndroid:name= "Android.intent.action.PACKAGE_REMOVED"/>                <DataAndroid:scheme= "Package"/>            </Intent-filter>        </receiver>    </Application></Manifest>

Set the broadcast to receive in the manifest file

Broadcast recipient
 PackageXidian.dy.com.chujia;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.widget.Toast;/*** Created by Dy on 2016/7/12.*/ Public classAppstatusreceiverextendsBroadcastreceiver {@Override Public voidOnReceive (Context context, Intent Intent) {//determine the type of broadcast receivedString action =intent.getaction (); Uri URI=Intent.getdata (); if("Android.intent.action.PACKAGE_ADDED". Equals (action)) {Toast.maketext (context,uri.tostring ()+ "be Installed", Toast.length_long). Show (); }        Else if("Android.intent.action.PACKAGE_CHANGED". Equals (action)) {Toast.maketext (context, uri.tostring ()+ "has been updated", Toast.length_short). Show (); }        Else if("Android.intent.action.PACKAGE_REMOVED". Equals (action)) {Toast.maketext (context, uri.tostring ()+ "uninstalled", Toast.length_short). Show (); }    }}

App Status Monitor broadcast

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.