Example usage for android.content Intent ACTION_PACKAGE_ADDED

List of usage examples for android.content Intent ACTION_PACKAGE_ADDED

Introduction

In this page you can find the example usage for android.content Intent ACTION_PACKAGE_ADDED.

Prototype

String ACTION_PACKAGE_ADDED

To view the source code for android.content Intent ACTION_PACKAGE_ADDED.

Click Source Link

Document

Broadcast Action: A new application package has been installed on the device.

Usage

From source file:com.example.android.home.Home.java

/**
 * Registers various intent receivers. The current implementation registers
 * only a wallpaper intent receiver to let other applications change the
 * wallpaper./*from  w  ww .ja  va2s. com*/
 */
private void registerIntentReceivers() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
    registerReceiver(mWallpaperReceiver, filter);

    filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    registerReceiver(mApplicationsReceiver, filter);
}

From source file:com.anysoftkeyboard.addons.AddOnsFactory.java

private boolean isEventRequiresCacheRefresh(Intent eventIntent) throws NameNotFoundException {
    String action = eventIntent.getAction();
    String packageNameSchemePart = eventIntent.getData().getSchemeSpecificPart();
    if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
        //will reset only if the new package has my addons
        boolean hasAddon = isPackageContainAnAddon(packageNameSchemePart);
        if (hasAddon) {
            Logger.d(mTag, "It seems that an addon exists in a newly installed package " + packageNameSchemePart
                    + ". I need to reload stuff.");
            return true;
        }/*from w  w w  .  jav  a  2  s  . c om*/
    } else if (Intent.ACTION_PACKAGE_REPLACED.equals(action) || Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
        //If I'm managing OR it contains an addon (could be new feature in the package), I want to reset.
        boolean isPackagedManaged = isPackageManaged(packageNameSchemePart);
        if (isPackagedManaged) {
            Logger.d(mTag, "It seems that an addon I use (in package " + packageNameSchemePart
                    + ") has been changed. I need to reload stuff.");
            return true;
        } else {
            boolean hasAddon = isPackageContainAnAddon(packageNameSchemePart);
            if (hasAddon) {
                Logger.d(mTag, "It seems that an addon exists in an updated package " + packageNameSchemePart
                        + ". I need to reload stuff.");
                return true;
            }
        }
    } else //removed
    {
        //so only if I manage this package, I want to reset
        boolean isPackagedManaged = isPackageManaged(packageNameSchemePart);
        if (isPackagedManaged) {
            Logger.d(mTag, "It seems that an addon I use (in package " + packageNameSchemePart
                    + ") has been removed. I need to reload stuff.");
            return true;
        }
    }
    return false;
}

From source file:org.deviceconnect.android.manager.DConnectMessageService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    super.onStartCommand(intent, flags, startId);
    if (intent == null) {
        mLogger.warning("intent is null.");
        return START_STICKY;
    }/*from w  ww.j a v  a  2  s.  co m*/

    if (!mRunningFlag) {
        return START_STICKY;
    }

    String action = intent.getAction();
    if (action == null) {
        mLogger.warning("action is null.");
        return START_STICKY;
    }

    String scheme = intent.getScheme();
    if (SCHEME_LAUNCH.equals(scheme)) {
        String key = intent.getStringExtra(IntentDConnectMessage.EXTRA_KEY);
        String origin = intent.getStringExtra(IntentDConnectMessage.EXTRA_ORIGIN);
        if (key != null && !TextUtils.isEmpty(origin)) {
            mHmacManager.updateKey(origin, key);
        }
        return START_STICKY;
    }

    if (checkAction(action)) {
        onRequestReceive(intent);
    } else if (IntentDConnectMessage.ACTION_RESPONSE.equals(action)) {
        onResponseReceive(intent);
    } else if (IntentDConnectMessage.ACTION_EVENT.equals(action)) {
        onEventReceive(intent);
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
        mPluginMgr.checkAndAddDevicePlugin(intent);
    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
        mPluginMgr.checkAndRemoveDevicePlugin(intent);
    }

    return START_STICKY;
}

From source file:me.piebridge.prevent.framework.SystemReceiver.java

private void handlePackage(Intent intent, String action) {
    String packageName = PackageUtils.getPackageName(intent);
    if (Intent.ACTION_PACKAGE_RESTARTED.equals(action)) {
        handlePackageRestarted("PACKAGE_RESTARTED", packageName);
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
        onPackageAdded(intent);/*from   ww w.  j  ava 2  s  .c o  m*/
    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
        onPackageRemoved(intent);
    }
}

