Example usage for android.content Intent getAction

List of usage examples for android.content Intent getAction

Introduction

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

Prototype

public @Nullable String getAction() 

Source Link

Document

Retrieve the general action to be performed, such as #ACTION_VIEW .

Usage

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    mServiceStartId = startId;/*  w w  w .ja  v  a  2 s  . c o m*/
    mDelayedStopHandler.removeCallbacksAndMessages(null);

    if (intent != null) {
        String action = intent.getAction();
        String cmd = intent.getStringExtra("command");
        MusicUtils.debugLog("onStartCommand " + action + " / " + cmd);

        if (CMDNEXT.equals(cmd) || NEXT_ACTION.equals(action)) {
            gotoNext(true);
        } else if (CMDPREVIOUS.equals(cmd) || PREVIOUS_ACTION.equals(action)) {
            if (position() < 2000) {
                prev();
            } else {
                seek(0);
                play();
            }
        } else if (CMDTOGGLEPAUSE.equals(cmd) || TOGGLEPAUSE_ACTION.equals(action)) {
            if (isPlaying()) {
                pause();
                mPausedByTransientLossOfFocus = false;
            } else {
                play();
            }
        } else if (CMDPAUSE.equals(cmd) || PAUSE_ACTION.equals(action)) {
            pause();
            mPausedByTransientLossOfFocus = false;
        } else if (CMDPLAY.equals(cmd)) {
            play();
        } else if (CMDSTOP.equals(cmd)) {
            pause();
            mPausedByTransientLossOfFocus = false;
            seek(0);
        }
    }

    // make sure the service will shut down on its own if it was
    // just started but not bound to and nothing is playing
    mDelayedStopHandler.removeCallbacksAndMessages(null);
    Message msg = mDelayedStopHandler.obtainMessage();
    mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
    return START_STICKY;
}

From source file:com.ichi2.anki.AbstractFlashcardViewer.java

/**
 * Show/dismiss dialog when sd card is ejected/remounted (collection is saved by SdCardReceiver)
 *//*from  ww w .j ava  2 s.co m*/
private void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) {
                    finishWithoutAnimation();
                }
            }
        };
        IntentFilter iFilter = new IntentFilter();
        iFilter.addAction(SdCardReceiver.MEDIA_EJECT);
        registerReceiver(mUnmountReceiver, iFilter);
    }
}

From source file:android.support.v7.media.RemotePlaybackClient.java

private void performItemAction(final Intent intent, final String sessionId, final String itemId, Bundle extras,
        final ItemActionCallback callback) {
    intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
    if (sessionId != null) {
        intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);
    }/*from   w w w. j a  v a2 s.  co m*/
    if (itemId != null) {
        intent.putExtra(MediaControlIntent.EXTRA_ITEM_ID, itemId);
    }
    if (extras != null) {
        intent.putExtras(extras);
    }
    logRequest(intent);
    mRoute.sendControlRequest(intent, new MediaRouter.ControlRequestCallback() {
        @Override
        public void onResult(Bundle data) {
            if (data != null) {
                String sessionIdResult = inferMissingResult(sessionId,
                        data.getString(MediaControlIntent.EXTRA_SESSION_ID));
                MediaSessionStatus sessionStatus = MediaSessionStatus
                        .fromBundle(data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS));
                String itemIdResult = inferMissingResult(itemId,
                        data.getString(MediaControlIntent.EXTRA_ITEM_ID));
                MediaItemStatus itemStatus = MediaItemStatus
                        .fromBundle(data.getBundle(MediaControlIntent.EXTRA_ITEM_STATUS));
                adoptSession(sessionIdResult);
                if (sessionIdResult != null && itemIdResult != null && itemStatus != null) {
                    if (DEBUG) {
                        Log.d(TAG,
                                "Received result from " + intent.getAction() + ": data=" + bundleToString(data)
                                        + ", sessionId=" + sessionIdResult + ", sessionStatus=" + sessionStatus
                                        + ", itemId=" + itemIdResult + ", itemStatus=" + itemStatus);
                    }
                    callback.onResult(data, sessionIdResult, sessionStatus, itemIdResult, itemStatus);
                    return;
                }
            }
            handleInvalidResult(intent, callback, data);
        }

        @Override
        public void onError(String error, Bundle data) {
            handleError(intent, callback, error, data);
        }
    });
}

