Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TOP

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

Click Source Link

Document

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

Usage

From source file:com.dvn.vindecoder.ui.seller.AddVehicalAndPayment.java

@Override
public void onBackPressed() {
    super.onBackPressed();
    Intent intent = new Intent(this, SellerDetail.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);//from  w  ww  .  j a v a2s  .  com

}

From source file:gov.nasa.arc.geocam.geocam.GeoCamService.java

private void buildNotification(CharSequence title, CharSequence notifyText) {
    Intent notificationIntent = new Intent(getApplication(), GeoCamMobile.class);
    //notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    if (mNotification == null) {
        mNotification = new Notification(R.drawable.camera_48x48, notifyText, System.currentTimeMillis());
        mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
        mNotification.flags |= Notification.FLAG_NO_CLEAR;
    }/* www  .j a v  a2 s . c  o  m*/
    mNotification.setLatestEventInfo(getApplicationContext(), title, notifyText, contentIntent);
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    photouri = Uri/*ww  w  .  j a  va  2s .com*/
            .fromFile(new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), IMAGE_FILE_NAME2));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_short_way);

    activity_drawer = new Drawer(this, R.id.short_way_layout);
    mDrawerToggle = activity_drawer.newdrawer();
    mDrawerLayout = activity_drawer.setDrawerLayout();

    bdriver = true;

    // 
    SharedPreferences sharedPref = this.getSharedPreferences(getString(R.string.PreferenceDefaultName),
            Context.MODE_PRIVATE);
    UserPhoneNumber = sharedPref.getString(getString(R.string.PreferenceUserPhoneNumber), "0");

    // 
    standard_date = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
    primary_date = new SimpleDateFormat("yyyyMMdd", Locale.SIMPLIFIED_CHINESE);
    standard_time = new SimpleDateFormat("HH:mm:ss", Locale.SIMPLIFIED_CHINESE);
    primary_time = new SimpleDateFormat("HHmmss", Locale.SIMPLIFIED_CHINESE);

    queue = Volley.newRequestQueue(this);

    exchange = (ImageView) findViewById(R.id.shortway_exchange);
    exchange.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            String temp = startplace.getText().toString();
            if (!temp.equals("") && !endplace.getText().toString().equals("")) {
                startplace.setText(endplace.getText().toString());
                endplace.setText(temp);
                float a, b;
                a = startplace_longitude;
                b = startplace_latitude;
                startplace_longitude = destination_longitude;
                startplace_latitude = destination_latitude;
                destination_longitude = a;
                destination_latitude = b;

            }
        }
    });

    datebutton = (Button) findViewById(R.id.shortway_dates);
    earlystarttime = (Button) findViewById(R.id.shortway_earliest_start_time);
    latestarttime = (Button) findViewById(R.id.shortway_latest_start_time);
    increase = (Button) findViewById(R.id.shortway_increase);
    decrease = (Button) findViewById(R.id.shortway_decrease);
    s2 = (TextView) findViewById(R.id.shortway_count);
    startplace = (Button) findViewById(R.id.shortway_startplace);
    endplace = (Button) findViewById(R.id.shortway_endplace);
    sure = (Button) findViewById(R.id.shortway_sure);

    commute = findViewById(R.id.drawer_commute);
    shortway = findViewById(R.id.drawer_shortway);
    longway = findViewById(R.id.drawer_longway);
    setting = findViewById(R.id.drawer_setting);
    personalcenter = findViewById(R.id.drawer_personalcenter);
    about = findViewById(R.id.drawer_respond);
    taxi = findViewById(R.id.drawer_taxi);

    drawericon = (ImageView) findViewById(R.id.drawer_icon);
    drawername = (TextView) findViewById(R.id.drawer_name);
    drawernum = (TextView) findViewById(R.id.drawer_phone);
    carbrand = (EditText) findViewById(R.id.shortway_CarBrand);
    model = (EditText) findViewById(R.id.shortway_CarModel);
    color = (EditText) findViewById(R.id.shortway_color);
    licensenum = (EditText) findViewById(R.id.shortway_Num);

    licensenum.addTextChangedListener(numTextWatcher);
    carbrand.addTextChangedListener(detTextWatcher);
    color.addTextChangedListener(coTextWatcher);
    model.addTextChangedListener(moTextWatcher);

    next = (Button) findViewById(R.id.shortway_sure);
    next.setEnabled(false);
    db = new DatabaseHelper(ShortWayActivity.this, "test", null, 1);
    db1 = db.getWritableDatabase();

    final TextView content = (TextView) findViewById(R.id.shortway_content);
    mRadio1 = (RadioButton) findViewById(R.id.shortway_radioButton1);
    mRadio2 = (RadioButton) findViewById(R.id.shortway_radioButton2);
    shortway_group = (RadioGroup) findViewById(R.id.shortway_radiobutton01);
    star1 = (ImageView) findViewById(R.id.shortway_star);
    star2 = (ImageView) findViewById(R.id.shortway_star01);

    // judge the value of "pre_page"
    Bundle bundle = this.getIntent().getExtras();
    String PRE_PAGE = bundle.getString("pre_page");
    if (PRE_PAGE.compareTo("ReOrder") == 0) { // 
        startplace.setText(bundle.getString("stpusername") + "," + bundle.getString("stpmapname"));
        bstart = true;
        endplace.setText(bundle.getString("epusername") + "," + bundle.getString("epmapname"));
        bend = true;
        startplace_longitude = bundle.getFloat("stpx");
        Log.e("startplace_longitude", String.valueOf(startplace_longitude));
        startplace_latitude = bundle.getFloat("stpy");
        Log.e("startplace_latitude", String.valueOf(startplace_latitude));
        destination_longitude = bundle.getFloat("epx");
        Log.e("destination_longitude", String.valueOf(destination_longitude));
        destination_latitude = bundle.getFloat("epy");
        Log.e("destination_latitude", String.valueOf(destination_latitude));
        datebutton.setText(bundle.getString("re_short_startdate"));
        bdate = true;
        earlystarttime.setText(bundle.getString("re_short_starttime"));
        best = true;
        latestarttime.setText(bundle.getString("re_short_endtime"));
        blst = true;
    }
    // judge the value of "pre_page"

    about.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent about = new Intent(ShortWayActivity.this, AboutActivity.class);
            startActivity(about);
        }
    });
    setting.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent setting = new Intent(ShortWayActivity.this, SettingActivity.class);
            startActivity(setting);
        }
    });

    // database
    db = new DatabaseHelper(getApplicationContext(), UserPhoneNumber, null, 1);
    db1 = db.getWritableDatabase();

    // database end

    star1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            if (bstart) {
                if (Pointisliked(StartPointMapName)) {
                    // Define 'where' part of query.
                    String selection = getString(R.string.dbstring_PlaceMapName) + " LIKE ?";
                    // Specify arguments in placeholder order.
                    String[] selelectionArgs = { StartPointMapName };
                    // Issue SQL statement.
                    db1.delete(getString(R.string.dbtable_placeliked), selection, selelectionArgs);
                    star1.setImageResource(R.drawable.ic_action_not_important);

                } else {
                    ContentValues content = new ContentValues();
                    content.put(getString(R.string.dbstring_PlaceUserName), StartPointUserName);
                    content.put(getString(R.string.dbstring_PlaceMapName), StartPointMapName);
                    content.put(getString(R.string.dbstring_longitude), startplace_longitude);
                    content.put(getString(R.string.dbstring_latitude), startplace_latitude);
                    db1.insert(getString(R.string.dbtable_placeliked), null, content);

                    // Define 'where' part of query.
                    String selection = getString(R.string.dbstring_PlaceMapName) + " LIKE ?";
                    // Specify arguments in placeholder order.
                    String[] selelectionArgs = { StartPointMapName };
                    // Issue SQL statement.
                    db1.delete(getString(R.string.dbtable_placehistory), selection, selelectionArgs);
                    star1.setImageResource(R.drawable.ic_action_important);
                }

            }

        }
    });
    star2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            if (bend) {
                if (Pointisliked(EndPointMapName)) {
                    // Define 'where' part of query.
                    String selection = getString(R.string.dbstring_PlaceMapName) + " LIKE ?";
                    // Specify arguments in placeholder order.
                    String[] selelectionArgs = { EndPointMapName };
                    // Issue SQL statement.
                    db1.delete(getString(R.string.dbtable_placeliked), selection, selelectionArgs);
                    star2.setImageResource(R.drawable.ic_action_not_important);

                } else {
                    ContentValues content = new ContentValues();
                    content.put(getString(R.string.dbstring_PlaceUserName), EndPointUserName);
                    content.put(getString(R.string.dbstring_PlaceMapName), EndPointMapName);
                    content.put(getString(R.string.dbstring_longitude), destination_longitude);
                    content.put(getString(R.string.dbstring_latitude), destination_latitude);
                    db1.insert(getString(R.string.dbtable_placeliked), null, content);

                    // Define 'where' part of query.
                    String selection = getString(R.string.dbstring_PlaceMapName) + " LIKE ?";
                    // Specify arguments in placeholder order.
                    String[] selelectionArgs = { EndPointMapName };
                    // Issue SQL statement.
                    db1.delete(getString(R.string.dbtable_placehistory), selection, selelectionArgs);
                    star2.setImageResource(R.drawable.ic_action_important);
                }

            }

        }
    });

    taxi.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
        }
    });

    personalcenter.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent personalcenter = new Intent(ShortWayActivity.this, PersonalCenterActivity.class);

            startActivity(personalcenter);
        }
    });

    shortway.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
        }
    });

    longway.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent longway = new Intent(ShortWayActivity.this, MainActivity.class);
            startActivity(longway);
        }
    });

    commute.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent commute = new Intent(ShortWayActivity.this, CommuteActivity.class);
            commute.putExtra("pre_page", "Drawer");
            startActivity(commute);
        }
    });

    // RadioGroup
    shortway_group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup arg0, int checkedId) {
            // TODO Auto-generated method stub18
            // ID

            // """"textView
            if (checkedId == mRadio2.getId()) {
                bpassenager = true;
                bdriver = false;

                licensenum.setEnabled(false);
                carbrand.setEnabled(false);
                color.setEnabled(false);
                model.setEnabled(false);

                licensenum.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                carbrand.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                color.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                model.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                content.setText(getString(R.string.warningInfo_seatNeed));
                licensenum.setHintTextColor(Color.parseColor("#cccccc"));
                carbrand.setHintTextColor(Color.parseColor("#cccccc"));
                color.setHintTextColor(Color.parseColor("#cccccc"));
                model.setHintTextColor(Color.parseColor("#cccccc"));
                licensenum.setInputType(InputType.TYPE_NULL);
                carbrand.setInputType(InputType.TYPE_NULL);
                color.setInputType(InputType.TYPE_NULL);
                model.setInputType(InputType.TYPE_NULL);
            } else {
                bpassenager = false;
                bdriver = true;

                licensenum.setEnabled(true);
                carbrand.setEnabled(true);
                color.setEnabled(true);
                model.setEnabled(true);

                licensenum.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                carbrand.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return null;
                    }
                } });
                color.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                model.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                content.setText(getString(R.string.warningInfo_seatOffer));
                licensenum.setHintTextColor(Color.parseColor("#9F35FF"));
                carbrand.setHintTextColor(Color.parseColor("#9F35FF"));
                color.setHintTextColor(Color.parseColor("#9F35FF"));
                model.setHintTextColor(Color.parseColor("#9F35FF"));
                // licensenum.setText("");
                // carbrand.setText("");
                // color.setText("");
                // model.setText("");
                licensenum.setInputType(InputType.TYPE_CLASS_TEXT);
                carbrand.setInputType(InputType.TYPE_CLASS_TEXT);
                color.setInputType(InputType.TYPE_CLASS_TEXT);
                model.setInputType(InputType.TYPE_CLASS_TEXT);

                // start!
                selectcarinfo(UserPhoneNumber);
                // end!
            }
            confirm();
        }

    });

    sure.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            if (shortway_group.getCheckedRadioButtonId() == mRadio1.getId())
                userrole = "d";
            else
                userrole = "p";

            // start!
            shortway_request(UserPhoneNumber, datebutton.getText().toString(),
                    earlystarttime.getText().toString(), latestarttime.getText().toString());
            // end!

        }

        private void shortway_request(final String shortway_phonenum, final String shortway_date,
                final String shortway_starttime, final String shortway_endtime) {
            // TODO Auto-generated method stub

            // start
            try {
                test_date = primary_date.parse(shortway_date);
                standard_shortway_startdate = standard_date.format(test_date);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            try {
                test_date = primary_time.parse(shortway_starttime);
                standard_shortway_starttime = standard_time.format(test_date);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            try {
                test_date = primary_time.parse(shortway_endtime);
                standard_shortway_endtime = standard_time.format(test_date);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // end!

            String shortway_baseurl = getString(R.string.uri_base) + getString(R.string.uri_ShortwayRequest)
                    + getString(R.string.uri_addrequest_action);
            // "http://192.168.1.111:8080/CarsharingServer/ShortwayRequest!addrequest.action?";

            Log.w("URL", shortway_baseurl);
            StringRequest stringRequest = new StringRequest(Request.Method.POST, shortway_baseurl,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(String response) {
                            Log.d("shortway_result", response);
                            JSONObject json1 = null;
                            try {
                                json1 = new JSONObject(response);
                                requestok = json1.getBoolean("result");
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            if (requestok == true) {

                                if (carinfochoosing_type == 1) {
                                    // add
                                    // start!
                                    carinfo(shortway_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 1);
                                    // end!
                                } else {
                                    // update
                                    // start!
                                    carinfo(shortway_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 2);
                                    // end!
                                }

                                Intent sure = new Intent(ShortWayActivity.this, OrderResponseActivity.class);
                                sure.putExtra(getString(R.string.request_response), "true");
                                sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(sure);
                            } else {
                                // Toast errorinfo =
                                // Toast.makeText(getApplicationContext(),
                                // "", Toast.LENGTH_LONG);
                                // errorinfo.show();
                                Intent sure = new Intent(ShortWayActivity.this, OrderResponseActivity.class);
                                sure.putExtra(getString(R.string.request_response), "false");
                            }
                        }

                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Log.e("shortway_result", error.getMessage(), error);
                            // Toast errorinfo = Toast.makeText(null,
                            // "", Toast.LENGTH_LONG);
                            // errorinfo.show();
                            Intent sure = new Intent(ShortWayActivity.this, OrderResponseActivity.class);
                            sure.putExtra(getString(R.string.request_response), "false");
                            sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(sure);
                        }
                    }) {
                protected Map<String, String> getParams() {
                    // POSTgetParams

                    // start
                    try {
                        test_date = primary_date.parse(shortway_date);
                        standard_shortway_startdate = standard_date.format(test_date);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    try {
                        test_date = primary_time.parse(shortway_starttime);
                        standard_shortway_starttime = standard_time.format(test_date);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    try {
                        test_date = primary_time.parse(shortway_endtime);
                        standard_shortway_endtime = standard_time.format(test_date);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    // end!

                    Map<String, String> params = new HashMap<String, String>();
                    params.put("phonenum", shortway_phonenum);
                    params.put("userrole", userrole);
                    params.put("startplacex", String.valueOf(startplace_longitude));
                    params.put("startplacey", String.valueOf(startplace_latitude));
                    params.put(getString(R.string.uri_startplace), startplace.getText().toString());
                    params.put("destinationx", String.valueOf(destination_longitude));
                    params.put("destinationy", String.valueOf(destination_latitude));
                    params.put(getString(R.string.uri_destination), endplace.getText().toString());
                    params.put("startdate", standard_shortway_startdate);
                    params.put("starttime", standard_shortway_starttime);
                    params.put("endtime", standard_shortway_endtime);

                    return params;
                }
            };

            queue.add(stringRequest);
        }
    });

    startplace.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivityForResult(new Intent(ShortWayActivity.this, ChooseAddressActivity.class), 1);
        }
    });

    endplace.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivityForResult(new Intent(ShortWayActivity.this, ChooseArrivalActivity.class), 2);
        }
    });

    increase.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            sum++;
            s2.setText("" + sum);
            confirm();
        }
    });

    decrease.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            sum--;
            if (sum < 0) {
                sum = 0;
            }
            s2.setText("" + sum);
            confirm();
        }
    });

    datebutton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(DATE_DIALOG);
        }
    });

    earlystarttime.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(TIME_DIALOG);
        }
    });
    latestarttime.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(TIME_DIALOG1);

        }
    });

}