From source file:com.google.android.apps.muzei.settings.SettingsChooseSourceFragment.java

@Override
public void onResume() {
    super.onResume();
    updateSources();/*  w  w  w .  j av a 2s . c  o  m*/

    IntentFilter packageChangeIntentFilter = new IntentFilter();
    packageChangeIntentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageChangeIntentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    packageChangeIntentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    packageChangeIntentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageChangeIntentFilter.addDataScheme("package");
    getActivity().registerReceiver(mPackagesChangedReceiver, packageChangeIntentFilter);
}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

private void registerReceivers() {
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mNetworkReceiver, filter);
    IntentFilter intentClickFilter = new IntentFilter(Constants.BROADCAST_CLICK_INTENT);
    registerReceiver(mIntentClickReceiver, intentClickFilter);

    IntentFilter appFilter = new IntentFilter();
    appFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    appFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    appFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    appFilter.addDataScheme("package");
    registerReceiver(mInstallReceiver, appFilter);

    IntentFilter updatefilter = new IntentFilter();
    updatefilter.addAction(Constants.BROADCAST_FORCE_EXIT);
    updatefilter.addAction(Constants.BROADCAST_REMIND_LATTER);
    updatefilter.addAction(Constants.BROADCAST_DOWNLOAD_OPT);
    updatefilter.addAction(Constants.BROADCAST_DOWNLOAD);
    registerReceiver(mUpdateReceiver, updatefilter);
}

From source file:com.cleanwiz.applock.service.LockService.java

public void registerApplicationReceiver() {
    IntentFilter packageIntentFilter = new IntentFilter();
    IntentFilter eventIntentFilter = new IntentFilter();
    eventIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    eventIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
    eventIntentFilter.addAction(Intent.ACTION_TIME_TICK);
    eventIntentFilter.addAction(Intent.ACTION_USER_PRESENT);
    eventIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    packageIntentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageIntentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageIntentFilter.addDataScheme("package");
    getApplicationContext().registerReceiver(packageReceiver, packageIntentFilter);
    getApplicationContext().registerReceiver(eventReceiver, eventIntentFilter);
    IntentFilter filter = new IntentFilter();
    filter.addAction(LOCK_SERVICE_LASTTIME);
    filter.addAction(LOCK_SERVICE_LEAVEAMENT);
    filter.addAction(LOCK_SERVICE_LEAVERTIME);
    filter.addAction(LOCK_SERVICE_LOCKSTATE);

    lastUnlockTimeSeconds = 0;/* w  ww .  ja  v  a2  s.c  o  m*/
    allowedLeaveAment = application.getAllowedLeaveAment();
    leaverTime = application.getLeaverTime();
    lockState = application.getAppLockState();
    registerReceiver(new ServiceReceiver(), filter);
}

From source file:com.fastbootmobile.encore.service.PlaybackService.java

/**
 * Called when the service is created/* w  ww.jav  a  2  s  .  com*/
 */
