2016-09-22 32 views
-1

我是新的android java編程,我需要創建一個活動,這將有助於用戶發送像圖像,視頻,音頻媒體..到另一個用戶或用戶組,這樣發送的動作就像Whatsapp一樣超級快,但我不知道我可以跟隨哪些方式,以及我需要知道什麼。我使用的是android studio 2.如果有一些教程或源代碼請與我分享鏈接。感謝您對我的問題最高的評價。什麼是有效的方式來發送媒體像圖像,..使用我的android應用程序

公共類MainActivity擴展活動{

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main);  
    EditText MyText=(EditText) findViewById(R.id.text); 
    Button send=(Button) findViewById(R.id.button1); 
    ImageView attach =(ImageView) findViewById(R.id.attach); 

    button.setOnClickListener(new OnClickListener() { 

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

String txt =MyText.getText().toString(); 
     ... 
AlertDialog alertDialog = new  AlertDialog.Builder(MainActivity.this).create(); 
    ... 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.activity_main, menu); 
    return true; 
} 

}

+0

Defuke效率,你的情況 – Antoniossss

+0

我不明白你說的@Antoniosss,你想什麼意思 –

+0

定義*我的意思;) – Antoniossss

回答

0

試試火力地堡https://firebase.google.com/

使用火力地堡的存儲空間,並且火力地堡實時數據庫

https://firebase.google.com/docs/storage/android/upload-files

小S上面鏈接的代碼很充足 從本地文件上傳

您可以使用putFile()方法上傳設備上的本地文件,例如照相機中的照片和視頻。 putFile()接受一個File並返回一個UploadTask,您可以使用它來管理和監視上傳的狀態。

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

// Register observers to listen for when the download is done or if it fails 
uploadTask.addOnFailureListener(new OnFailureListener() { 
    @Override 
    public void onFailure(@NonNull Exception exception) { 
     // Handle unsuccessful uploads 
    } 
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { 
    @Override 
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 
     // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL. 
     Uri downloadUrl = taskSnapshot.getDownloadUrl(); 
    } 
}); 
+0

一些教程通過谷歌https://www.udacity.com/course/firebase-essentials-for-android--ud009 –

相關問題