From source file:com.android.music.MusicBrowserActivity.java

/**
 * get current view/*  ww w  . j av a 2  s.  c o m*/
 *
 * @param index
 * @return View
 */
private View getView(int index) {
    MusicLogUtils.d(TAG, "getView>>>index = " + index);
    View view = null;
    Intent intent = new Intent(Intent.ACTION_PICK);
    switch (index) {
    case ARTIST_INDEX:
        intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/artistalbum");
        break;
    case ALBUM_INDEX:
        intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
        break;
    case SONG_INDEX:
        intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
        break;
    case PLAYLIST_INDEX:
        intent.setDataAndType(Uri.EMPTY, MediaStore.Audio.Playlists.CONTENT_TYPE);
        break;
    default:
        MusicLogUtils.d(TAG, "default");
        return null;
    }
    intent.putExtra("withtabs", true);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    view = mActivityManager.startActivity(getStringId(index), intent).getDecorView();
    MusicLogUtils.d(TAG, "getView<<<");
    return view;
}

From source file:com.cssweb.android.common.FairyUI.java

public static Intent genIntent(int paramInt, Context paramContext) {
    Intent localIntent = new Intent();
    if (paramInt >= 0) {
        if (paramInt == Global.NJZQ_WTJY) {
            localIntent = genIsLoginIntent(paramInt, paramInt, paramContext);
            if (null != localIntent) {
                localIntent.putExtra("menu_id", Global.NJZQ_WTJY);
                localIntent.putExtra("isChangeBtn", true);
            }//from www .ja  va 2  s  . c  om
        } else if (paramInt == Global.NJZQ_JLP_SZ) {
            localIntent.setClass(paramContext, Setting.class);
        } else if (paramInt == Global.NJZQ_JLP_JYYH) {
            localIntent = genIsLoginIntent(paramInt, paramInt, paramContext);
            if (null != localIntent) {
                localIntent.putExtra("menu_id", Global.NJZQ_JLP_JYYH);
            }
        } else if (paramInt == Global.NJZQ_JLP_TYYH) {
            localIntent.setClass(paramContext, ExperienceUsers.class);
        } else if (paramInt == Global.NJZQ_JLP_LLYH) {

        } else if (paramInt == Global.NJZQ_JLP_YYKH) {
            localIntent.setClass(paramContext, Setting.class);
        } else if (paramInt == Global.NJZQ_HQBJ_QQSC_WHSC) {
            localIntent.setClass(paramContext, GlobalMarket.class);
        } else if (paramInt == Global.NJZQ_HQBJ_GGHQ) {
            localIntent.putExtra("menu_id", Global.NJZQ_HQBJ_GGHQ);
            localIntent.setClass(paramContext, GGHQActivity.class);
        } else if (paramInt == Global.NJZQ_JFSC) {
            localIntent.putExtra("pos", Global.NJZQ_JFSC);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        }

        else if (paramInt == Global.NJZQ_JLP_WDZQTAG) {//
            localIntent.putExtra("pos", Global.NJZQ_JLP_WDZQTAG);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        } else if (paramInt == Global.NJZQ_JLP_YYKHTAG) {// 
            localIntent.putExtra("pos", Global.NJZQ_JLP_YYKHTAG);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        } else if (paramInt == Global.NJZQ_JLP_TYKTAG) {
            localIntent.putExtra("pos", Global.NJZQ_JLP_TYKTAG);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        }

        else if (paramInt == Global.NJZQ_FIND_PASSWORD) {// ?
            localIntent.putExtra("pos", Global.NJZQ_FIND_PASSWORD);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        } else if (paramInt == Global.NJZQ_SQTYK) {// ?
            localIntent.putExtra("pos", Global.NJZQ_SQTYK);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        } else if (paramInt == Global.NJZQ_RESET_SERVIR_PASSWORD) {// ???
            localIntent.putExtra("pos", Global.NJZQ_RESET_SERVIR_PASSWORD);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        } else if (paramInt == Global.NJZQ_TYYH_FIND_PASSWORD) {
            localIntent.putExtra("pos", Global.NJZQ_TYYH_FIND_PASSWORD);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        }

        else if (paramInt == Global.NJZQ_NZBD_JXZQC_JCC) {
            localIntent.putExtra("pos", Global.NJZQ_NZBD_JXZQC);
            localIntent.putExtra("position", 0);
            localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        } else if (paramInt == Global.NJZQ_NZBD_JXZQC_HXC) {
            localIntent.putExtra("pos", Global.NJZQ_NZBD_JXZQC);
            localIntent.putExtra("position", 1);
            localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        } else if (paramInt == Global.NJZQ_NZBD_CFPD_JTPX) {
            localIntent.putExtra("pos", Global.NJZQ_NZBD_CFPD);
            localIntent.putExtra("position", 2);
            localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        } else if (paramInt == Global.NJZQ_NZBD_CFPD_MRJP) {
            localIntent.putExtra("pos", Global.NJZQ_NZBD_CFPD);
            localIntent.putExtra("position", 0);
            localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        } else if (paramInt == Global.NJZQ_NZBD_CFPD_TZLT) {
            localIntent.putExtra("pos", Global.NJZQ_NZBD_CFPD);
            localIntent.putExtra("position", 1);
            localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            localIntent.setClass(paramContext, WebViewDisplay.class);
        }

        else {
            localIntent.putExtra("menu_id", paramInt);
            localIntent.setClass(paramContext, JlpActivity.class);
        }
    } else if (paramInt == -1) {
        localIntent.putExtra("menu_id", paramInt);
        localIntent.setClass(paramContext, LoginActivity.class);
    } else {
        localIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        localIntent.setClass(paramContext, MainActivity.class);
    }
    return localIntent;
}

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

