Example usage for android.net Uri fromFile

List of usage examples for android.net Uri fromFile

Introduction

In this page you can find the example usage for android.net Uri fromFile.

Prototype

public static Uri fromFile(File file) 

Source Link

Document

Creates a Uri from a file.

Usage

From source file:com.stroke.academy.common.updater.ApkDownloadUtil.java

public static void installBundledApps(File file) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    AcademyApplication.getInstance().startActivity(intent);
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * Intent???/*from  w  ww .j  a  v a2  s .c  om*/
 *
 * @param intent
 * @param filePaths
 * @param mimeType
 * @return
 */
public static Intent addFiles(Intent intent, ArrayList<String> filePaths, String mimeType) {
    intent.setAction(Intent.ACTION_SEND_MULTIPLE);
    intent.setType(mimeType);
    ArrayList<Uri> uris = new ArrayList<Uri>(filePaths.size());
    for (String filePath : filePaths) {
        uris.add(Uri.fromFile(new File(filePath)));
    }
    intent.putExtra(Intent.EXTRA_STREAM, uris);
    return intent;
}

From source file:com.smapley.vehicle.activity.SetActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {/*from  w  w w .j a va 2 s.c  om*/
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
            case 0:
                List<String> resultList = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
                //?
                Uri sourceUri = Uri.fromFile(new File(resultList.get(0)));
                Uri destinationUri = Uri.fromFile(new File(getCacheDir(), "SampleCropImage.jpeg"));
                UCrop.of(sourceUri, destinationUri).withAspectRatio(1, 1).withMaxResultSize(maxWidth, maxHeight)
                        .start(SetActivity.this);
                break;
            case UCrop.REQUEST_CROP:
                //
                final Uri resultUri = UCrop.getOutput(data);
                File file = new File(resultUri.getPath());
                updatePic(file);
                break;
            }

        }
    } catch (Exception e) {

    }
}

From source file:com.docd.purefm.utils.PFMFileUtils.java

