Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8454689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:05:33+00:00 2026-06-10T12:05:33+00:00

Hi Iam doing an android aplication in which iam uploading videos to PHP server.

  • 0

Hi Iam doing an android aplication in which iam uploading videos to PHP server.
Iam using HTTPURLConnection to do the upload. Iam strucked in showing progress bar in notification area and updating it.
Iam searching almost a week to do this.But can’t get a hint.Please help me if anybody knows:

My code:

HttpURLConnection conn = null;
        DataOutputStream dos = null;
        DataInputStream inStream = null;
        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary = "*****";
        int bytesRead;
        byte[] buffer;
        String urlString = "http://xxxxx/My_path.php";
        try {
            long total = 0;
            int count = 0;
            // ------------------ CLIENT REQUEST
            UUID uniqueKey = UUID.randomUUID();
            fname = uniqueKey.toString();
            Log.e("UNIQUE NAME", fname);
            FileInputStream fileInputStream = new FileInputStream(
                    new File(selectedPath));
            URL url = new URL(urlString);                       
            conn = (HttpURLConnection) url.openConnection();
            int length=selectedPath.length();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Content-Type",
                    "multipart/form-data;boundary=" + boundary);
            dos = new DataOutputStream(conn.getOutputStream());
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\""
                    + fname + "" + lineEnd);
            dos.writeBytes(lineEnd);
            buffer = new byte[8192];
            bytesRead = 0;
            while ((bytesRead = fileInputStream.read(buffer)) > 0) {                                 
                dos.write(buffer, 0, bytesRead);                    
            }           
            dos.writeBytes(lineEnd);
            dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);           
            Log.e("Debug", "File is written");
            fileInputStream.close();
            dos.flush();
            dos.close();

        } catch (MalformedURLException ex) {
            Log.e("Debug", "error: " + ex.getMessage(), ex);
        } catch (IOException ioe) {
            Log.e("Debug", "error: " + ioe.getMessage(), ioe);
        }       
        // ------------------ read the SERVER RESPONSE
        try {
            inStream = new DataInputStream(conn.getInputStream());
            String str;
            while ((str = inStream.readLine()) != null) {
                Log.e("Debug", "Server Response " + str);
            }
            inStream.close();

        } catch (IOException ioex) {
            Log.e("Debug", "error: " + ioex.getMessage(), ioex);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:05:34+00:00Added an answer on June 10, 2026 at 12:05 pm

    After a long search i finished the task of showing progress bar in notification area.All we need is asynctask.May be the code iam showing here will not work perfectly,It works fine when iam testing.Please check and upvote for this answer if it works good.

    My code:

    public class loadVideo extends AsyncTask<Void, Integer, Void> {
    
            int progress = 0;
            Notification notification;
            NotificationManager notificationManager;
            int id = 10;
    
            protected void onPreExecute() {
    
            }
    
            @Override
            protected Void doInBackground(Void... params) {
                HttpURLConnection conn = null;
                DataOutputStream dos = null;
                DataInputStream inStream = null;
                String lineEnd = "\r\n";
                String twoHyphens = "--";
                String boundary = "*****";
                int bytesRead;
                int sentData = 0;               
                byte[] buffer;
                String urlString = "http://xxxxx/xxx/xxxxxx.php";
                try {
                    UUID uniqueKey = UUID.randomUUID();
                    fname = uniqueKey.toString();
                    Log.e("UNIQUE NAME", fname);
                    FileInputStream fileInputStream = new FileInputStream(new File(
                            selectedPath));
                    int length = fileInputStream.available();
                    URL url = new URL(urlString);
                    conn = (HttpURLConnection) url.openConnection();
                    conn.setDoInput(true);
                    conn.setDoOutput(true);
                    conn.setUseCaches(false);
                    conn.setRequestMethod("POST");
                    conn.setRequestProperty("Connection", "Keep-Alive");
                    conn.setRequestProperty("Content-Type",
                            "multipart/form-data;boundary=" + boundary);
                    dos = new DataOutputStream(conn.getOutputStream());
                    dos.writeBytes(twoHyphens + boundary + lineEnd);
                    dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\""
                            + fname + "" + lineEnd);
                    dos.writeBytes(lineEnd);
                    buffer = new byte[8192];
                    bytesRead = 0;
                    while ((bytesRead = fileInputStream.read(buffer)) > 0) {
                        dos.write(buffer, 0, bytesRead);
                        sentData += bytesRead;
                        int progress = (int) ((sentData / (float) length) * 100);
                        publishProgress(progress);
                    }
                    dos.writeBytes(lineEnd);
                    dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
                    Log.e("Debug", "File is written");
                    fileInputStream.close();
                    dos.flush();
                    dos.close();
    
                } catch (MalformedURLException ex) {
                    Log.e("Debug", "error: " + ex.getMessage(), ex);
                } catch (IOException ioe) {
                    Log.e("Debug", "error: " + ioe.getMessage(), ioe);
                }
                // ------------------ read the SERVER RESPONSE
                try {
                    inStream = new DataInputStream(conn.getInputStream());
                    String str;
                    while ((str = inStream.readLine()) != null) {
                        Log.e("Debug", "Server Response " + str);
                    }
                    inStream.close();
    
                } catch (IOException ioex) {
                    Log.e("Debug", "error: " + ioex.getMessage(), ioex);
                }
    
                return null;
            }
    
            @Override
            protected void onProgressUpdate(Integer... progress) {
    
                Intent intent = new Intent();
                final PendingIntent pendingIntent = PendingIntent.getActivity(
                        getApplicationContext(), 0, intent, 0);
                notification = new Notification(R.drawable.video_upload,
                        "Uploading file", System.currentTimeMillis());
                notification.flags = notification.flags
                        | Notification.FLAG_ONGOING_EVENT;
                notification.contentView = new RemoteViews(getApplicationContext()
                        .getPackageName(), R.layout.upload_progress_bar);
                notification.contentIntent = pendingIntent;
                notification.contentView.setImageViewResource(R.id.status_icon,
                        R.drawable.video_upload);
                notification.contentView.setTextViewText(R.id.status_text,
                        "Uploading...");
                notification.contentView.setProgressBar(R.id.progressBar1, 100,
                        progress[0], false);
                getApplicationContext();
                notificationManager = (NotificationManager) getApplicationContext()
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.notify(id, notification);
            }
    
            protected void onPostExecute(Void result) {
                Notification notification = new Notification();
                Intent intent1 = new Intent(MultiThreadActivity.this,
                        MultiThreadActivity.class);
                final PendingIntent pendingIntent = PendingIntent.getActivity(
                        getApplicationContext(), 0, intent1, 0);
                int icon = R.drawable.check_16; // icon from resources
                CharSequence tickerText = "Video Uploaded Successfully"; // ticker-text
                CharSequence contentTitle = getResources().getString(
                        R.string.app_name); // expanded message
                // title
                CharSequence contentText = "Video Uploaded Successfully"; // expanded
                                                                            // message
                long when = System.currentTimeMillis(); // notification time
                Context context = getApplicationContext(); // application
                                                            // Context
                notification = new Notification(icon, tickerText, when);
                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                notification.setLatestEventInfo(context, contentTitle, contentText,
                        pendingIntent);
                String notificationService = Context.NOTIFICATION_SERVICE;
                notificationManager = (NotificationManager) context
                        .getSystemService(notificationService);
                notificationManager.notify(id, notification);
            }
        }
    

    Thanks and Regards
    Sundar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now i am doing an android application.In that application I am using asynchtask class
I am doing push notification for android using C2DM. it works well. but while
I am doing some development about google reader on android platform. Using google reader
I am doing NDK profiling for my project using android-ndk-profiler-3.1. I have made changes
I am doing a small android application, which will show established WiFi connection is
I'm doing an android application. It has a server back end too. I need
I want to read data which is receiding in the domino server database using
I have written an application in C which I am porting to Android using
I am developing an android application in which I have to upload image from
I am currently doing an android application that contains customize alert dialog. It contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.