Android Open Source - playground-android-video Upload Service






From Project

Back to project page playground-android-video.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project playground-android-video listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package v.app.Services;
// w  w w.  ja  v a2  s.com
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;

import java.io.File;

import retrofit.mime.TypedFile;
import retrofit.mime.TypedString;
import v.app.Helpers.HTTP;
import v.app.Interfaces.RemoteInterface;
import v.app.MainActivity;

/**
 * Created by vasanth on 25/03/14.
 */
public class UploadService extends IntentService {

    public UploadService() {
        super("Upload");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Uri uri = intent.getData();
        upload(uri);
    }

    private void upload(Uri uri) {
        HTTP http = new HTTP();
        RemoteInterface remote = http.adapter.create(RemoteInterface.class);

        try {
            File file = getFile(uri);
            Log.v("V-app", file.toString());
            Log.v("V-app", String.valueOf(file.length()));
            String mime = "video/mp4";
            String message = remote.upload(
                    new TypedFile(mime, file),
                    new TypedString(mime)
            );
            showNotification(message);
        } catch(Exception e) {
            e.printStackTrace();
        }

    }

    private File getFile(Uri uri) {
        Cursor cursor =
                getContentResolver().query(uri, null, null, null, null);
        cursor.moveToFirst();
        int fileNameIndex = cursor.getColumnIndex(MediaStore.Video.Media.DATA);

        return new File(cursor.getString(fileNameIndex));
    }

    private void showNotification(String message) {
        NotificationManager nm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification=new Notification(android.R.drawable.stat_notify_more,
                message, System.currentTimeMillis());

        CharSequence title="Video App";

        Intent intent=new Intent(this,MainActivity.class);
        PendingIntent pending=PendingIntent.getActivity(this, 0, intent, 0);

        notification.setLatestEventInfo(this, title, message, pending);
        nm.notify(0, notification);
    }

}




Java Source Code List

v.app.Config.java
v.app.MainActivity.java
v.app.Fragments.NoVideoFragment.java
v.app.Fragments.RecorderFragment.java
v.app.Fragments.VideoFragment.java
v.app.Helpers.HTTP.java
v.app.Interfaces.RemoteInterface.java
v.app.Services.UploadService.java