@Override
public void onCreate() {
    super.onCreate();
    mListenLogger = new ListenLogger(this);
    mPrefetcher = new Prefetcher(this);

    mCommandsHandlerThread = new HandlerThread("PlaybackServiceCommandsHandler");
    mCommandsHandlerThread.start();

    mCommandsHandler = new CommandHandler(this, mCommandsHandlerThread);

    // Register package manager to receive updates
    mPacManReceiver = new PacManReceiver();
    IntentFilter pacManFilter = new IntentFilter();
    pacManFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    pacManFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    pacManFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED);
    pacManFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    pacManFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    pacManFilter.addDataScheme("package");
    registerReceiver(mPacManReceiver, pacManFilter);

    // Really Google, I'd love to use your new APIs... But they're not working. If you use
    // the new Lollipop metadata system, you lose Bluetooth AVRCP since the Bluetooth
    // package still use the old RemoteController system.
    /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    mRemoteMetadata = new RemoteMetadataManagerv21(this);
    } else*/ {
        mRemoteMetadata = new RemoteMetadataManager(this);
    }

    ProviderAggregator.getDefault().addUpdateCallback(this);

    // Native playback initialization
    mNativeHub = new NativeHub(getApplicationContext());
    mNativeSink = new NativeAudioSink();
    mNativeHub.setSinkPointer(mNativeSink.getPlayer().getHandle());
    mNativeHub.setOnAudioWrittenListener(this);
    mNativeHub.onStart();

    mDSPProcessor = new DSPProcessor(this);
    mDSPProcessor.restoreChain(this);

    // Plugins initialization
    PluginsLookup.getDefault().initialize(getApplicationContext());
    PluginsLookup.getDefault().registerProviderListener(this);

    List<ProviderConnection> connections = PluginsLookup.getDefault().getAvailableProviders();
    for (ProviderConnection conn : connections) {
        if (conn.getBinder(false) != null) {
            assignProviderAudioSocket(conn);
        } else {
            Log.w(TAG, "Cannot assign audio socket to " + conn.getIdentifier() + ", binder is null");
        }
    }

    // Setup
    mIsStopping = false;

    // Bind to all provider
    List<ProviderConnection> providers = PluginsLookup.getDefault().getAvailableProviders();
    for (ProviderConnection pc : providers) {
        try {
            IMusicProvider binder = pc.getBinder(false);
            if (binder != null) {
                binder.registerCallback(mProviderCallback);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Cannot register callback", e);
        }
    }

    // Register AutoMix manager
    mCallbacks.add(AutoMixManager.getDefault());

    // Setup notification system
    mNotification = new ServiceNotification(this);
    mNotification.setOnNotificationChangedListener(new ServiceNotification.NotificationChangedListener() {
        @Override
        public void onNotificationChanged(ServiceNotification notification) {
            NotificationManagerCompat nmc = NotificationManagerCompat.from(PlaybackService.this);
            if (mIsForeground) {
                notification.notify(nmc);
                mIsForeground = true;
            } else {
                notification.notify(PlaybackService.this);
            }

            BitmapDrawable albumArt = notification.getAlbumArt();
            mRemoteMetadata.setAlbumArt(albumArt);
        }
    });

    // Setup lockscreen remote controls
    mRemoteMetadata.setup();

    // Setup playback wakelock (but don't acquire it yet)
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "OmniMusicPlayback");

    // Restore preferences
    SharedPreferences prefs = getSharedPreferences(SERVICE_SHARED_PREFS, MODE_PRIVATE);
    mRepeatMode = prefs.getBoolean(PREF_KEY_REPEAT, false);
    mShuffleMode = prefs.getBoolean(PREF_KEY_SHUFFLE, false);

    // TODO: Use callbacks
    // Restore playback queue after one second - we have multiple things to wait here:
    //  - The callbacks of the main app's UI
    //  - The providers connecting
    //  - The providers ready to send us data
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            SharedPreferences queuePrefs = getSharedPreferences(QUEUE_SHARED_PREFS, MODE_PRIVATE);
            mPlaybackQueue.restore(queuePrefs);
            mCurrentTrack = queuePrefs.getInt("current", -1);
            mCurrentTrackLoaded = false;
            mNotification.setHasNext(mPlaybackQueue.size() > 1 || (mPlaybackQueue.size() > 0 && mRepeatMode));
        }
    }, 1000);
}

From source file:com.android.tv.settings.users.AppRestrictionsFragment.java

@Override
public void onResume() {
    super.onResume();

    getActivity().registerReceiver(mUserBackgrounding, new IntentFilter(Intent.ACTION_USER_BACKGROUND));
    IntentFilter packageFilter = new IntentFilter();
    packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageFilter.addDataScheme("package");
    getActivity().registerReceiver(mPackageObserver, packageFilter);

    mAppListChanged = false;/*from  w  ww.  j av  a  2s  .  c o m*/
    if (mAppLoadingTask == null || mAppLoadingTask.getStatus() == AsyncTask.Status.FINISHED) {
        mAppLoadingTask = new AppLoadingTask().execute();
    }
}

From source file:org.mariotaku.twidere.app.TwidereApplication.java