From source file:com.lewa.crazychapter11.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    //set to full screen
    // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);

    ///set to no title
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    // acionBar = getSupportActionBar();
    // acionBar = getActionBar();
    // acionBar.hide();

    // Window win = getWindow();
    //          win.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //          win.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS  | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);  
    //          win.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);  
    // win.setStatusBarColor(Color.TRANSPARENT);  
    // win.setNavigationBarColor(Color.TRANSPARENT);

    /*///from w  w  w  .j  a va2 s .c  o  m
       win.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
       win.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS  | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);  
       win.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);  
       win.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);  
       win.setStatusBarColor(Color.TRANSPARENT);  
       win.setNavigationBarColor(Color.TRANSPARENT);
    //*/

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    /* setTheme(R.style.CrazyTheme); */
    AddGameBtn();
    AddNoification();
    LookupContact();
    AddServiceBtn();
    broadcastMain();
    mediaPlayerMain();
    mediaRecordSoundMain();
    cameraMain();
    recordvideoMain();
    queMySql();
    TestFragment();
    justForTest();
    LoadJson();
    AddTestBtn();
    AddUsageStatsBtn();
    AddPeopleProvideBtn();
    getInput();

    ////just for test shutdown broadcast receiver
    IntentFilter mIntentFilter = new IntentFilter("android.intent.action.ACTION_SHUTDOWN");
    mIntentFilter.addAction("com.lewa.alarm.test");
    mIntentFilter.addAction("android.provider.Telephony.SECRET_CODE");
    mIntentFilter.addAction("android.intent.action.SCREEN_ON");
    mIntentFilter.addAction("android.intent.action.SCREEN_OFF");
    mShoutdown = new shutdownReceiver();
    registerReceiver(mShoutdown, mIntentFilter);
    ////test      

    preferences = getSharedPreferences("crazyit", MODE_WORLD_WRITEABLE | MODE_WORLD_READABLE);
    editor = preferences.edit();

    preferencestime = getSharedPreferences("RMS_Shutdown_time", MODE_WORLD_WRITEABLE | MODE_WORLD_READABLE);
    editortime = preferencestime.edit();

    SharedShutdownTimeRead();

    AddSharedPreBtn();

    etNum = (EditText) findViewById(R.id.etNum);

    // //
    int maxLength = 4;

    InputFilter[] fArray = new InputFilter[1];

    fArray[0] = new InputFilter.LengthFilter(maxLength);

    etNum.setFilters(fArray);
    // //

    calThread = new CalThread();
    calThread.start();

    Log.i("algerheMain", "MainActivity onCreate in!!");
    String page = getString(R.string.str_page, "345", "24");
    Log.i("algerheMain", "page=" + page);

    // /just for test here
    ComponentName comp = getIntent().getComponent();
    show_txt = (EditText) findViewById(R.id.show_txt);
    show_txt.setText(
            "??" + comp.getPackageName() + " \n ??" + comp.getClassName());

    ////MD5 check item
    ///1.IMEI
    TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    String szImei = TelephonyMgr.getDeviceId();
    String m_szSIMSerialNm = TelephonyMgr.getSimSerialNumber();
    CellLocation m_location = TelephonyMgr.getCellLocation();
    String m_Line1Number = TelephonyMgr.getLine1Number();
    String m_OperatorName = TelephonyMgr.getSimOperatorName();
    Log.i("algerheTelephonyMgr", "szImei=" + szImei);
    Log.i("algerheTelephonyMgr", "m_szSIMSerialNm=" + m_szSIMSerialNm);
    Log.i("algerheTelephonyMgr", "m_location=" + m_location);
    Log.i("algerheTelephonyMgr", "m_Line1Number=" + m_Line1Number);
    Log.i("algerheTelephonyMgr", "m_OperatorName=" + m_OperatorName);

    Log.i("algerheMain01", "szImei=" + szImei);
    Log.i("algerheMain01", "m_szSIMSerialNm=" + m_szSIMSerialNm);

    ///2.Pseudo-Unique ID
    String m_szDevIDShort = "35" + //we make this look like a valid IMEI 
            Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10
            + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10
            + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10
            + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10
            + Build.USER.length() % 10; //13 digits

    Log.i("algerheMain01", "m_szDevIDShort=" + m_szDevIDShort);

    ///3. Android ID
    String m_szAndroidID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    Log.i("algerheMain01", "m_szAndroidID=" + m_szAndroidID);

    ///4.WLAN MAC Address string
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    String m_szWLANMAC = "unknow_wifi_mac";
    if (wm != null && wm.getConnectionInfo() != null) {
        m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
    }

    Log.i("algerheMain01", "m_szWLANMAC=" + m_szWLANMAC);

    ///5.BT MAC Address string
    BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter      
    m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    String m_szBTMAC = m_BluetoothAdapter.getAddress();

    Log.i("algerheMain01", "m_szBTMAC=" + m_szBTMAC);

    ///6.sim serial number .getSimSerialNumber()

    // /

    ///reflect test   
    checkMethod();

    // */
    final Intent alarmIntent = new Intent();
    Log.i("algerheMain00", "isLewaRom=" + isLewaRom(this, alarmIntent));

    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0x4567) {
                String languageStr = null;
                String countryStr = null;

                Locale[] locList = Locale.getAvailableLocales();

                for (int i = 0; i < locList.length; i++) {
                    languageStr += locList[i].getLanguage();
                    countryStr += locList[i].getCountry();
                }
                // show_txt = (EditText) findViewById(R.id.show_txt);
                show_txt.setText("" + languageStr + " \n " + countryStr);
            } else if (msg.what == 0x2789) {
                Log.i("algerheAlarm", "send alarm message in time=" + System.currentTimeMillis() + "\n action="
                        + alarmIntent.getAction());

                // sendBroadcast(alarmIntent);
            }
        }
    };

    // String strApkPath = intent.getStringExtra("apkPath");
    //         String strCmd = "pm install -r " + strApkPath;
    //         try {
    //             Process install = Runtime.getRuntime().exec(strCmd);
    //             Log.d(TAG, "install = " + install + ", strCmd =" + strCmd);
    //         }catch (Exception ex){
    //             Log.d(TAG, ex.getMessage());
    //         }   
    // */
}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

