1

Am developing an app that enables one to send images,audio and video through the internet. the person receiving this media files must have installed my app in his device.

What i can do right now is compress the image to be sent. i don't know where to start since most of the online tutorials are using intents to do this but i don't want to trigger another app to carry out the sending. my app should be able to do all this by itself.

this is how am compressing the image

public class ImageCompression extends AsyncTask<String, Void, String> {

private Context context;
private static final float maxHeight = 1280.0f;
private static final float maxWidth = 1280.0f;


public ImageCompression(Context context){
    this.context=context;
}

@Override
protected String doInBackground(String... strings) {
    if(strings.length == 0 || strings[0] == null)
        return null;

    return compressImage(strings[0]);
}

protected void onPostExecute(String imagePath){
    // imagePath is path of new compressed image.
}
Edijae Crusar
  • 3,473
  • 3
  • 37
  • 74
  • you need backend server where webservice may be accepts image url or whatever media and target audience... You may use websocket then to push data received on server to target device using server-client push mechanism – virendrao Dec 23 '15 at 09:51
  • @virendrao i have a backend server which am using to send messages using GCM. do you have an example that i can use to send media? – Edijae Crusar Dec 23 '15 at 09:53
  • you want to show image or media as notification or something like whatsapp where you see images on opening chat – virendrao Dec 23 '15 at 09:57
  • @virendrao if possible, i show a notification just like chat messages.(also whatapp have notification for images) and when one click the notif, it will take him to relevant Activity. i have no problem implementing notifications. the problem is sending and receiving media – Edijae Crusar Dec 23 '15 at 09:59
  • Checkout - http://stackoverflow.com/questions/4126625/how-to-send-a-file-in-android-from-mobile-to-server-using-http – Harish Ved Dec 28 '15 at 06:07
  • @HarishVed that answer is great(although 5 years old). which is the best way to alert the recipient(person am sending my image) about the image? am thinking of sending the url as a GCM message to the recipient and on my **GCMListenerService class** i check if the message received contain a url, if it does, i download the image using picasso(an android image library) and show it to the receiver. i don't know whether it's the best way – Edijae Crusar Dec 28 '15 at 07:09

1 Answers1

0

It was a long time ago. I was new in android development. The problem is easily solved using firebase. Just uploading a file in firebase and sending a FCM notification which contains image uri.

Uri file = Uri.fromFile(new File("path/to/images/rivers.jpg"));
StorageReference riversRef = storageRef.child("images/"+file.getLastPathSegment());
UploadTask uploadTask = riversRef.putFile(file);

Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
    @Override
    public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
        if (!task.isSuccessful()) {
            throw task.getException();
        }

        // Continue with the task to get the download URL
        return ref.getDownloadUrl();
    }
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
    @Override
    public void onComplete(@NonNull Task<Uri> task) {
        if (task.isSuccessful()) {
            Uri downloadUri = task.getResult();
            int id =1;
FirebaseMessaging fm = FirebaseMessaging.getInstance();
fm.send(new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com")
  .setMessageId("1")
  .addData("my_message", downloadUri.toString())
  .addData("my_action","SAY_HELLO")
  .build());

        } else {
            // Handle failures
            // ...
        }
    }
});
Edijae Crusar
  • 3,473
  • 3
  • 37
  • 74