Search in sources :

Example 21 with BroadcastReceiver

use of android.content.BroadcastReceiver in project meatspace-android by RomainPiel.

the class ChatService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    cacheManager = new CacheManager(this, false);
    apiManager = ApiManager.get();
    busManager = BusManager.get();
    handler = new Handler();
    ioState = IOState.IDLE;
    chatList = new ChatList();
    mutedUsers = new HashSet<String>();
    BackgroundExecutor.execute(new Runnable() {

        @Override
        public void run() {
            final HashSet<String> cachedMutedUsers = (HashSet<String>) cacheManager.readFile(Constants.CACHE_MUTED_USERS, null);
            if (cachedMutedUsers != null) {
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        mutedUsers = cachedMutedUsers;
                        if (chatList.get() != null && !chatList.get().isEmpty()) {
                            syncChatList(chatList);
                            post();
                        }
                    }
                });
            }
        }
    }, API_GET_CACHED_MUTED_REQ_ID, null);
    busManager.getChatBus().register(this);
    busManager.getUiBus().register(this);
    closeChatReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            ioState = IOState.DISCONNECTED;
            post();
            context.stopService(new Intent(context, ChatService.class));
        }
    };
    registerReceiver(closeChatReceiver, new IntentFilter(Constants.FILTER_CHAT_CLOSE));
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) ChatList(com.romainpiel.model.ChatList) CacheManager(com.romainpiel.lib.utils.CacheManager) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver) HashSet(java.util.HashSet)

Example 22 with BroadcastReceiver

use of android.content.BroadcastReceiver in project Signal-Android by WhisperSystems.

the class ConversationActivity method initializeReceivers.

private void initializeReceivers() {
    securityUpdateReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            initializeSecurity(isSecureText, isDefaultSms);
            calculateCharactersRemaining();
        }
    };
    recipientsStaleReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.w(TAG, "Group update received...");
            if (recipients != null) {
                long[] ids = recipients.getIds();
                Log.w(TAG, "Looking up new recipients...");
                recipients = RecipientFactory.getRecipientsForIds(context, ids, true);
                recipients.addListener(ConversationActivity.this);
                onModified(recipients);
                fragment.reloadList();
            }
        }
    };
    IntentFilter staleFilter = new IntentFilter();
    staleFilter.addAction(GroupDatabase.DATABASE_UPDATE_ACTION);
    staleFilter.addAction(RecipientFactory.RECIPIENT_CLEAR_ACTION);
    registerReceiver(securityUpdateReceiver, new IntentFilter(SecurityEvent.SECURITY_UPDATE_EVENT), KeyCachingService.KEY_PERMISSION, null);
    registerReceiver(recipientsStaleReceiver, staleFilter);
}
Also used : GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 23 with BroadcastReceiver

use of android.content.BroadcastReceiver in project Signal-Android by WhisperSystems.

the class RecipientPreferenceActivity method initializeReceivers.

private void initializeReceivers() {
    this.staleReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Recipients recipients = RecipientFactory.getRecipientsForIds(context, getIntent().getLongArrayExtra(RECIPIENTS_EXTRA), true);
            recipients.addListener(RecipientPreferenceActivity.this);
            onModified(recipients);
        }
    };
    IntentFilter staleFilter = new IntentFilter();
    staleFilter.addAction(GroupDatabase.DATABASE_UPDATE_ACTION);
    staleFilter.addAction(RecipientFactory.RECIPIENT_CLEAR_ACTION);
    registerReceiver(staleReceiver, staleFilter);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Recipients(org.thoughtcrime.securesms.recipients.Recipients) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 24 with BroadcastReceiver

use of android.content.BroadcastReceiver in project phonegap-facebook-plugin by Wizcorp.

the class CordovaWebView method setup.