/** register boradcast*/
private void registerBoradcast() {
    IntentFilter intentfilter = new IntentFilter();
    intentfilter.addAction(Constants.RECEIVER_BROADCAST);
    intentfilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentfilter.addAction(Intent.ACTION_SCREEN_OFF);
    intentfilter.addAction(Intent.ACTION_SCREEN_ON);
    boradcastListener = new BroadcastReceiver() {
        @Override//from  w  w  w.  java2 s  . c  om
        public void onReceive(Context context, Intent intent) {

            DebugLog.d(TAG, "WebViewActivity onReceive");
            DebugLog.e(TAG, "BroadcastReceiver action = " + intent.getAction());
            if (intent.getAction().equalsIgnoreCase(Constants.RECEIVER_BROADCAST)) {
                Bundle bundle = intent.getExtras();
                int msgtype = bundle.getInt("msgtype");
                String msgcontent = bundle.getString("msgcontent");
                DebugLog.d(TAG, "handleMessage...... msgtype=" + msgtype + ", msgcontent=" + msgcontent);
                switch (msgtype) {
                case NotifyManagement.UP_PROBE_BAD_NETWORK:
                    //irtsp 1.12 , WebBrowser is not need to handler the UP_PROBE_BAD_NETWORK event message.
                    /*DebugLog.d(TAG, "UP_PROBE_BAD_NETWORK");
                    mPoorProbingresultFlag = true;
                    mPlayer.bitrate_stopProbe();
                    notifyProbingCompleted(true);*/
                    break;
                case NotifyManagement.UP_PROBE_EXIT:// callback disconnectCB = 6 when bandwidth probe
                    // success. Up_ui_gc.h
                    DebugLog.d(TAG, "GameActivity.m_player.bitrate_stopProbe()");
                    //notifyProbingCompleted(true);
                    /*if(bExitWaitProbeDone){
                       new Timer().schedule(new LogoutTimer(), 100);
                    }*/
                    break;
                case NotifyManagement.UP_PROBE_EXIT_FAIL:// callback disconnectCB = 10 when bandwidth probe
                    // fail. Up_ui_gc.h
                    DebugLog.d(TAG,
                            "WebViewActivity.onStart() probe fail, GameActivity.m_player.bitrate_stopProbe()");
                    //mPlayer.bitrate_stopProbe();
                    notifyProbingCompleted(false);
                    /*if(bExitWaitProbeDone){
                       new Timer().schedule(new LogoutTimer(), 100);
                    }*/
                    break;
                case NotifyManagement.UP_GAME_NOTIFY_DISPLAYTEXT:
                    DebugLog.d(TAG, "notify UP_GAME_NOTIFY_DISPLAYTEXT");
                    gBNotifyDisplayExit = true;
                    gNotifyDisplayText = msgcontent;

                    break;
                case NotifyManagement.LOCAL_BROADCAST_CALL_UPDATE_STATE_200:
                    callJsUpdateStatus(Constants.RESPONSE_200);
                    break;

                case NotifyManagement.LOCAL_NOTIFY_WEBJS_GET_DUI:
                    String gid = bundle.getString("gid");
                    String useragent = bundle.getString("useragent");
                    DebugLog.d(TAG, "notify webview js get DUI gid=" + gid + ",useragent=" + useragent);
                    setToJsPlayMetadata(gid, useragent);
                    break;
                case NotifyManagement.LOCAL_GAMEACTIVITY_RESULT:
                    DebugLog.d(TAG, "Constants.LOCAL_GAMEACTIVITY_RESULT");
                    ((LoadWebJsActivity) mWebviewActivity).handleGameActivityResult();
                    break;

                case NotifyManagement.CAST_SESSION_STATUS_WEB:
                    DebugLog.d(TAG, "build session have done");

                    String deviceId;
                    String deviceName;
                    String status;

                    deviceId = bundle.getString("deviceId");
                    deviceName = bundle.getString("deviceName");
                    status = bundle.getString("status");
                    retPlayOnCast(deviceId, deviceName, status);

                    synchronized (mLock) {
                        mLock.notify();
                        DebugLog.d(TAG, "notify the thread");
                    }

                    break;
                }
            } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                processNetworkType(intent, context);
            }

            if (intent.getAction().compareTo(Intent.ACTION_SCREEN_OFF) == 0) {
                DebugLog.d(TAG, "POWER ACTION_SCREEN_OFF");
                final LoadWebJsActivity loadWebJsActivity = (LoadWebJsActivity) mContext;
                loadWebJsActivity.gBEntryPowerKeyMode = true;
                loadWebJsActivity.gCurEntryBackgroundTime = System.currentTimeMillis();
            } else if (intent.getAction().compareTo(Intent.ACTION_SCREEN_ON) == 0) {
                DebugLog.d(TAG, "POWER ACTION_SCREEN_ON");
                final LoadWebJsActivity loadWebJsActivity = (LoadWebJsActivity) mContext;
                loadWebJsActivity.gBEntryPowerKeyMode = false;
                //   loadWebJsActivity.gCurEntryBackgroundTime = 0;

            }
        }
    };
    this.mContext.registerReceiver(boradcastListener, intentfilter);
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@Override
protected void onNewIntent(Intent intent) {
    // Handle clear XPrivacy data (needs UI refresh)
    Bundle extras = intent.getExtras();/*from   ww  w.  j av  a 2  s  . co  m*/
    if (extras != null && extras.containsKey(cAction) && extras.getInt(cAction) == cActionRefresh)
        recreate();
    else {
        // Refresh application list
        if (mAppAdapter != null)
            mAppAdapter.notifyDataSetChanged();

        // Import pro license
        if (Intent.ACTION_VIEW.equals(intent.getAction()))
            Util.importProLicense(new File(intent.getData().getPath()));
    }
}