public static void openFileInExternalApp(@NonNull final Context context, @NonNull final File target) {
    final String mime = MimeTypes.getMimeType(target);
    if (mime != null) {
        final Intent i = new Intent(Intent.ACTION_VIEW);
        i.setDataAndType(Uri.fromFile(target), mime);
        final PackageManager packageManager = context.getPackageManager();
        if (packageManager == null) {
            throw new IllegalArgumentException("No PackageManager for context");
        }/*from  w  w w  .j ava 2  s .  com*/
        if (packageManager.queryIntentActivities(i, 0).isEmpty()) {
            Toast.makeText(context, R.string.no_apps_to_open, Toast.LENGTH_SHORT).show();
            return;
        }
        try {
            context.startActivity(i);
        } catch (Exception e) {
            Toast.makeText(context, context.getString(R.string.could_not_open_file_) + e.getMessage(),
                    Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:me.xingrz.finder.ZipFinderActivity.java

private void openFileInZip() {
    if (getExternalCacheDir() == null) {
        Log.e(TAG, "no external cache dir to extract");
        return;//from w  ww. ja  va2 s  .c  o m
    }

    File target = new File(getExternalCacheDir(), extracting.getFileName());
    Intent intent = intentToView(Uri.fromFile(target), mimeOfFile(target));

    if (intent.resolveActivityInfo(getPackageManager(), 0) == null) {
        Log.e(TAG, "no activity to handle file " + extracting.getFileName());
        Toast.makeText(this, "", Toast.LENGTH_SHORT).show();
        return;
    }

    if (extracting.isEncrypted()
            && (extracting.getPassword() == null || extracting.getPassword().length == 0)) {
        passwordPrompt.show();
        return;
    }

    try {
        zipFile.extractFile(extracting, getExternalCacheDir().getAbsolutePath());
    } catch (ZipException ignored) {
    }

    pendingIntent = intent;

    progressDialog.setProgress(0);
    progressDialog.show();

    handler.post(this);
}

From source file:com.otaupdater.utils.RomInfo.java

@TargetApi(11)
public long fetchFile(Context ctx) {
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setTitle(ctx.getString(R.string.notif_downloading));
    request.setDescription(romName);/*from   w ww .java2  s  .  com*/
    request.setVisibleInDownloadsUi(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    }

    request.setDestinationUri(Uri.fromFile(new File(Config.ROM_DL_PATH_FILE, getDownloadFileName())));

    int netTypes = DownloadManager.Request.NETWORK_WIFI;
    if (!Config.getInstance(ctx).getWifiOnlyDl())
        netTypes |= DownloadManager.Request.NETWORK_MOBILE;
    request.setAllowedNetworkTypes(netTypes);

    DownloadManager manager = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
    return manager.enqueue(request);
}

From source file:com.oe.phonegap.plugins.AutoRecordVideo.java

/**
 * Called when the video view exits.//from  w  w  w .j a  va 2  s  . c  o m
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 * @throws JSONException
 */
public void onActivityResult(int requestCode, int resultCode, final Intent intent) {

    // Result received okay
    if (resultCode == Activity.RESULT_OK) {
        // An audio clip was requested
        if (requestCode == CAPTURE_VIDEO) {

            final AutoRecordVideo that = this;
            Runnable captureVideo = new Runnable() {

                @Override
                public void run() {

                    Uri data = null;

                    if (intent != null) {
                        // Get the uri of the video clip
                        data = intent.getData();
                    }

                    if (data == null) {
                        File movie = new File(getTempDirectoryPath(), "AutoRecordVideo.avi");

                        OELog.d("data null " + movie.toURI());

                        data = Uri.fromFile(movie);
                    }

                    // create a file object from the uri
                    if (data == null) {
                        that.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
                    } else {
                        result = createMediaFile(data);

                        OELog.d("Camera success" + data);

                        that.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                    }
                }
            };

            this.cordova.getThreadPool().execute(captureVideo);
        }
    }

    // If canceled
    else if (resultCode == Activity.RESULT_CANCELED) {
        // If we have partial results send them back to the user
        if (result != null) {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
        }
        // user canceled the action
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Canceled."));
        }
    }

    // If something else
    else {
        // If we have partial results send them back to the user
        if (result != null) {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
        }
        // something bad happened
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Did not complete!"));
        }
    }
}

From source file:com.ushahidi.android.app.BackgroundService.java

private void showNotification(String tickerText) {

    // This is what should be launched if the user selects our notification.
    Intent baseIntent = new Intent(this, IncidentTab.class);
    baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0);

    // choose the ticker text
    newUshahidiReportNotification = new Notification(R.drawable.notification_icon, tickerText,
            System.currentTimeMillis());
    newUshahidiReportNotification.contentIntent = contentIntent;
    newUshahidiReportNotification.flags = Notification.FLAG_AUTO_CANCEL;
    newUshahidiReportNotification.defaults = Notification.DEFAULT_ALL;
    newUshahidiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent);

    if (Preferences.ringtone) {
        // set the ringer
        Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3"));
        newUshahidiReportNotification.sound = ringURI;
    }//from   ww w. java2s.  c o  m

    if (Preferences.vibrate) {
        double vibrateLength = 100 * Math.exp(0.53 * 20);
        long[] vibrate = new long[] { 100, 100, (long) vibrateLength };
        newUshahidiReportNotification.vibrate = vibrate;

        if (Preferences.flashLed) {
            int color = Color.BLUE;
            newUshahidiReportNotification.ledARGB = color;
        }

        newUshahidiReportNotification.ledOffMS = (int) vibrateLength;
        newUshahidiReportNotification.ledOnMS = (int) vibrateLength;
        newUshahidiReportNotification.flags = newUshahidiReportNotification.flags
                | Notification.FLAG_SHOW_LIGHTS;
    }

    mNotificationManager.notify(Preferences.NOTIFICATION_ID, newUshahidiReportNotification);
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    photouri = Uri
            .fromFile(new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), IMAGE_FILE_NAME2));
    System.out.println("abc");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_long_way);

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

    // //w  w w .j a  va2s .  com
    standard_date = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
    primary_date = new SimpleDateFormat("yyyyMMdd", Locale.SIMPLIFIED_CHINESE);

    queue = Volley.newRequestQueue(this);
    exchange = (ImageView) findViewById(R.id.longway_exchange);
    exchange.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            String temp = startplace.getText().toString();

            startplace.setText(endplace.getText().toString());
            endplace.setText(temp);

        }
    });

    bdriver = true;

    datebutton = (Button) findViewById(R.id.longway_dates);
    increase = (Button) findViewById(R.id.longway_increase);
    decrease = (Button) findViewById(R.id.longway_decrease);
    s1 = (TextView) findViewById(R.id.longway_count);
    sure = (Button) findViewById(R.id.longway_sure);
    sure.setEnabled(false);
    startplace = (EditText) findViewById(R.id.longway_start_place);
    endplace = (EditText) findViewById(R.id.longway_end_place);
    noteinfo = (EditText) findViewById(R.id.longway_remarkText);
    commute = findViewById(R.id.drawer_commute);
    shortway = findViewById(R.id.drawer_shortway);
    longway = findViewById(R.id.drawer_longway);
    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.longway_CarBrand);
    model = (EditText) findViewById(R.id.longway_CarModel);
    color = (EditText) findViewById(R.id.longway_color);
    setting = findViewById(R.id.drawer_setting);
    licensenum = (EditText) findViewById(R.id.longway_Num);

    licensenum.addTextChangedListener(numTextWatcher);
    carbrand.addTextChangedListener(detTextWatcher);
    color.addTextChangedListener(coTextWatcher);
    model.addTextChangedListener(moTextWatcher);
    startplace.addTextChangedListener(spTextWatcher);
    endplace.addTextChangedListener(epTextWatcher);

    final TextView content = (TextView) findViewById(R.id.longway_content);
    longway_group = (RadioGroup) findViewById(R.id.longway_radiobutton);
    passangerRadioButton = (RadioButton) findViewById(R.id.longway_radioButton02);
    driverRadioButton = (RadioButton) findViewById(R.id.longway_radioButton01);
    personalcenter = findViewById(R.id.drawer_personalcenter);
    taxi = findViewById(R.id.drawer_taxi);

    // 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("stpmapname"));
        bstart = true;
        endplace.setText(bundle.getString("epmapname"));
        bend = true;
        datebutton.setText(bundle.getString("re_longway_startdate"));
        bdate = true;
    }
    // judge the value of "pre_page"

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

    // database
    db = new DatabaseHelper(getApplicationContext(), UserPhoneNumber, null, 1);
    db1 = db.getWritableDatabase();
    about = findViewById(R.id.drawer_respond);
    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(LongWayActivity.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(LongWayActivity.this, SettingActivity.class);
            startActivity(setting);
        }
    });

    // database end

    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(LongWayActivity.this, PersonalCenterActivity.class);
            personalcenter.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(personalcenter);
        }
    });

    // RadioGroup

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

            // """"textView
            if (checkedId == passangerRadioButton.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();
        }

        private void selectcarinfo(final String phonenum) {
            // TODO Auto-generated method stub
            String carinfo_selectrequest_baseurl = getString(R.string.uri_base)
                    + getString(R.string.uri_CarInfo) + getString(R.string.uri_selectcarinfo_action);

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

                        @Override
                        public void onResponse(String response) {
                            // TODO Auto-generated method stub
                            Log.d("carinfo_select", response);
                            String jas_id = null;
                            JSONObject json1 = null;
                            try {
                                json1 = new JSONObject(response);
                                JSONObject json = json1.getJSONObject("result");
                                jas_id = json.getString("id");

                                if (jas_id.compareTo("") != 0) { // 

                                    carinfochoosing_type = 2;

                                    carbrand.setText(json.getString("carBrand"));
                                    model.setText(json.getString("carModel"));
                                    licensenum.setText(json.getString("carNum"));
                                    color.setText(json.getString("carColor"));

                                }
                                {
                                    carinfochoosing_type = 1;
                                }

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

                    }, new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub
                            Log.e("carinfo_selectresult_result", error.getMessage(), error);
                        }
                    }) {
                protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("phonenum", phonenum);
                    return params;
                }
            };

            queue.add(stringRequest);
        }
    });

    sure.setOnClickListener(new OnClickListener() {

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

            if (longway_group.getCheckedRadioButtonId() == passangerRadioButton.getId())
                userrole = "p";
            else
                userrole = "d";

            // start!
            Context phonenumber = LongWayActivity.this;
            SharedPreferences filename = phonenumber
                    .getSharedPreferences(getString(R.string.PreferenceDefaultName), Context.MODE_PRIVATE);
            username = filename.getString("refreshfilename", "0");
            longway_request(username, userrole, datebutton.getText().toString(),
                    startplace.getText().toString(), endplace.getText().toString(),
                    noteinfo.getText().toString());
            // end!
        }

        private void longway_request(final String longway_phonenum, final String longway_userrole,
                final String longway_startdate, final String longway_startplace,
                final String longway_destination, final String longway_noteinfo) {
            // TODO Auto-generated method stub

            String longway_addrequest_baseurl = getString(R.string.uri_base)
                    + getString(R.string.uri_LongwayPublish) + getString(R.string.uri_addpublish_action);
            // + "phonenum=" + longway_phonenum
            // + "&userrole=" + longway_userrole
            // + "&startdate=" + standard_longway_startdate
            // + "&startplace=" + longway_startplace
            // + "&destination=" + longway_destination
            // + "&noteinfo=" + longway_noteinfo;

            // Log.d("longway_baseurl",longway_addrequest_baseurl);

            StringRequest stringRequest = new StringRequest(Request.Method.POST, longway_addrequest_baseurl,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(String response) {
                            Log.d("longway_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(longway_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 1);
                                    // end!
                                } else {
                                    // update
                                    // start!
                                    carinfo(longway_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 2);
                                    // end!
                                }

                                Intent sure = new Intent(LongWayActivity.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(LongWayActivity.this, OrderResponseActivity.class);
                                sure.putExtra(getString(R.string.request_response), "false");
                                sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(sure);
                            }
                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Log.e("longway_result", error.getMessage(), error);
                            // Toast errorinfo = Toast.makeText(null,
                            // "", Toast.LENGTH_LONG);
                            // errorinfo.show();
                            Intent sure = new Intent(LongWayActivity.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(longway_startdate);
                        standard_longway_startdate = standard_date.format(test_date);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    // end!

                    Map<String, String> params = new HashMap<String, String>();
                    params.put(getString(R.string.uri_phonenum), longway_phonenum);
                    params.put(getString(R.string.uri_userrole), longway_userrole);
                    params.put(getString(R.string.uri_startplace), longway_startplace);
                    params.put(getString(R.string.uri_destination), longway_destination);
                    params.put(getString(R.string.uri_startdate), standard_longway_startdate);
                    params.put(getString(R.string.uri_noteinfo), longway_noteinfo);

                    return params;
                }
            };
            queue.add(stringRequest);
        }
    });

    // start!
    shortway.setOnClickListener(new OnClickListener() {

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

    longway.setOnClickListener(new OnClickListener() {

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

    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(LongWayActivity.this, CommuteActivity.class);
            startActivity(commute);
        }
    });

    // end!

    increase.setOnClickListener(new OnClickListener() {

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

    decrease.setOnClickListener(new OnClickListener() {

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

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

From source file:com.otaupdater.utils.KernelInfo.java

@TargetApi(11)
public long fetchFile(Context ctx) {
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setTitle(ctx.getString(R.string.notif_downloading));
    request.setDescription(kernelName);/*from   w w  w  . j  a va 2 s  . co m*/
    request.setVisibleInDownloadsUi(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    }

    request.setDestinationUri(Uri.fromFile(new File(Config.KERNEL_DL_PATH_FILE, getDownloadFileName())));

    int netTypes = DownloadManager.Request.NETWORK_WIFI;
    if (!Config.getInstance(ctx).getWifiOnlyDl())
        netTypes |= DownloadManager.Request.NETWORK_MOBILE;
    request.setAllowedNetworkTypes(netTypes);

    DownloadManager manager = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
    return manager.enqueue(request);
}