/**
     * Initialize webview.
     */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void setup() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    if (shouldRequestFocusOnInit()) {
        this.requestFocusFromTouch();
    }
    // Enable JavaScript
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean 4.2)
    try {
        Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] { boolean.class });
        String manufacturer = android.os.Build.MANUFACTURER;
        Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB && android.os.Build.MANUFACTURER.contains("HTC")) {
            gingerbread_getMethod.invoke(settings, true);
        }
    } catch (NoSuchMethodException e) {
        Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8");
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "Doing the NavDump failed with bad arguments");
    } catch (IllegalAccessException e) {
        Log.d(TAG, "This should never happen: IllegalAccessException means this isn't Android anymore");
    } catch (InvocationTargetException e) {
        Log.d(TAG, "This should never happen: InvocationTargetException means this isn't Android anymore.");
    }
    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);
    // while we do this
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        Level16Apis.enableUniversalAccess(settings);
    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);
    //Determine whether we're in debug or release mode, and turn on Debugging!
    try {
        final String packageName = this.cordova.getActivity().getPackageName();
        final PackageManager pm = this.cordova.getActivity().getPackageManager();
        ApplicationInfo appInfo;
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            setWebContentsDebuggingEnabled(true);
        }
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    } catch (NameNotFoundException e) {
        Log.d(TAG, "This should never happen: Your application's package can't be found.");
        e.printStackTrace();
    }
    settings.setGeolocationDatabasePath(databasePath);
    // Enable DOM storage
    settings.setDomStorageEnabled(true);
    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);
    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    String pathToCache = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setAppCachePath(pathToCache);
    settings.setAppCacheEnabled(true);
    // Fix for CB-1405
    // Google issue 4641
    this.updateUserAgentString();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                updateUserAgentString();
            }
        };
        this.cordova.getActivity().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
    pluginManager = new PluginManager(this, this.cordova);
    jsMessageQueue = new NativeToJsMessageQueue(this, cordova);
    exposedJsApi = new ExposedJsApi(pluginManager, jsMessageQueue);
    resourceApi = new CordovaResourceApi(this.getContext(), pluginManager);
    exposeJsInterface();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) Method(java.lang.reflect.Method) BroadcastReceiver(android.content.BroadcastReceiver) InvocationTargetException(java.lang.reflect.InvocationTargetException) PluginManager(org.apache.cordova.PluginManager) PackageManager(android.content.pm.PackageManager) WebSettings(android.webkit.WebSettings) SuppressLint(android.annotation.SuppressLint)

Example 25 with BroadcastReceiver

use of android.content.BroadcastReceiver in project atlas by alibaba.

the class InstrumentationHook method onException.

@Override
public boolean onException(Object obj, Throwable e) {
    if (obj instanceof BroadcastReceiver && (obj.getClass().getClassLoader().getClass().getName().equals(BundleClassLoader.class.getName()))) {
        try {
            Field locationField = BundleClassLoader.class.getDeclaredField("location");
            locationField.setAccessible(true);
            String location = (String) locationField.get(obj.getClass().getClassLoader());
            if (location != null) {
                BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(location);
                if (impl != null && !impl.checkValidate()) {
                    e.printStackTrace();
                    return true;
                }
            }
        } catch (Throwable e2) {
        }
    }
    return mBase.onException(obj, e);
}
Also used : Field(java.lang.reflect.Field) BundleImpl(android.taobao.atlas.framework.BundleImpl) BundleClassLoader(android.taobao.atlas.framework.BundleClassLoader) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)375 Intent (android.content.Intent)349 Context (android.content.Context)333 IntentFilter (android.content.IntentFilter)270 PendingIntent (android.app.PendingIntent)90 RemoteException (android.os.RemoteException)26 Test (org.junit.Test)23 Semaphore (java.util.concurrent.Semaphore)20 IOException (java.io.IOException)18 Point (android.graphics.Point)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ArrayList (java.util.ArrayList)15 AndroidRuntimeException (android.util.AndroidRuntimeException)14 GlobalContext (org.qii.weiciyuan.support.utils.GlobalContext)13 ComponentName (android.content.ComponentName)11 Handler (android.os.Handler)10 ErrnoException (android.system.ErrnoException)9 PackageManager (android.content.pm.PackageManager)8 ContentObserver (android.database.ContentObserver)8 Bundle (android.os.Bundle)8