From source file:cc.mintcoin.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    log.info("service start command: " + intent
            + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                    ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                    : ""));

    //log.info("org.bitcoin.NativeSecp256k1.enabled=" + org.bitcoin.NativeSecp256k1.enabled);

    if (blockChain == null) {
        boolean blockChainFileExists = blockChainFile.exists();
        boolean tryStarting = true;

        if (DownloadCompleteReceiver.isDownloading(application)) {
            log.info("isDownloading");
            DownloadCompleteReceiver.updateDownloadState(application); // it can fix itself this way

            tryStarting = false;/*from www  . j  a v  a  2s  .  com*/
        } else if (!blockChainFileExists) {
            if (DownloadCompleteReceiver.isObbAvailable(application)) {
                initializeBlockchainFast();
                tryStarting = true;
            } else if (intent.getBooleanExtra(DownloadCompleteReceiver.INTENT_EXTRA_SKIP_OBB_INIT, false)) {
                tryStarting = true;
            } else {
                // open dialog box to ask user what to do for download
                Intent intent2 = new Intent(this, InitialBlockchainActivity.class);
                intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(intent2);
                tryStarting = false;
            }
        }

        if (tryStarting) {
            try {
                startBlockChain();
            } catch (Error e) {
                stopSelf();
                throw e;
            }
        } else {
            stopSelf();
        }
    }

    String action = intent.getAction();

    if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
        notificationCount = 0;
        notificationAccumulatedAmount = BigInteger.ZERO;
        notificationAddresses.clear();

        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
    } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
        log.info("will remove blockchain on service shutdown");

        resetBlockchainOnShutdown = true;
        stopSelf();
    } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
        final Sha256Hash hash = new Sha256Hash(
                intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
        final Transaction tx = application.getWallet().getTransaction(hash);

        if (peerGroup != null) {
            log.info("broadcasting transaction " + tx.getHashAsString());
            peerGroup.broadcastTransaction(tx);
        } else {
            log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
        }
    }

    return START_NOT_STICKY;
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null && intent.hasExtra(EXTRA_COMMAND)
            && intent.getSerializableExtra(EXTRA_COMMAND) == Command.set) {
        set(intent);//  www.  j  a  v  a2 s.  com
        return START_STICKY;
    }

    // Keep awake
    getLock(this).acquire();

    // Handle service restart
    if (intent == null) {
        Log.i(TAG, "Restart");

        // Get enabled
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        boolean enabled = prefs.getBoolean("enabled", false);

        // Recreate intent
        intent = new Intent(this, ServiceSinkhole.class);
        intent.putExtra(EXTRA_COMMAND, enabled ? Command.start : Command.stop);
    }

    if (ACTION_HOUSE_HOLDING.equals(intent.getAction()))
        intent.putExtra(EXTRA_COMMAND, Command.householding);

    Command cmd = (Command) intent.getSerializableExtra(EXTRA_COMMAND);
    String reason = intent.getStringExtra(EXTRA_REASON);
    Log.i(TAG, "Start intent=" + intent + " command=" + cmd + " reason=" + reason + " vpn=" + (vpn != null)
            + " user=" + (Process.myUid() / 100000));

    commandHandler.queue(intent);
    return START_STICKY;
}