Example usage for android.content Intent setFlags

List of usage examples for android.content Intent setFlags

Introduction

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

Prototype

public @NonNull Intent setFlags(@Flags int flags) 

Source Link

Document

Set special flags controlling how this intent is handled.

Usage

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

public void onDocumentPicked(DocumentInfo doc) {
    final FragmentManager fm = getFragmentManager();
    if (doc.isDirectory()) {
        if (DEBUG) {
            Log.i(TAG, "onDocumentPicked()+directory");
        }/*from   w w  w  .j a va2  s .  c  om*/
        mState.stack.push(doc);
        mState.stackTouched = true;
        onCurrentDirectoryChanged(ANIM_DOWN);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
        // Explicit file picked, return
        if (DEBUG) {
            Log.i(TAG, "onDocumentPicked() " + mState.action);
        }
        new ExistingFinishTask(doc.derivedUri).executeOnExecutor(getCurrentExecutor());

        //           final Intent view = new Intent(Intent.ACTION_VIEW);
        //            view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        //            view.setData(doc.derivedUri);

        //            try {
        //                startActivity(view);
        //            } catch (ActivityNotFoundException ex2) {
        //                Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
        //            }            
    } else if (mState.action == ACTION_CREATE) {
        // Replace selected file
        if (DEBUG) {
            Log.i(TAG, "onDocumentPicked() " + mState.action);
        }
        SaveFragment.get(fm).setReplaceTarget(doc);
    } else if (mState.action == ACTION_MANAGE) {
        // First try managing the document; we expect manager to filter
        // based on authority, so we don't grant.
        if (DEBUG) {
            Log.i(TAG, "onDocumentPicked() " + mState.action);
        }
        final Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT);
        manage.setData(doc.derivedUri);

        try {
            startActivity(manage);
        } catch (ActivityNotFoundException ex) {
            // Fall back to viewing
            final Intent view = new Intent(Intent.ACTION_VIEW);
            view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            view.setData(doc.derivedUri);

            try {
                startActivity(view);
            } catch (ActivityNotFoundException ex2) {
                Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
            }
        }
    }
}

From source file:com.wso2.mobile.mdm.services.PolicyTester.java