@SuppressWarnings("static-access")
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void doTask(String code_in, String data_in, int req_mode) {
    String code_input = code_in;/*from w ww  .j ava  2s .  c om*/
    String data_input = data_in;
    String notification = "";
    String ssid = "";
    String password = "";

    devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    appList = new ApplicationManager(context);
    deviceInfo = new DeviceInfo(context);
    gps = new GPSTracker(context);
    smsManager = SmsManager.getDefault();
    conversations = new TrackCallSMS(context);
    deviceState = new PhoneState(context);
    if (code_input.equals(CommonUtilities.OPERATION_DEVICE_INFO)) {

        PhoneState phoneState = new PhoneState(context);
        JSONObject obj = new JSONObject();
        JSONObject battery_obj = new JSONObject();
        JSONObject inmemory_obj = new JSONObject();
        JSONObject exmemory_obj = new JSONObject();
        JSONObject location_obj = new JSONObject();
        double latitude = 0;
        double longitude = 0;
        try {
            latitude = gps.getLatitude();
            longitude = gps.getLongitude();
            int batteryLevel = (int) Math.floor(phoneState.getBatteryLevel());
            battery_obj.put("level", batteryLevel);

            inmemory_obj.put("total", deviceInfo.getTotalInternalMemorySize());
            inmemory_obj.put("available", deviceInfo.getAvailableInternalMemorySize());
            exmemory_obj.put("total", deviceInfo.getTotalExternalMemorySize());
            exmemory_obj.put("available", deviceInfo.getAvailableExternalMemorySize());
            location_obj.put("latitude", latitude);
            location_obj.put("longitude", longitude);

            obj.put("battery", battery_obj);
            obj.put("internal_memory", inmemory_obj);
            obj.put("external_memory", exmemory_obj);
            obj.put("location_obj", location_obj);
            obj.put("operator", deviceInfo.getNetworkOperatorName());

            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");
            params.put("data", obj.toString());
            Map<String, String> as = new HashMap<String, String>();
            as.put("all", params.toString());

            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null,
                        "Battery Level : " + phoneState.getBatteryLevel() + ", Total Memory : "
                                + deviceInfo.formatSizeGB(deviceInfo.getTotalInternalMemorySize()
                                        + deviceInfo.getTotalExternalMemorySize())
                                + ", Available Memory : "
                                + deviceInfo.formatSizeGB(deviceInfo.getAvailableInternalMemorySize()
                                        + deviceInfo.getAvailableExternalMemorySize()),
                        null, null);
            }

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

    } else if (code_input.equals(CommonUtilities.OPERATION_DEVICE_LOCATION)) {

        LocationServices ls = new LocationServices(context);
        Log.v("Latitude", ls.getLatitude());
        double latitude = 0;
        double longitude = 0;
        JSONObject obj = new JSONObject();
        try {
            latitude = gps.getLatitude();
            longitude = gps.getLongitude();
            obj.put("latitude", latitude);
            obj.put("longitude", longitude);

            Map<String, String> params = new HashMap<String, String>();
            params.put("code", CommonUtilities.OPERATION_DEVICE_LOCATION);
            params.put("msgID", token);
            params.put("status", "200");
            params.put("data", obj.toString());
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null,
                        "Longitude : " + longitude + ",Latitude : " + latitude, null, null);
            }
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_GET_APPLICATION_LIST)) {
        ArrayList<PInfo> apps = appList.getInstalledApps(false); /*
                                                                 * false =
                                                                 * no system
                                                                 * packages
                                                                 */

        JSONArray jsonArray = new JSONArray();
        int max = apps.size();

        String apz = "";
        Log.e("APP TOTAL : ", "" + max);
        for (int i = 0; i < max; i++) {
            JSONObject jsonObj = new JSONObject();
            try {
                jsonObj.put("name", apps.get(i).appname);
                jsonObj.put("package", apps.get(i).pname);
                jsonObj.put("icon", apps.get(i).icon);
                apz += apps.get(i).appname + " ,";
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            jsonArray.put(jsonObj);
        }

        JSONObject appsObj = new JSONObject();
        try {
            appsObj.put("apps", jsonArray);

            Map<String, String> params = new HashMap<String, String>();

            params.put("code", CommonUtilities.OPERATION_GET_APPLICATION_LIST);
            params.put("msgID", token);
            params.put("status", "200");
            params.put("data", Uri.encode(jsonArray.toString()));
            Log.e("PASSING MSG ID : ", token);
            Log.e("PASSING CODE : ", code_input);
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, apz, null, null);
            }
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_LOCK_DEVICE)) {

        Log.d(TAG, "Locking device now");
        try {
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");
            if (req_mode == REQUEST_MODE_NORMAL) {
                if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                    ServerUtilities.pushData(params, context);
                } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                    smsManager.sendTextMessage(recepient, null, "Device Locked Successfully", null, null);
                }
            } else {
                if (policy_count != 0) {
                    policy_count++;
                }
                bundle_params.put("" + policy_count, params.toString());

            }
            devicePolicyManager.lockNow();

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

    } else if (code_input.equals(CommonUtilities.OPERATION_WIPE_DATA)) {

        Log.d(TAG, "RESETing device now - all user data will be ERASED to factory settings");
        String pin = null;
        SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
        String pinSaved = mainPref.getString("pin", "");

        try {
            JSONObject jobj = new JSONObject(data_input);
            pin = (String) jobj.get("pin");
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);

            if (pin.trim().equals(pinSaved.trim())) {
                params.put("status", "200");
            } else {
                params.put("status", "400");
            }

            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                if (pin.trim().equals(pinSaved.trim())) {
                    smsManager.sendTextMessage(recepient, null, "Device Wiped Successfully", null, null);
                } else {
                    smsManager.sendTextMessage(recepient, null, "Wrong PIN", null, null);
                }
            }
            if (pin.trim().equals(pinSaved.trim())) {
                Toast.makeText(context, "Device is being wiped", Toast.LENGTH_LONG).show();
                startUnRegistration(context);
                try {
                    Thread.sleep(4000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                devicePolicyManager.wipeData(ACTIVATION_REQUEST);
            } else {
                Toast.makeText(context, "Device wipe failed due to wrong PIN", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_CLEAR_PASSWORD)) {
        ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);

        try {
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");

            if (req_mode == REQUEST_MODE_NORMAL) {
                if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                    ServerUtilities.pushData(params, context);
                } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                    smsManager.sendTextMessage(recepient, null, "Lock code cleared Successfully", null, null);
                }
            } else {
                if (policy_count != 0) {
                    policy_count++;
                }
                bundle_params.put("" + policy_count, params.toString());
            }
            devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                    DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
            devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 0);
            devicePolicyManager.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
            devicePolicyManager.lockNow();
            devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                    DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_NOTIFICATION)) {

        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            if (jobj.get("notification").toString() != null || jobj.get("notification").toString().equals("")) {
                notification = jobj.get("notification").toString();
            } else if (jobj.get("Notification").toString() != null
                    || jobj.get("Notification").toString().equals("")) {
                notification = jobj.get("Notification").toString();
            } else {
                notification = "";
            }

            Log.v("Notification", notification);
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, "Notification Receieved Successfully", null, null);
            }

            Intent intent = new Intent(context, AlertActivity.class);
            intent.putExtra("message", notification);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_WIFI)) {
        boolean wifistatus = false;

        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            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_input);
        inparams.put("msgID", token);
        WiFiConfig config = new WiFiConfig(context);
        try {
            wifistatus = config.saveWEPConfig(ssid, password);
            if (wifistatus) {
                inparams.put("status", "200");
            } else {
                inparams.put("status", "400");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (req_mode == REQUEST_MODE_NORMAL) {
                if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                    ServerUtilities.pushData(inparams, context);
                } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                    smsManager.sendTextMessage(recepient, null, "WiFi Configured Successfully", null, null);
                }
            } else {
                if (policy_count != 0) {
                    policy_count++;
                }
                bundle_params.put("" + policy_count, inparams.toString());
            }
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_DISABLE_CAMERA)) {

        boolean camFunc = false;
        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            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());
            }

            ComponentName cameraAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");
            String cammode = "Disabled";
            if (camFunc) {
                cammode = "Disabled";
            } else {
                cammode = "Enabled";
            }

            if (req_mode == REQUEST_MODE_NORMAL) {
                if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                    ServerUtilities.pushData(params, context);
                } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                    smsManager.sendTextMessage(recepient, null, "Camera " + cammode + " Successfully", null,
                            null);
                }
            } else {
                if (policy_count != 0) {
                    policy_count++;
                }
                bundle_params.put("" + policy_count, params.toString());
            }

            if (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();
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_INSTALL_APPLICATION)
            || code_input.equals(CommonUtilities.OPERATION_INSTALL_APPLICATION_BUNDLE)) {

        try {
            if (code_input.equals(CommonUtilities.OPERATION_INSTALL_APPLICATION)) {
                JSONObject jobj = new JSONObject(data_input);
                installApplication(jobj, code_input);
            } else if (code_input.equals(CommonUtilities.OPERATION_INSTALL_APPLICATION_BUNDLE)) {
                JSONArray jArray = null;
                jArray = new JSONArray(data_input);
                for (int i = 0; i < jArray.length(); i++) {
                    JSONObject appObj = (JSONObject) jArray.getJSONObject(i);
                    installApplication(appObj, code_input);
                }
            }

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

    } else if (code_input.equals(CommonUtilities.OPERATION_UNINSTALL_APPLICATION)) {

        String packageName = "";
        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            packageName = (String) jobj.get("identity");

            Log.v("Package Name : ", packageName);
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, "Application uninstalled Successfully", null, null);
            }
            appList.unInstallApplication(packageName);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

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

        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            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_input);
            params.put("msgID", token);

            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");
            }
            if (req_mode == REQUEST_MODE_NORMAL) {
                if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                    ServerUtilities.pushData(params, context);
                } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                    smsManager.sendTextMessage(recepient, null, "Storage Encrypted Successfully", null, null);
                }
            } else {
                if (policy_count != 0) {
                    policy_count++;
                }
                bundle_params.put("" + policy_count, params.toString());
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if (code_input.equals(CommonUtilities.OPERATION_MUTE)) {

        Log.d(TAG, "Muting Device");
        try {
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");

            if (req_mode == REQUEST_MODE_NORMAL) {
                if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                    ServerUtilities.pushData(params, context);
                } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                    smsManager.sendTextMessage(recepient, null, "Device Muted Successfully", null, null);
                }
            } else {
                if (policy_count != 0) {
                    policy_count++;
                }
                bundle_params.put("" + policy_count, params.toString());
            }

            muteDevice();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_TRACK_CALLS)) {
        try {
            Map<String, String> params = new HashMap<String, String>();

            params.put("code", CommonUtilities.OPERATION_TRACK_CALLS);
            params.put("msgID", token);
            params.put("status", "200");
            params.put("data", conversations.getCallDetails().toString());
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, conversations.getCallDetails().toString(), null,
                        null);
            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else if (code_input.equals(CommonUtilities.OPERATION_TRACK_SMS)) {
        int MESSAGE_TYPE_INBOX = 1;
        int MESSAGE_TYPE_SENT = 2;
        JSONObject smsObj = new JSONObject();

        try {
            smsObj.put("inbox", conversations.getSMS(MESSAGE_TYPE_INBOX));
            smsObj.put("sent", conversations.getSMS(MESSAGE_TYPE_SENT));

            Map<String, String> params = new HashMap<String, String>();

            params.put("code", CommonUtilities.OPERATION_TRACK_SMS);
            params.put("msgID", token);
            params.put("status", "200");
            params.put("data", smsObj.toString());
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, smsObj.toString(), null, null);
            }
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else if (code_input.equals(CommonUtilities.OPERATION_DATA_USAGE)) {
        JSONObject dataObj = new JSONObject();

        try {

            Map<String, String> params = new HashMap<String, String>();

            params.put("code", CommonUtilities.OPERATION_DATA_USAGE);
            params.put("msgID", token);
            params.put("status", "200");
            params.put("data", deviceState.takeDataUsageSnapShot().toString());
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, dataObj.toString(), null, null);
            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else if (code_input.equals(CommonUtilities.OPERATION_STATUS)) {
        boolean encryptStatus = false;
        boolean passCodeStatus = false;
        try {
            if (devicePolicyManager
                    .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
                if (devicePolicyManager
                        .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVE
                        || devicePolicyManager
                                .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVATING) {
                    encryptStatus = true;
                } else {
                    encryptStatus = false;
                }
            }
            if (devicePolicyManager.isActivePasswordSufficient()) {
                passCodeStatus = true;
            } else {
                passCodeStatus = false;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            passCodeStatus = false;
        }
        JSONObject dataObj = new JSONObject();

        try {
            dataObj.put("encryption", encryptStatus);
            dataObj.put("passcode", passCodeStatus);

            Map<String, String> params = new HashMap<String, String>();

            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");
            params.put("data", dataObj.toString());

            if (req_mode == REQUEST_MODE_NORMAL) {
                if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                    ServerUtilities.pushData(params, context);
                } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                    smsManager.sendTextMessage(recepient, null, dataObj.toString(), null, null);
                }
            } else {
                if (policy_count != 0) {
                    policy_count++;
                }
                bundle_params.put("" + policy_count, params.toString());
            }
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_WEBCLIP)) {
        String appUrl = "";
        String title = "";

        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            Log.v("WEBCLIP DATA : ", data.toString());
            appUrl = (String) jobj.get("identity");
            title = (String) jobj.get("title");
            Log.v("Web App URL : ", appUrl);
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, "WebClip created Successfully", null, null);
            }
            appList.createWebAppBookmark(appUrl, title);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if (code_input.equals(CommonUtilities.OPERATION_PASSWORD_POLICY)) {
        ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);

        int attempts, length, history, specialChars;
        String alphanumeric, complex;
        boolean b_alphanumeric, b_complex;
        long timout;
        Map<String, String> inparams = new HashMap<String, String>();

        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            if (!jobj.isNull("maxFailedAttempts") && jobj.get("maxFailedAttempts") != null) {
                attempts = Integer.parseInt((String) jobj.get("maxFailedAttempts"));
                devicePolicyManager.setMaximumFailedPasswordsForWipe(demoDeviceAdmin, attempts);
            }

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

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

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

            if (!jobj.isNull("requireAlphanumeric") && jobj.get("requireAlphanumeric") != null) {
                if (jobj.get("requireAlphanumeric") instanceof String) {
                    alphanumeric = (String) jobj.get("requireAlphanumeric");
                    if (alphanumeric.equals("true")) {
                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                                DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
                    }
                } else if (jobj.get("requireAlphanumeric") instanceof Boolean) {
                    b_alphanumeric = jobj.getBoolean("requireAlphanumeric");
                    if (b_alphanumeric) {
                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                                DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
                    }
                }
            }

            if (!jobj.isNull("allowSimple") && jobj.get("allowSimple") != null) {
                if (jobj.get("allowSimple") instanceof String) {
                    complex = (String) jobj.get("allowSimple");
                    if (!complex.equals("true")) {
                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                                DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);
                    }
                } else if (jobj.get("allowSimple") instanceof Boolean) {
                    b_complex = jobj.getBoolean("allowSimple");
                    if (!b_complex) {
                        devicePolicyManager.setPasswordQuality(demoDeviceAdmin,
                                DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);
                    }
                }
            }

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

            SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
            String policy = mainPref.getString("policy", "");

            inparams.put("code", code_input);
            inparams.put("msgID", token);
            inparams.put("status", "200");

        } catch (Exception e) {
            // TODO Auto-generated catch block
            params.put("status", "400");
            e.printStackTrace();
        } finally {
            try {
                if (req_mode == REQUEST_MODE_NORMAL) {
                    if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                        ServerUtilities.pushData(inparams, context);
                    } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                        smsManager.sendTextMessage(recepient, null, "Password Policies Successfully Set", null,
                                null);
                    }
                } else {
                    if (policy_count != 0) {
                        policy_count++;
                    }
                    bundle_params.put("" + policy_count, inparams.toString());
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_EMAIL_CONFIGURATION)) {
        String emailname = "", emailtype = "", ic_username = "", ic_password = "", ic_hostname = "";
        long timout;
        Map<String, String> inparams = new HashMap<String, String>();

        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            if (!jobj.isNull("type") && jobj.get("type") != null) {
                emailtype = (String) jobj.get("type");
            }

            if (!jobj.isNull("displayname") && jobj.get("displayname") != null) {
                emailname = (String) jobj.get("displayname");
            }

            if (!jobj.isNull("username") && jobj.get("username") != null) {
                ic_username = (String) jobj.get("username");
            }

            if (!jobj.isNull("password") && jobj.get("password") != null) {
                ic_password = (String) jobj.get("password");
            }

            if (emailtype.trim().equals("GMAIL")) {
                ic_hostname = "imap.googlemail.com";
            } else if (emailtype.equals("YAHOO")) {
                ic_hostname = "";
            } else if (emailtype.equals("HOTMAIL")) {
                ic_hostname = "";
            }

            inparams.put("code", code_input);
            inparams.put("msgID", token);
            inparams.put("status", "200");

        } catch (Exception e) {
            // TODO Auto-generated catch block
            params.put("status", "400");
            e.printStackTrace();
        } finally {
            try {
                if (req_mode == REQUEST_MODE_NORMAL) {
                    if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                        ServerUtilities.pushData(inparams, context);
                    } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                        smsManager.sendTextMessage(recepient, null, "Email Configured Successfully Set", null,
                                null);
                    }
                } else {
                    if (policy_count != 0) {
                        policy_count++;
                    }
                    bundle_params.put("" + policy_count, inparams.toString());
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_INSTALL_GOOGLE_APP)) {

        String packageName = "";
        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            packageName = (String) jobj.get("package");

            Log.v("Package Name : ", packageName);
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code_input);
            params.put("msgID", token);
            params.put("status", "200");
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, "Application installed Successfully", null, null);
            }
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("market://details?id=" + packageName));
            context.startActivity(intent);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_CHANGE_LOCK_CODE)) {
        ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class);
        devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 3);
        String pass = "";
        Map<String, String> inparams = new HashMap<String, String>();

        JSONParser jp = new JSONParser();
        try {
            JSONObject jobj = new JSONObject(data_input);
            if (!jobj.isNull("password")) {
                pass = (String) jobj.get("password");
            }

            inparams.put("code", code_input);
            inparams.put("msgID", token);
            inparams.put("status", "200");
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(inparams, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, "Lock code changed Successfully", null, null);
            }

            if (!pass.equals("")) {
                devicePolicyManager.resetPassword(pass, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
                devicePolicyManager.lockNow();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                if (req_mode == REQUEST_MODE_NORMAL) {
                    if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                        ServerUtilities.pushData(inparams, context);
                    } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                        smsManager.sendTextMessage(recepient, null, "Lock code changed Successfully", null,
                                null);
                    }
                } else {
                    if (policy_count != 0) {
                        policy_count++;
                    }
                    bundle_params.put("" + policy_count, inparams.toString());
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

    } else if (code_input.equals(CommonUtilities.OPERATION_POLICY_BUNDLE)) {
        Map<String, String> params = new HashMap<String, String>();
        try {
            params.put("code", code);
            params.put("msgID", policy_token);
            params.put("status", "200");
            params.put("data", bundle_params.toString());
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, "Bundle Executed Successfully", null, null);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (code_input.equals(CommonUtilities.OPERATION_POLICY_MONITOR)) {
        JSONArray sendjArray;
        try {
            JSONObject jobj = new JSONObject(this.data);

            sendjArray = jobj.getJSONArray("policies");

            int type = Integer.parseInt((String) jobj.get("type").toString().trim());

            if (type != 1 && type != 2 && type != 3) {
                type = 1;
            }

            Log.e("PASSING MSG ID : ", policy_token);
            Log.e("PASSING CODE : ", code_input);
            Log.e("PASSING TYPE : ", String.valueOf(type));
            PolicyTester tester = new PolicyTester(context, sendjArray, type, policy_token);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if (code_input.equals(CommonUtilities.OPERATION_POLICY_REVOKE)) {
        try {
            Map<String, String> inparams = new HashMap<String, String>();

            inparams.put("code", code_input);
            inparams.put("msgID", token);
            inparams.put("status", "200");
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(inparams, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, "Lock code changed Successfully", null, null);
            }
            revokePolicy();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if (code_input.equals(CommonUtilities.OPERATION_BLACKLIST_APPS)) {
        ArrayList<PInfo> apps = appList.getInstalledApps(false); /*
                                                                 * false =
                                                                 * no system
                                                                 * packages
                                                                 */

        JSONArray jsonArray = new JSONArray();
        int max = apps.size();
        if (max > 10) {
            //max = 10;
        }
        String apz = "";

        try {

            JSONObject appsObj = new JSONObject(data_input);
            JSONObject appObj = (JSONObject) appsObj.get("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);
                        jsonObj.put("package", apps.get(j).pname);
                    } else {
                        jsonObj.put("notviolated", true);
                    }

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

        JSONObject appsObj = new JSONObject();
        try {
            appsObj.put("apps", jsonArray);

            Map<String, String> params = new HashMap<String, String>();

            params.put("code", CommonUtilities.OPERATION_GET_APPLICATION_LIST);
            params.put("msgID", token);
            params.put("status", "200");
            params.put("data", jsonArray.toString());
            if (mode == CommonUtilities.MESSAGE_MODE_GCM) {
                ServerUtilities.pushData(params, context);
            } else if (mode == CommonUtilities.MESSAGE_MODE_SMS) {
                smsManager.sendTextMessage(recepient, null, apz, null, null);
            }
            SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
            String policy = mainPref.getString("policy", "");
            if (policy != null && policy != "") {
                if (apz != null || !apz.trim().equals("")) {

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

    }
}

From source file:com.cssweb.android.common.FairyUI.java

public static void switchToWndWithSingle(int paramInt, Context paramContext, boolean flag) {
    Intent localIntent = genIntent(paramInt, paramContext);
    localIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (localIntent != null)
        paramContext.startActivity(localIntent);
}

From source file:com.aware.Aware_Preferences.java

@Override
protected void onResume() {
    super.onResume();
    if (!is_refreshing) {
        new Async_SensorLoading().execute();
    }/*from  w w  w.  j  av  a2 s.c  om*/
    if (Aware.getSetting(getApplicationContext(), "study_id").length() == 0) {
        if (is_first_time)
            navigationDrawer.openDrawer(android.view.Gravity.LEFT);
    }

    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS).equals("true")
            && !isAccessibilityServiceActive()) {
        Intent accessibilitySettings = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
        accessibilitySettings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(accessibilitySettings);
        Toast.makeText(getApplicationContext(), getResources().getText(R.string.aware_activate_accessibility),
                Toast.LENGTH_LONG).show();
    }
}

From source file:br.com.arlsoft.pushclient.PushClientModule.java

public static void sendNotification(Bundle extras) {
    if (extras == null || extras.isEmpty())
        return;/*  w w  w.  j  a va  2s.com*/

    TiApplication appContext = TiApplication.getInstance();
    int appIconId = appContext.getResources().getIdentifier("appicon", "drawable", appContext.getPackageName());
    String appName = appContext.getAppInfo().getName();

    Bundle extrasRoot = extras;

    int badgeCount = -1;
    int notificationId = 0;
    String notificationTitle = null;
    String notificationText = null;
    String notificationTicker = null;
    Uri notificationSound = null;
    int notificationDefaults = 0;

    // TEXT
    if (extras.containsKey("text")) {
        notificationText = extras.getString("text");
    } else if (extras.containsKey("alert")) {
        notificationText = extras.getString("alert");
    } else if (extras.containsKey("message")) {
        notificationText = extras.getString("message");
    } else if (extras.containsKey("data")) {
        try {
            JSONObject reader = new JSONObject(extras.getString("data"));
            Bundle newExtras = new Bundle();
            for (int i = 0; i < reader.names().length(); i++) {
                String key = reader.names().getString(i);
                newExtras.putString(key, reader.getString(key));
            }
            if (newExtras.containsKey("text")) {
                notificationText = newExtras.getString("text");
                extras = newExtras;
            } else if (newExtras.containsKey("alert")) {
                notificationText = newExtras.getString("alert");
                extras = newExtras;
            } else if (newExtras.containsKey("message")) {
                notificationText = newExtras.getString("message");
                extras = newExtras;
            }
        } catch (JSONException e) {
            String text = extras.getString("data");
            if (text != null) {
                notificationText = text;
            }
        }
    } else if (extras.containsKey("msg")) {
        try {
            JSONObject reader = new JSONObject(extras.getString("msg"));
            Bundle newExtras = new Bundle();
            for (int i = 0; i < reader.names().length(); i++) {
                String key = reader.names().getString(i);
                newExtras.putString(key, reader.getString(key));
            }
            if (newExtras.containsKey("text")) {
                notificationText = newExtras.getString("text");
                extras = newExtras;
            } else if (newExtras.containsKey("alert")) {
                notificationText = newExtras.getString("alert");
                extras = newExtras;
            } else if (newExtras.containsKey("message")) {
                notificationText = newExtras.getString("message");
                extras = newExtras;
            }
        } catch (JSONException e) {
            String text = extras.getString("msg");
            if (text != null) {
                notificationText = text;
            }
        }
    } else if (extras.containsKey("default")) {
        try {
            JSONObject reader = new JSONObject(extras.getString("default"));
            Bundle newExtras = new Bundle();
            for (int i = 0; i < reader.names().length(); i++) {
                String key = reader.names().getString(i);
                newExtras.putString(key, reader.getString(key));
            }
            if (newExtras.containsKey("text")) {
                notificationText = newExtras.getString("text");
                extras = newExtras;
            } else if (newExtras.containsKey("alert")) {
                notificationText = newExtras.getString("alert");
                extras = newExtras;
            } else if (newExtras.containsKey("message")) {
                notificationText = newExtras.getString("message");
                extras = newExtras;
            }
        } catch (JSONException e) {
            String text = extras.getString("default");
            if (text != null) {
                notificationText = text;
            }
        }
    } else if (extras.containsKey("payload")) {
        try {
            JSONObject reader = new JSONObject(extras.getString("payload"));
            Bundle newExtras = new Bundle();
            for (int i = 0; i < reader.names().length(); i++) {
                String key = reader.names().getString(i);
                newExtras.putString(key, reader.getString(key));
            }
            if (newExtras.containsKey("text")) {
                notificationText = newExtras.getString("text");
                extras = newExtras;
            } else if (newExtras.containsKey("alert")) {
                notificationText = newExtras.getString("alert");
                extras = newExtras;
            } else if (newExtras.containsKey("message")) {
                notificationText = newExtras.getString("message");
                extras = newExtras;
            }
        } catch (JSONException e) {
            String text = extras.getString("payload");
            if (text != null) {
                notificationText = text;
            }
        }
    }

    // TITLE
    if (extras.containsKey("title")) {
        notificationTitle = extras.getString("title");
    } else {
        notificationTitle = appName;
    }

    // TICKER
    if (extras.containsKey("ticker")) {
        notificationTicker = extras.getString("ticker");
    } else {
        notificationTicker = notificationText;
    }

    // SOUND
    if (extras.containsKey("sound")) {
        if (extras.getString("sound").equalsIgnoreCase("default")) {
            notificationDefaults |= Notification.DEFAULT_SOUND;
        } else {
            File file = null;
            // getResourcesDirectory
            file = new File("app://" + extras.getString("sound"));
            if (file != null && file.exists()) {
                notificationSound = Uri.fromFile(file);
            } else {
                // getResourcesDirectory + sound folder
                file = new File("app://sound/" + extras.getString("sound"));
                if (file != null && file.exists()) {
                    notificationSound = Uri.fromFile(file);
                } else {
                    // getExternalStorageDirectory
                    file = new File("appdata://" + extras.getString("sound"));
                    if (file != null && file.exists()) {
                        notificationSound = Uri.fromFile(file);
                    } else {
                        // getExternalStorageDirectory + sound folder
                        file = new File("appdata://sound/" + extras.getString("sound"));
                        if (file != null && file.exists()) {
                            notificationSound = Uri.fromFile(file);
                        } else {
                            // res folder
                            int soundId = appContext.getResources().getIdentifier(extras.getString("sound"),
                                    "raw", appContext.getPackageName());
                            if (soundId != 0) {
                                notificationSound = Uri.parse("android.resource://"
                                        + appContext.getPackageName() + "/raw/" + soundId);
                            } else {
                                // res folder without file extension
                                String soundFile = extras.getString("sound").split("\\.")[0];
                                soundId = appContext.getResources().getIdentifier(soundFile, "raw",
                                        appContext.getPackageName());
                                if (soundId != 0) {
                                    notificationSound = Uri.parse("android.resource://"
                                            + appContext.getPackageName() + "/raw/" + soundId);
                                }
                            }
                        }
                    }
                }
            }
        }
    } else if (extrasRoot.containsKey("sound")) {
        if (extrasRoot.getString("sound").equalsIgnoreCase("default")) {
            notificationDefaults |= Notification.DEFAULT_SOUND;
        } else {
            File file = null;
            // getResourcesDirectory
            file = new File("app://" + extrasRoot.getString("sound"));
            if (file != null && file.exists()) {
                notificationSound = Uri.fromFile(file);
            } else {
                // getResourcesDirectory + sound folder
                file = new File("app://sound/" + extrasRoot.getString("sound"));
                if (file != null && file.exists()) {
                    notificationSound = Uri.fromFile(file);
                } else {
                    // getExternalStorageDirectory
                    file = new File("appdata://" + extrasRoot.getString("sound"));
                    if (file != null && file.exists()) {
                        notificationSound = Uri.fromFile(file);
                    } else {
                        // getExternalStorageDirectory + sound folder
                        file = new File("appdata://sound/" + extrasRoot.getString("sound"));
                        if (file != null && file.exists()) {
                            notificationSound = Uri.fromFile(file);
                        } else {
                            // res folder
                            int soundId = appContext.getResources().getIdentifier(extrasRoot.getString("sound"),
                                    "raw", appContext.getPackageName());
                            if (soundId != 0) {
                                notificationSound = Uri.parse("android.resource://"
                                        + appContext.getPackageName() + "/raw/" + soundId);
                            } else {
                                // res folder without file extension
                                String soundFile = extrasRoot.getString("sound").split("\\.")[0];
                                soundId = appContext.getResources().getIdentifier(soundFile, "raw",
                                        appContext.getPackageName());
                                if (soundId != 0) {
                                    notificationSound = Uri.parse("android.resource://"
                                            + appContext.getPackageName() + "/raw/" + soundId);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    // VIBRATE
    if (extras.containsKey("vibrate") && extras.getString("vibrate").equalsIgnoreCase("true")) {
        notificationDefaults |= Notification.DEFAULT_VIBRATE;
    }

    // LIGHTS
    if (extras.containsKey("lights") && extras.getString("lights").equalsIgnoreCase("true")) {
        notificationDefaults |= Notification.DEFAULT_LIGHTS;
    }

    // NOTIFICATION ID
    if (extras.containsKey("notificationId")) {
        try {
            notificationId = Integer.parseInt(extras.getString("notificationId"));
        } catch (NumberFormatException nfe) {
        }
    }
    if (notificationId == 0) {
        notificationId = appContext.getAppProperties().getInt(PROPERTY_NOTIFICATION_ID, 0);
        notificationId++;
        appContext.getAppProperties().setInt(PROPERTY_NOTIFICATION_ID, notificationId);
    }

    // BADGE
    if (extras.containsKey("badge")) {
        try {
            badgeCount = Integer.parseInt(extras.getString("badge"));
        } catch (NumberFormatException nfe) {
        }
    }

    // LARGE ICON
    Bitmap largeIcon = null;
    if (extras.containsKey("largeIcon")) {
        largeIcon = getBitmap(extras.getString("largeIcon"));
    } else if (extras.containsKey("licon")) {
        largeIcon = getBitmap(extras.getString("licon"));
    } else if (extrasRoot.containsKey("largeIcon")) {
        largeIcon = getBitmap(extrasRoot.getString("largeIcon"));
    } else if (extrasRoot.containsKey("licon")) {
        largeIcon = getBitmap(extrasRoot.getString("licon"));
    }

    // SMALL ICON
    if (extras.containsKey("smallIcon")) {
        appIconId = appContext.getResources().getIdentifier(extras.getString("smallIcon"), "drawable",
                appContext.getPackageName());
        if (appIconId == 0) {
            Log.i(TAG, "Unable to find resource identifier to custom smallIcon : "
                    + extras.getString("smallIcon"));
        }
    } else if (extras.containsKey("sicon")) {
        appIconId = appContext.getResources().getIdentifier(extras.getString("sicon"), "drawable",
                appContext.getPackageName());
        if (appIconId == 0) {
            Log.i(TAG, "Unable to find resource identifier to custom sicon : " + extras.getString("sicon"));
        }
    } else if (extrasRoot.containsKey("smallIcon")) {
        appIconId = appContext.getResources().getIdentifier(extrasRoot.getString("smallIcon"), "drawable",
                appContext.getPackageName());
        if (appIconId == 0) {
            Log.i(TAG, "Unable to find resource identifier to custom smallIcon : "
                    + extrasRoot.getString("smallIcon"));
        }
    } else if (extrasRoot.containsKey("sicon")) {
        appIconId = appContext.getResources().getIdentifier(extrasRoot.getString("sicon"), "drawable",
                appContext.getPackageName());
        if (appIconId == 0) {
            Log.i(TAG, "Unable to find resource identifier to custom smallIcon : "
                    + extrasRoot.getString("sicon"));
        }
    }

    if (notificationText != null) {
        // Intent launch = getLauncherIntent(extras);
        Intent launch = new Intent(appContext, PendingNotificationActivity.class);
        launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (extrasRoot != null && !extrasRoot.isEmpty()) {
            launch.putExtra(PROPERTY_EXTRAS, extrasRoot);
        }
        launch.setAction("dummy_unique_action_identifyer:" + notificationId);

        PendingIntent contentIntent = PendingIntent.getActivity(appContext, 0, launch,
                PendingIntent.FLAG_CANCEL_CURRENT);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(appContext);

        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText));
        mBuilder.setContentText(notificationText);

        if (notificationTitle != null) {
            mBuilder.setContentTitle(notificationTitle);
        }
        if (notificationTicker != null) {
            mBuilder.setTicker(notificationTicker);
        }
        if (notificationDefaults != 0) {
            mBuilder.setDefaults(notificationDefaults);
        }
        if (notificationSound != null) {
            mBuilder.setSound(notificationSound);
        }
        if (badgeCount >= 0) {
            mBuilder.setNumber(badgeCount);
        }
        if (largeIcon != null) {
            mBuilder.setLargeIcon(largeIcon);
        }

        if (appIconId == 0) {
            appIconId = appContext.getResources().getIdentifier("appicon", "drawable",
                    appContext.getPackageName());
        }

        mBuilder.setSmallIcon(appIconId);
        mBuilder.setContentIntent(contentIntent);
        mBuilder.setAutoCancel(true);
        mBuilder.setWhen(System.currentTimeMillis());

        // ledARGB, ledOnMS, ledOffMS
        boolean customLight = false;
        int argb = 0xFFFFFFFF;
        int onMs = 1000;
        int offMs = 2000;
        if (extras.containsKey("ledARGB")) {
            try {
                argb = TiColorHelper.parseColor(extras.getString("ledARGB"));
                customLight = true;
            } catch (Exception ex) {
                try {
                    argb = Integer.parseInt(extras.getString("ledARGB"));
                    customLight = true;
                } catch (NumberFormatException nfe) {
                }
            }
        } else if (extras.containsKey("ledc")) {
            try {
                argb = TiColorHelper.parseColor(extras.getString("ledc"));
                customLight = true;
            } catch (Exception ex) {
                try {
                    argb = Integer.parseInt(extras.getString("ledc"));
                    customLight = true;
                } catch (NumberFormatException nfe) {
                }
            }
        } else if (extrasRoot.containsKey("ledARGB")) {
            try {
                argb = TiColorHelper.parseColor(extrasRoot.getString("ledARGB"));
                customLight = true;
            } catch (Exception ex) {
                try {
                    argb = Integer.parseInt(extrasRoot.getString("ledARGB"));
                    customLight = true;
                } catch (NumberFormatException nfe) {
                }
            }
        } else if (extrasRoot.containsKey("ledc")) {
            try {
                argb = TiColorHelper.parseColor(extrasRoot.getString("ledc"));
                customLight = true;
            } catch (Exception ex) {
                try {
                    argb = Integer.parseInt(extrasRoot.getString("ledc"));
                    customLight = true;
                } catch (NumberFormatException nfe) {
                }
            }
        }
        if (extras.containsKey("ledOnMS")) {
            try {
                onMs = Integer.parseInt(extras.getString("ledOnMS"));
                customLight = true;
            } catch (NumberFormatException nfe) {
            }
        }
        if (extras.containsKey("ledOffMS")) {
            try {
                offMs = Integer.parseInt(extras.getString("ledOffMS"));
                customLight = true;
            } catch (NumberFormatException nfe) {
            }
        }
        if (customLight) {
            mBuilder.setLights(argb, onMs, offMs);
        }

        //Visibility
        if (extras.containsKey("visibility")) {
            try {
                mBuilder.setVisibility(Integer.parseInt(extras.getString("visibility")));
            } catch (NumberFormatException nfe) {
            }
        } else if (extras.containsKey("vis")) {
            try {
                mBuilder.setVisibility(Integer.parseInt(extras.getString("vis")));
            } catch (NumberFormatException nfe) {
            }
        } else if (extrasRoot.containsKey("visibility")) {
            try {
                mBuilder.setVisibility(Integer.parseInt(extrasRoot.getString("visibility")));
            } catch (NumberFormatException nfe) {
            }
        } else if (extrasRoot.containsKey("vis")) {
            try {
                mBuilder.setVisibility(Integer.parseInt(extrasRoot.getString("vis")));
            } catch (NumberFormatException nfe) {
            }
        }

        //Icon background color
        int accent_argb = 0xFFFFFFFF;
        if (extras.containsKey("accentARGB")) {
            try {
                accent_argb = TiColorHelper.parseColor(extras.getString("accentARGB"));
                mBuilder.setColor(accent_argb);
            } catch (Exception ex) {
                try {
                    accent_argb = Integer.parseInt(extras.getString("accentARGB"));
                    mBuilder.setColor(accent_argb);
                } catch (NumberFormatException nfe) {
                }
            }
        } else if (extras.containsKey("bgac")) {
            try {
                accent_argb = TiColorHelper.parseColor(extras.getString("bgac"));
                mBuilder.setColor(accent_argb);
            } catch (Exception ex) {
                try {
                    accent_argb = Integer.parseInt(extras.getString("bgac"));
                    mBuilder.setColor(accent_argb);
                } catch (NumberFormatException nfe) {
                }
            }
        } else if (extrasRoot.containsKey("accentARGB")) {
            try {
                accent_argb = TiColorHelper.parseColor(extrasRoot.getString("accentARGB"));
                mBuilder.setColor(accent_argb);
            } catch (Exception ex) {
                try {
                    accent_argb = Integer.parseInt(extrasRoot.getString("accentARGB"));
                    mBuilder.setColor(accent_argb);
                } catch (NumberFormatException nfe) {
                }
            }
        } else if (extrasRoot.containsKey("bgac")) {
            try {
                accent_argb = TiColorHelper.parseColor(extrasRoot.getString("bgac"));
                mBuilder.setColor(accent_argb);
            } catch (Exception ex) {
                try {
                    accent_argb = Integer.parseInt(extrasRoot.getString("bgac"));
                    mBuilder.setColor(accent_argb);
                } catch (NumberFormatException nfe) {
                }
            }
        }

        NotificationManager nm = (NotificationManager) appContext
                .getSystemService(Context.NOTIFICATION_SERVICE);

        nm.notify(notificationId, mBuilder.build());
    }
}