@Override
public void onCreate() {
    sInstance = this;
    if (BuildConfig.DEBUG) {
        StrictModeUtils.detectAllVmPolicy();
    }//from w w w . ja v a2s  .  co m
    final SharedPreferences preferences = getSharedPreferences();
    resetTheme(preferences);
    super.onCreate();

    mProfileImageViewViewProcessor = new ProfileImageViewViewProcessor();
    mFontFamilyTagProcessor = new FontFamilyTagProcessor();

    ATE.registerViewProcessor(TabPagerIndicator.class, new TabPagerIndicatorViewProcessor());
    ATE.registerViewProcessor(FloatingActionButton.class, new FloatingActionButtonViewProcessor());
    ATE.registerViewProcessor(ActionBarContextView.class, new ActionBarContextViewViewProcessor());
    ATE.registerViewProcessor(SwipeRefreshLayout.class, new SwipeRefreshLayoutViewProcessor());
    ATE.registerViewProcessor(TimelineContentTextView.class, new TimelineContentTextViewViewProcessor());
    ATE.registerViewProcessor(TextView.class, new TextViewViewProcessor());
    ATE.registerViewProcessor(ImageView.class, new ImageViewViewProcessor());
    ATE.registerViewProcessor(MaterialEditText.class, new MaterialEditTextViewProcessor());
    ATE.registerViewProcessor(ProgressWheel.class, new ProgressWheelViewProcessor());
    ATE.registerViewProcessor(ProfileImageView.class, mProfileImageViewViewProcessor);
    ATE.registerTagProcessor(OptimalLinkColorTagProcessor.TAG, new OptimalLinkColorTagProcessor());
    ATE.registerTagProcessor(FontFamilyTagProcessor.TAG, mFontFamilyTagProcessor);
    ATE.registerTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR,
            new IconActionButtonTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR));
    ATE.registerTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR_ACTIVATED,
            new IconActionButtonTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR_ACTIVATED));
    ATE.registerTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR_DISABLED,
            new IconActionButtonTagProcessor(IconActionButtonTagProcessor.PREFIX_COLOR_DISABLED));
    ATE.registerTagProcessor(ThemedMultiValueSwitch.PREFIX_TINT, new ThemedMultiValueSwitch.TintTagProcessor());

    mProfileImageViewViewProcessor.setStyle(Utils.getProfileImageStyle(preferences));
    mFontFamilyTagProcessor.setFontFamily(ThemeUtils.getThemeFontFamily(preferences));

    final int themeColor = preferences.getInt(KEY_THEME_COLOR,
            ContextCompat.getColor(this, R.color.branding_color));
    if (!ATE.config(this, VALUE_THEME_NAME_LIGHT).isConfigured()) {
        //noinspection WrongConstant
        ATE.config(this, VALUE_THEME_NAME_LIGHT).primaryColor(themeColor)
                .accentColor(ThemeUtils.getOptimalAccentColor(themeColor, Color.BLACK)).coloredActionBar(true)
                .coloredStatusBar(true).commit();
    }
    if (!ATE.config(this, VALUE_THEME_NAME_DARK).isConfigured()) {
        ATE.config(this, VALUE_THEME_NAME_DARK)
                .accentColor(ThemeUtils.getOptimalAccentColor(themeColor, Color.WHITE)).coloredActionBar(false)
                .coloredStatusBar(true).statusBarColor(Color.BLACK).commit();
    }
    if (!ATE.config(this, null).isConfigured()) {
        ATE.config(this, null).accentColor(ThemeUtils.getOptimalAccentColor(themeColor, Color.WHITE))
                .coloredActionBar(false).coloredStatusBar(false).commit();
    }
    initializeAsyncTask();
    initDebugMode();
    initBugReport();
    mHandler = new Handler();

    final PackageManager pm = getPackageManager();
    final ComponentName main = new ComponentName(this, MainActivity.class);
    final ComponentName main2 = new ComponentName(this, MainHondaJOJOActivity.class);
    final boolean mainDisabled = pm
            .getComponentEnabledSetting(main) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    final boolean main2Disabled = pm
            .getComponentEnabledSetting(main2) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    final boolean noEntry = mainDisabled && main2Disabled;
    if (noEntry) {
        pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    } else if (!mainDisabled) {
        pm.setComponentEnabledSetting(main2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }
    if (!Utils.isComposeNowSupported(this)) {
        final ComponentName assist = new ComponentName(this, AssistLauncherActivity.class);
        pm.setComponentEnabledSetting(assist, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }

    migrateUsageStatisticsPreferences();
    Utils.startRefreshServiceIfNeeded(this);

    DependencyHolder holder = DependencyHolder.get(this);
    registerActivityLifecycleCallbacks(holder.getActivityTracker());

    final IntentFilter packageFilter = new IntentFilter();
    packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
            final String[] packages = getPackageManager().getPackagesForUid(uid);
            DependencyHolder holder = DependencyHolder.get(context);
            final ExternalThemeManager manager = holder.getExternalThemeManager();
            if (ArrayUtils.contains(packages, manager.getEmojiPackageName())) {
                manager.reloadEmojiPreferences();
            }
        }
    }, packageFilter);
}