Search in sources :

Example 41 with BroadcastReceiver

use of android.content.BroadcastReceiver in project cordova-android by apache.

the class CoreAndroid method initTelephonyReceiver.

/**
     * Listen for telephony events: RINGING, OFFHOOK and IDLE
     * Send these events to all plugins using
     *      CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle")
     */
private void initTelephonyReceiver() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    //final CordovaInterface mycordova = this.cordova;
    this.telephonyReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // If state has changed
            if ((intent != null) && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                if (intent.hasExtra(TelephonyManager.EXTRA_STATE)) {
                    String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
                    if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        LOG.i(TAG, "Telephone RINGING");
                        webView.getPluginManager().postMessage("telephone", "ringing");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        LOG.i(TAG, "Telephone OFFHOOK");
                        webView.getPluginManager().postMessage("telephone", "offhook");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        LOG.i(TAG, "Telephone IDLE");
                        webView.getPluginManager().postMessage("telephone", "idle");
                    }
                }
            }
        }
    };
    // Register the receiver
    webView.getContext().registerReceiver(this.telephonyReceiver, intentFilter);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 42 with BroadcastReceiver

use of android.content.BroadcastReceiver in project cordova-android by apache.

the class SystemWebViewEngine method initWebViewSettings.

@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.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.JELLY_BEAN) {
        settings.setAllowUniversalAccessFromFileURLs(true);
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        settings.setMediaPlaybackRequiresUserGesture(false);
    }
    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().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!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        enableRemoteDebugging();
    }
    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);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);
    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();
    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360
    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) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
// end CB-1405
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) Method(java.lang.reflect.Method) BroadcastReceiver(android.content.BroadcastReceiver) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebSettings(android.webkit.WebSettings) SuppressLint(android.annotation.SuppressLint)

Example 43 with BroadcastReceiver

use of android.content.BroadcastReceiver in project weiciyuan by qii.

the class BrowserWeiboMsgFragment method onResume.

//android has a bug,I am tired. I use another color and disable underline for link,but when I open "dont save activity" in
//developer option,click the link to open another activity, then press back,this fragment is restored,
//but the link color is restored to android own blue color,not my custom color,the underline appears
//the workaround is set textview value in onresume() method
@Override
public void onResume() {
    super.onResume();
    //        buildViewData(false);
    //        if (hasGpsInfo())
    //            layout.mapView.onResume();
    getListView().setFastScrollEnabled(SettingUtility.allowFastScroll());
    sendCommentCompletedReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (isCommentList) {
                loadNewCommentData();
            }
        }
    };
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(sendCommentCompletedReceiver, new IntentFilter(AppEventAction.buildSendCommentOrReplySuccessfullyAction(msg)));
    sendRepostCompletedReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (!isCommentList) {
                loadNewRepostData();
            }
        }
    };
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(sendRepostCompletedReceiver, new IntentFilter(AppEventAction.buildSendRepostSuccessfullyAction(msg)));
}
Also used : GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 44 with BroadcastReceiver

use of android.content.BroadcastReceiver in project weiciyuan by qii.

the class LeftMenuFragment method showSearchPage.

private boolean showSearchPage(boolean reset) {
    getActivity().getActionBar().setDisplayShowTitleEnabled(true);
    if (currentIndex == SEARCH_INDEX && !reset) {
        ((MainTimeLineActivity) getActivity()).getSlidingMenu().showContent();
        return true;
    }
    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
    currentIndex = SEARCH_INDEX;
    if (Utility.isDevicePort() && !reset) {
        BroadcastReceiver receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(this);
                if (currentIndex == SEARCH_INDEX) {
                    showSearchPageImp();
                }
            }
        };
        LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, new IntentFilter(AppEventAction.SLIDING_MENU_CLOSED_BROADCAST));
    } else {
        showSearchPageImp();
    }
    ((MainTimeLineActivity) getActivity()).getSlidingMenu().showContent();
    return false;
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 45 with BroadcastReceiver

use of android.content.BroadcastReceiver in project weiciyuan by qii.

the class LeftMenuFragment method showFavPage.

private boolean showFavPage(boolean reset) {
    getActivity().getActionBar().setDisplayShowTitleEnabled(true);
    if (currentIndex == FAV_INDEX && !reset) {
        ((MainTimeLineActivity) getActivity()).getSlidingMenu().showContent();
        return true;
    }
    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    currentIndex = FAV_INDEX;
    if (Utility.isDevicePort() && !reset) {
        BroadcastReceiver receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(this);
                if (currentIndex == FAV_INDEX) {
                    showFavPageImp();
                }
            }
        };
        LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, new IntentFilter(AppEventAction.SLIDING_MENU_CLOSED_BROADCAST));
    } else {
        showFavPageImp();
    }
    ((MainTimeLineActivity) getActivity()).getSlidingMenu().showContent();
    return false;
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)381 Intent (android.content.Intent)354 Context (android.content.Context)337 IntentFilter (android.content.IntentFilter)280 PendingIntent (android.app.PendingIntent)91 RemoteException (android.os.RemoteException)26 Test (org.junit.Test)24 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)11 ContentObserver (android.database.ContentObserver)9 Bundle (android.os.Bundle)9 ErrnoException (android.system.ErrnoException)9 View (android.view.View)9