@SuppressWarnings("static-access")
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public boolean testPolicy(String code, String data) {
    if (code.equals(CommonUtilities.OPERATION_CLEAR_PASSWORD)) {
        ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
        JSONObject jobj = new JSONObject();
        // data = intent.getStringExtra("data");
        try {/*from   www  .  j av a2s  .  c o  m*/
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);
            params.put("status", "200");

            if (IS_ENFORCE) {
                devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                        DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
                devicePolicyManager.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
                devicePolicyManager.lockNow();
                devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                        DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
                jobj.put("status", true);
            } else {
                if (devicePolicyManager.getPasswordQuality(
                        demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                    jobj.put("status", false);
                } else {
                    jobj.put("status", true);
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            jobj.put("code", code);

            //finalArray.put(jobj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_WIFI)) {
        boolean wifistatus = false;
        JSONObject jobjc = new JSONObject();
        WiFiConfig config = new WiFiConfig(context);
        // data = intent.getStringExtra("data");
        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data);
            if (!jobj.isNull("ssid")) {
                ssid = (String) jobj.get("ssid");
            }
            if (!jobj.isNull("password")) {
                password = (String) jobj.get("password");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Map<String, String> inparams = new HashMap<String, String>();
        inparams.put("code", code);
        if (IS_ENFORCE) {
            try {
                wifistatus = config.saveWEPConfig(ssid, password);
                jobjc.put("status", true);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        try {
            if (config.readWEPConfig(ssid)) {
                jobjc.put("status", true);
            } else {
                jobjc.put("status", false);
                if (usermessage != null && usermessage != "") {
                    usermessage += "\nYou are not using company WIFI account, please change your WIFI configuration \n";
                } else {
                    usermessage += "You are not using company WIFI account, please change your WIFI configuration \n";
                }

            }
            jobjc.put("code", code);

            finalArray.put(jobjc);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_DISABLE_CAMERA)) {
        ComponentName cameraAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
        boolean camFunc = false;
        // data = intent.getStringExtra("data");
        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data);

            if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("enable")) {
                camFunc = false;
            } else if (!jobj.isNull("function")
                    && jobj.get("function").toString().equalsIgnoreCase("disable")) {
                camFunc = true;
            } else if (!jobj.isNull("function")) {
                camFunc = Boolean.parseBoolean(jobj.get("function").toString());
            }

            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);
            params.put("status", "200");
            String cammode = "Disabled";
            if (camFunc) {
                cammode = "Disabled";
            } else {
                cammode = "Enabled";
            }

            if (IS_ENFORCE && (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
                devicePolicyManager.setCameraDisabled(cameraAdmin, camFunc);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        JSONObject jobj = new JSONObject();
        try {
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                if (!camFunc) {
                    if (!devicePolicyManager.getCameraDisabled(cameraAdmin)) {
                        jobj.put("status", true);
                    } else {
                        jobj.put("status", false);
                    }
                } else {
                    if (devicePolicyManager.getCameraDisabled(cameraAdmin)) {
                        jobj.put("status", true);
                    } else {
                        jobj.put("status", false);
                        /*if(usermessage!=null && usermessage!=""){
                           usermessage+="\nYour camera should be deactivated according to the policy, please deactivate your camera\n";
                        }else{
                           usermessage+="Your camera should be deactivated according to the policy, please deactivate your camera \n";
                        }*/
                    }
                }
            } else {
                jobj.put("status", false);
            }
            jobj.put("code", code);

            finalArray.put(jobj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_ENCRYPT_STORAGE)) {
        boolean encryptFunc = true;
        String pass = "";

        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data);

            if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("encrypt")) {
                encryptFunc = true;
            } else if (!jobj.isNull("function")
                    && jobj.get("function").toString().equalsIgnoreCase("decrypt")) {
                encryptFunc = false;
            } else if (!jobj.isNull("function")) {
                encryptFunc = Boolean.parseBoolean(jobj.get("function").toString());
            }

            ComponentName admin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);

            if (IS_ENFORCE) {
                if (encryptFunc && devicePolicyManager
                        .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
                    if (devicePolicyManager
                            .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) {
                        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                            devicePolicyManager.setStorageEncryption(admin, encryptFunc);
                            Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(intent);
                        }
                    }
                } else if (!encryptFunc && devicePolicyManager
                        .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
                    if (devicePolicyManager
                            .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVE
                            || devicePolicyManager
                                    .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVATING) {
                        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                            devicePolicyManager.setStorageEncryption(admin, encryptFunc);
                        }
                    }
                }
            }
            if (devicePolicyManager
                    .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
                params.put("status", "200");
            } else {
                params.put("status", "400");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        JSONObject jobj = new JSONObject();
        try {
            jobj.put("code", code);
            if (encryptFunc) {
                if (devicePolicyManager
                        .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED
                        && devicePolicyManager
                                .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) {
                    jobj.put("status", true);
                } else {
                    jobj.put("status", false);
                    if (usermessage != null && usermessage != "") {
                        usermessage += "\nYour device should be encrypted according to the policy, please enable device encryption through device settings\n";
                    } else {
                        usermessage += "Your device should be encrypted according to the policy, please enable device encryption through device settings \n";
                    }
                }
            } else {
                if (devicePolicyManager
                        .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED
                        || devicePolicyManager
                                .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) {
                    jobj.put("status", true);
                } else {
                    jobj.put("status", false);
                }
            }
            finalArray.put(jobj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else if (code.equals(CommonUtilities.OPERATION_MUTE)) {

        try {
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);
            params.put("status", "200");
            if (IS_ENFORCE) {
                muteDevice();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        JSONObject jobj = new JSONObject();
        try {
            jobj.put("code", code);
            if (isMuted()) {
                jobj.put("status", true);
            } else {
                jobj.put("status", false);
                if (usermessage != null && usermessage != "") {
                    usermessage += "\nYour phone should be muted according to the policy, please mute your phone \n";
                } else {
                    usermessage += "Your phone should be muted according to the policy, please mute your phone \n";
                }
            }
            finalArray.put(jobj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_PASSWORD_POLICY)) {

        ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
        JSONObject jobjx = new JSONObject();
        int attempts, length, history, specialChars;
        String alphanumeric, complex;
        boolean b_alphanumeric = false, b_complex = false, is_comply = true, comply_fac1 = true,
                comply_fac2 = true, comply_fac3 = true, comply_fac4 = true, comply_fac5 = true,
                comply_fac6 = true, comply_fac7 = true;
        long timout;
        Map<String, String> inparams = new HashMap<String, String>();
        // data = intent.getStringExtra("data");
        JSONParser jp = new JSONParser();
        try {
            JSONObject jobjpass = new JSONObject();
            jobjpass.put("code", CommonUtilities.OPERATION_CHANGE_LOCK_CODE);

            if (devicePolicyManager.isActivePasswordSufficient()) {
                is_comply = true;
                //finalArray.put(jobjpass);
            } else {
                is_comply = false;
            }

            JSONObject jobj = new JSONObject(data);
            if (!jobj.isNull("maxFailedAttempts") && jobj.get("maxFailedAttempts") != null) {
                attempts = Integer.parseInt((String) jobj.get("maxFailedAttempts"));
                if (IS_ENFORCE) {
                    devicePolicyManager.setMaximumFailedPasswordsForWipe(demoDeviceAdmin, attempts);
                    comply_fac1 = true;
                } else {
                    if (devicePolicyManager.getMaximumFailedPasswordsForWipe(demoDeviceAdmin) != attempts) {
                        comply_fac1 = false;
                    } else {
                        comply_fac1 = true;
                    }
                }
            }

            if (!jobj.isNull("minLength") && jobj.get("minLength") != null) {
                length = Integer.parseInt((String) jobj.get("minLength"));
                if (IS_ENFORCE) {
                    devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, length);
                    comply_fac2 = true;
                } else {
                    if (devicePolicyManager.getPasswordMinimumLength(demoDeviceAdmin) != length) {
                        comply_fac2 = false;
                    } else {
                        comply_fac2 = true;
                    }
                }
            }

            if (!jobj.isNull("pinHistory") && jobj.get("pinHistory") != null) {
                history = Integer.parseInt((String) jobj.get("pinHistory"));
                if (IS_ENFORCE) {
                    devicePolicyManager.setPasswordHistoryLength(demoDeviceAdmin, history);
                    comply_fac3 = true;
                } else {
                    if (devicePolicyManager.getPasswordHistoryLength(demoDeviceAdmin) != history) {
                        comply_fac3 = false;
                    } else {
                        comply_fac3 = true;
                    }
                }
            }

            if (!jobj.isNull("minComplexChars") && jobj.get("minComplexChars") != null) {
                specialChars = Integer.parseInt((String) jobj.get("minComplexChars"));
                if (IS_ENFORCE) {
                    devicePolicyManager.setPasswordMinimumSymbols(demoDeviceAdmin, specialChars);
                    comply_fac4 = true;
                } else {
                    if (devicePolicyManager.getPasswordMinimumSymbols(demoDeviceAdmin) != specialChars) {
                        comply_fac4 = false;
                    } else {
                        comply_fac4 = true;
                    }
                }
            }

            if (!jobj.isNull("requireAlphanumeric") && jobj.get("requireAlphanumeric") != null) {

                if (jobj.get("requireAlphanumeric") instanceof String) {
                    alphanumeric = (String) jobj.get("requireAlphanumeric").toString();
                    if (alphanumeric.equals("true")) {
                        b_alphanumeric = true;
                    } else {
                        b_alphanumeric = false;
                    }
                } else if (jobj.get("requireAlphanumeric") instanceof Boolean) {
                    b_alphanumeric = jobj.getBoolean("requireAlphanumeric");
                }
                if (b_alphanumeric) {
                    if (IS_ENFORCE) {
                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                                DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
                        comply_fac5 = true;
                    } else {
                        if (devicePolicyManager.getPasswordQuality(
                                demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC) {
                            comply_fac5 = false;
                        } else {
                            comply_fac5 = true;
                        }
                    }
                } else {
                    if (devicePolicyManager.getPasswordQuality(
                            demoDeviceAdmin) == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC) {
                        comply_fac5 = false;
                    } else {
                        comply_fac5 = true;
                    }
                }
            }

            if (!jobj.isNull("allowSimple") && jobj.get("allowSimple") != null) {

                if (jobj.get("allowSimple") instanceof String) {
                    complex = (String) jobj.get("allowSimple").toString();
                    if (complex.equals("true")) {
                        b_complex = true;
                    } else {
                        b_complex = false;
                    }
                } else if (jobj.get("allowSimple") instanceof Boolean) {
                    b_complex = jobj.getBoolean("allowSimple");
                }

                if (!b_complex) {
                    if (IS_ENFORCE) {
                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                                DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);
                        comply_fac6 = true;
                    } else {
                        if (devicePolicyManager.getPasswordQuality(
                                demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
                            comply_fac6 = false;
                        } else {
                            comply_fac6 = true;
                        }
                    }
                } else {
                    if (devicePolicyManager.getPasswordQuality(
                            demoDeviceAdmin) == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
                        comply_fac6 = false;
                    } else {
                        comply_fac6 = true;
                    }
                }
            }

            if (!jobj.isNull("maxPINAgeInDays") && jobj.get("maxPINAgeInDays") != null) {
                int daysOfExp = Integer.parseInt((String) jobj.get("maxPINAgeInDays"));
                timout = (long) (daysOfExp * 24 * 60 * 60 * 1000);
                if (IS_ENFORCE) {
                    devicePolicyManager.setPasswordExpirationTimeout(demoDeviceAdmin, timout);
                    comply_fac7 = true;
                } else {
                    if (devicePolicyManager.getPasswordExpirationTimeout(demoDeviceAdmin) != timout) {
                        comply_fac7 = false;
                    } else {
                        comply_fac7 = true;
                    }
                }
            }

            if (!is_comply || !comply_fac1 || !comply_fac2 || !comply_fac3 || !comply_fac4 || !comply_fac5
                    || !comply_fac6 || !comply_fac7) {
                jobjx.put("status", false);
                if (usermessage != null && usermessage != "") {
                    usermessage += "\nYour screen lock password doesn't meet current policy requirement. Please reset your passcode \n";
                } else {
                    usermessage += "Your screen lock password doesn't meet current policy requirement. Please reset your passcode \n";
                }
            } else {
                jobjx.put("status", true);
            }

            inparams.put("code", code);
            inparams.put("status", "200");

        } catch (Exception e) {
            // TODO Auto-generated catch block

            e.printStackTrace();
        }

        try {
            jobjx.put("code", code);

            finalArray.put(jobjx);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code.equals(CommonUtilities.OPERATION_BLACKLIST_APPS)) {
        ArrayList<PInfo> apps = appList.getInstalledApps(false); /*
                                                                 * false =
                                                                 * no system
                                                                 * packages
                                                                 */
        JSONArray jsonArray = new JSONArray();
        int max = apps.size();

        Boolean flag = true;

        try {
            JSONObject appObj = new JSONObject(data);
            String identity = (String) appObj.get("identity");
            for (int j = 0; j < max; j++) {
                JSONObject jsonObj = new JSONObject();
                try {
                    jsonObj.put("name", apps.get(j).appname);
                    jsonObj.put("package", apps.get(j).pname);
                    if (identity.trim().equals(apps.get(j).pname)) {
                        jsonObj.put("notviolated", false);
                        flag = false;
                        jsonObj.put("package", apps.get(j).pname);
                        if (apps.get(j).appname != null) {
                            appcount++;
                            apz = appcount + ". " + apps.get(j).appname;
                        }

                        if (apz != null || !apz.trim().equals("")) {
                            if (usermessage != null && usermessage != "") {
                                if (appcount > 1) {
                                    usermessage += "\n" + apz;
                                } else {
                                    usermessage += "\nFollowing apps are blacklisted by your MDM Admin, please remove them \n\n"
                                            + apz;
                                }
                            } else {
                                if (appcount > 1) {
                                    usermessage += "\n" + apz;
                                } else {
                                    usermessage += "Following apps are blacklisted by your MDM Admin, please remove them \n\n"
                                            + apz;
                                }

                            }
                        }

                    } else {
                        jsonObj.put("notviolated", true);
                    }

                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                jsonArray.put(jsonObj);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        /*
         * for(int i=0;i<apps.length;i++){ jsonArray.add(apps[i]); }
         */
        JSONObject appsObj = new JSONObject();
        try {
            //appsObj.put("data", jsonArray);
            appsObj.put("status", flag);
            appsObj.put("code", code);
            finalArray.put(appsObj);

        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    }

    return true;
}

From source file:org.sirimangalo.meditationplus.ActivityMain.java

@Override
protected void onResume() {
    super.onResume();
    isShowing = true;/*from   ww  w.j a  v  a  2 s. c o  m*/
    listVersion = -1;
    chatVersion = -1;
    restartTimer = true;

    refreshPeriod = Integer.parseInt(prefs.getString("refresh_period", "10")) * 1000;
    refreshPeriod = Math.max(refreshPeriod, 10);

    fullRefreshPeriod = Integer.parseInt(prefs.getString("full_refresh_period", "60")) * 1000;
    fullRefreshPeriod = Math.max(fullRefreshPeriod, 60);

    if (ct != null)
        ct.cancel();

    ct = new CountDownTimer(fullRefreshPeriod, refreshPeriod) {
        @Override
        public void onTick(long l) {
            ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
            if (l < fullRefreshPeriod - refreshPeriod && isShowing) {
                doSubmit(null, nvp, false);
            }
        }

        @Override
        public void onFinish() {
            if (isShowing) {
                listVersion = -1;
                chatVersion = -1;
                restartTimer = true;
                ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
                nvp.add(new BasicNameValuePair("full_update", "true"));
                doSubmit(null, nvp, false);
            }
        }
    };
    loginToken = prefs.getString("login_token", "");

    if (loginToken.equals("")) {
        Intent i = new Intent(this, ActivityMain.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (!doingLogin)
            startActivity(i);
    } else {
        username = prefs.getString("username", "");
        password = "";
        doSubmit(null, new ArrayList<NameValuePair>(), false);
    }

}

From source file:com.lofland.housebot.BotController.java

public void startCamera() {
    // old "return to launcher" intent
    // Intent launcher = new
    // Intent().setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);

    // To get it not to run ANOTHER instance of House Bot, use the below two
    // lines for the return
    // intent for housebot
    // From://ww  w.j  a v a  2 s  . c om
    // http://stackoverflow.com/questions/2424488/android-new-intent-starts-new-instance-with-androidlaunchmode-singletop
    // Also added android:launchMode="singleTop" to the manifest
    Intent housebot = new Intent().setClassName(BotController.this, BotController.class.getName());
    housebot.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    Intent ipwebcam = new Intent().setClassName("com.pas.webcam", "com.pas.webcam.Rolling")
            // Original
            /*
             * .putExtra("cheats", new String[] { "set(Photo,1024,768)", // set photo resolution to 1024x768 "set(DisableVideo,true)", // Disable video streaming (only photo
             * and immediate photo) "reset(Port)", // Use default port 8080 "set(HtmlPath,/sdcard/html/)", // Override server pages with ones in this directory })
             * .putExtra("hidebtn1", true) // Hide help button .putExtra("caption2", "Run in background") // Change caption on "Actions..." .putExtra("intent2", launcher) //
             * And give button another purpose .putExtra("returnto", new Intent().setClassName(ApiTest.this,ApiTest.class.getName())); // Set activity to return to
             */
            // Mine
            .putExtra("cheats", new String[] { "set(Video,640,480)", // set photo resolution to
                    // 1024x768
                    "reset(Photo)", "reset(DisableVideo)", "set(DisablePhoto,true)", "set(DisablePhotoAF,true)",
                    "set(DisableImmediatePhoto,true)", "set(DisableTorchCtl,true)", "reset(HtmlPath)",
                    "reset(Port)", // Use default port 8080
                    "set(Awake,true)", "set(Quality,50)" })
            .putExtra("hidebtn1", true) // Hide help button
            .putExtra("caption2", "Run in background") // Change caption on
            // "Actions..."
            .putExtra("intent2", housebot); // And give button another
    // purpose, go to Housebot :)
    // .putExtra("returnto", housebot ); // Also returns to Housebot
    // No, then if I exit HouseBot it goes here and then I get a small loop
    startActivity(ipwebcam);
}

From source file:com.piggate.sdk.Piggate.java

public void postNotification(String title, String msg, Class myClass, int resource, Bundle extras,
        Boolean force) {// w  w  w  .  j a v  a2 s .  c o  m
    if (!getApplicationContext().getPackageName()
            .equalsIgnoreCase(((ActivityManager) getApplicationContext()
                    .getSystemService(getApplicationContext().ACTIVITY_SERVICE)).getRunningAppProcesses()
                            .get(0).processName)
            || force) {

        Intent notifyIntent = new Intent(_context, myClass);
        if (extras != null)
            notifyIntent.putExtras(extras);
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivities(_context, 0, new Intent[] { notifyIntent },
                PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new Notification.Builder(_context).setSmallIcon(resource)
                .setContentTitle(title).setContentText(msg).setAutoCancel(true).setContentIntent(pendingIntent)
                .build();
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        notificationManager.notify(123, notification);
    }
}

From source file:com.example.carsharing.ShortWayActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Intent returnp = new Intent(ShortWayActivity.this, PersonalCenterActivity.class);
        returnp.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(returnp);// w w w .j  av a 2s.  c  om
        return false;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java

private void displayArtistInfo(JSONObject j) throws JSONException {
    if (imageLoader == null)
        imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited())
        imageLoader.init(config);//from  www  . ja  va  2 s .co  m

    Log.i("musicInfo", "LinkPopUp. displayArtistInfo " + j.toString());

    //JSONObject j_artist_info = j.getJSONObject("artist");

    final String artist_name = j.getString("name");

    tArtistName.setText(artist_name);
    final JSONObject urls = j.optJSONObject("urls");
    final JSONArray videos = j.optJSONArray("video");
    final JSONArray images = j.optJSONArray("images");

    final String msg = artist_name.replaceAll("\\p{Punct}", " ").replaceAll("\\p{Space}", "+");

    AsyncHttpClient client = new AsyncHttpClient();

    String fmURL = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" + msg
            + "&autocorrect[1]&format=json&api_key=ca4c10f9ae187ebb889b33ba12da7ee9";
    Log.i("musicInfo", fmURL);

    client.get(fmURL, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            String r = new String(responseBody);
            ArrayList<String> image_urls = new ArrayList<String>();

            try {
                Log.i("musicInfo", "Communicating with LastFM...");

                JSONObject json = new JSONObject(r);
                Log.i("musicInfo", json.toString());

                json = json.getJSONObject("artist");
                Log.i("musicInfo", json.toString());

                JSONArray artist_images = json.optJSONArray("image");
                Log.i("musicInfo", artist_images.toString());

                for (int i = 0; i < artist_images.length(); i++) {
                    JSONObject j = artist_images.getJSONObject(i);
                    Log.i("musicInfo", j.optString("size"));
                    if (j.optString("size").contains("extralarge")) {
                        image_urls.add(j.optString("#text"));
                        //b.putString("fm_image", j.getString("#text"));
                        //Log.i("musicInfo", j.getString("#text"));
                        break;
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            if (images != null) {
                for (int i = 0; i < images.length(); i++) {
                    JSONObject image = null;
                    try {
                        image = images.getJSONObject(i);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    int width = image.optInt("width", 0);
                    int height = image.optInt("height", 0);
                    String url = image.optString("url", "");
                    Log.i("musicInfo", i + ": " + url);
                    if ((width * height > 10000) && (width * height < 100000)
                            && (!url.contains("userserve-ak"))) {
                        //if ((width>300&&width<100)&&(height>300&&height<1000)&&(!url.contains("userserve-ak"))) {
                        image_urls.add(url);
                        Log.i("musicInfo", "Selected: " + url);
                        //available_images.put(image);
                    }
                }
            }

            int random = (int) (Math.random() * image_urls.size());
            final String f_url = image_urls.get(random);

            Log.i("musicInfo",
                    "Total image#=" + image_urls.size() + " Selected image#=" + random + " " + f_url);

            if (image_urls.size() > 0) {
                imageLoader.displayImage(f_url, ArtistImage, new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {

                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

                        lLinkList.removeAllViews();
                        //String attr = fImage.optJSONObject("license").optString("attribution");
                        //tAttribution.setText("Credit. " + ((attr == null) || (attr.contains("n/a")) ? "Unknown" : attr));
                        if (urls != null) {
                            String[] jsonName = { "wikipedia_url", "mb_url", "lastfm_url", "official_url",
                                    "twitter_url" };
                            for (int i = 0; i < jsonName.length; i++) {
                                if ((urls.optString(jsonName[i]) != null)
                                        && (urls.optString(jsonName[i]) != "")) {
                                    Log.d("musicinfo", "Link URL: " + urls.optString(jsonName[i]));
                                    TextView tv = new TextView(getApplicationContext());
                                    tv.setTextSize(11);
                                    tv.setPadding(16, 16, 16, 16);
                                    tv.setTextColor(Color.LTGRAY);
                                    tv.setTypeface(Typeface.SANS_SERIF);
                                    tv.setGravity(Gravity.CENTER_VERTICAL);

                                    switch (jsonName[i]) {
                                    case "official_url":
                                        tv.setText("HOME.");
                                        break;
                                    case "wikipedia_url":
                                        tv.setText("WIKI.");
                                        break;
                                    case "mb_url":
                                        tv.setText("Music Brainz.");
                                        break;
                                    case "lastfm_url":
                                        tv.setText("Last FM.");
                                        break;
                                    case "twitter_url":
                                        tv.setText("Twitter.");
                                        break;
                                    }

                                    try {
                                        tv.setTag(urls.getString(jsonName[i]));
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }

                                    tv.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            Intent intent = new Intent();
                                            intent.setAction(Intent.ACTION_VIEW);
                                            intent.addCategory(Intent.CATEGORY_BROWSABLE);
                                            intent.setData(Uri.parse((String) v.getTag()));
                                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                            startActivity(intent);
                                            Toast.makeText(getApplicationContext(), "Open the Link...",
                                                    Toast.LENGTH_SHORT).show();
                                            //finish();
                                        }
                                    });
                                    lLinkList.addView(tv);
                                }
                            }
                        } else {
                            TextView tv = new TextView(getApplicationContext());
                            tv.setTextSize(11);
                            tv.setPadding(16, 16, 16, 16);
                            tv.setTextColor(Color.LTGRAY);
                            tv.setTypeface(Typeface.SANS_SERIF);
                            tv.setGravity(Gravity.CENTER_VERTICAL);
                            tv.setText("Sorry, No Link Here...");
                            lLinkList.addView(tv);
                        }

                        if (videos != null) {
                            jVideoArray = videos;
                            mAdapter = new StaggeredViewAdapter(getApplicationContext(),
                                    android.R.layout.simple_list_item_1, generateImageData(videos));
                            //if (mData == null) {
                            mData = generateImageData(videos);
                            //}

                            //mAdapter.clear();

                            for (JSONObject data : mData) {
                                mAdapter.add(data);
                            }
                            mGridView.setAdapter(mAdapter);
                        } else {

                        }

                        adjBottomColor(((ImageView) view).getDrawable());
                    }

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {

                    }
                });
            } else {
                ArtistImage.setImageResource(R.drawable.lamb_no_image_available);
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

        }
    });
}

From source file:org.sirimangalo.meditationplus.ActivityMain.java

@Override
public void onClick(View view) {
    int id = view.getId();
    ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
    switch (id) {
    case R.id.chat_send:

        smiliesShell.setVisibility(View.GONE);
        EditText message = (EditText) findViewById(R.id.chat_text);
        String messageT = message.getText().toString();
        if (messageT.length() == 0) {
            Toast.makeText(this, R.string.no_message, Toast.LENGTH_SHORT).show();
            return;
        }//from   w ww . ja v a 2  s  .  com
        if (messageT.length() > 140) {
            Toast.makeText(this, R.string.message_too_long, Toast.LENGTH_SHORT).show();
            return;
        }
        nvp.add(new BasicNameValuePair("message", messageT));
        doSubmit("chatform", nvp, true);
        doChatScroll = true;
        break;
    case R.id.med_send:
        int w = walkingPicker.getValue();
        int s = sittingPicker.getValue();

        if (w == 0 && s == 0) {
            Toast.makeText(this, R.string.no_time, Toast.LENGTH_SHORT).show();
            return;
        }

        SharedPreferences.Editor editor = prefs.edit();
        editor.putInt("walking", w);
        editor.putInt("sitting", s);
        editor.apply();

        lastWalking = w * 5;
        lastSitting = s * 5;

        startMeditating = true;

        nvp.add(new BasicNameValuePair("walking", lastWalking + ""));
        nvp.add(new BasicNameValuePair("sitting", lastSitting + ""));
        doSubmit("timeform", nvp, true);
        break;
    case R.id.med_cancel:

        Intent rIntent = new Intent(this, ReceiverAlarm.class);
        PendingIntent walkPendingIntent = PendingIntent.getBroadcast(context, 0, rIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        PendingIntent sitPendingIntent = PendingIntent.getBroadcast(context, 1, rIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        mAlarmMgr.cancel(walkPendingIntent);
        mAlarmMgr.cancel(sitPendingIntent);
        mNM.cancelAll();

        doSubmit("cancelform", nvp, true);
        break;
    case R.id.smily_button:
        if (smiliesShell.getVisibility() == View.GONE)
            smiliesShell.setVisibility(View.VISIBLE);
        else
            smiliesShell.setVisibility(View.GONE);
        break;
    case R.id.chat_text:
        smiliesShell.setVisibility(View.GONE);
        singleClick++;
        Handler handler = new Handler();
        Runnable r = new Runnable() {

            @Override
            public void run() {
                singleClick = 0;
            }
        };

        if (singleClick == 1) {
            //Single click
            handler.postDelayed(r, 250);
        } else if (singleClick == 2) {
            //Double click
            singleClick = 0;
            ((EditText) findViewById(R.id.chat_text)).setText("");
        }
        break;
    case R.id.new_commit:
        Intent i = new Intent(this, ActivityCommit.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
        break;
    default:
        smiliesShell.setVisibility(View.GONE);
        break;
    }
}