我正在创建照片共享应用程序...但是我的问题是,当用户单击上载按钮时,我希望将用户定向到新闻源活动,而不是停留在上载活动中...并且它应该开始上载新闻源活动。.像 Instagram和Facebook 一样...是因为我不想让用户在上载活动中等待...我希望他们在同时享受新闻提要上传正在后台进行...。我也想显示视频的进度...我该怎么做...我应该在后台进行操作,我不知道请告诉我我是新手对此
这是上传的地方
mUpload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
parse = Uri.fromFile(new File(path));
String description = mdescription.getText().toString();
Toast.makeText(mContext, "uploading the video", Toast.LENGTH_SHORT).show();
String category = selected;
String links = mlinks.getText().toString();
uploadNewVideo(getString(R.string.new_photo), description, VideoCount, category, parse, links);
Intent intent = new Intent(mContext, HomeActivity.class);
mContext.startActivity(intent);
((Activity) mContext).finish();
}
});
}
public void uploadNewVideo(String photoType, final String description, int count , final String category, final Uri imgUrl, final String links){
Log.d(TAG, "uploadNewPhoto: attemting to upload new photo");
FilePaths filePaths = new FilePaths();
if (parse == null) {
Toast.makeText(mContext, "Please select image ", Toast.LENGTH_SHORT).show();
}else {
StorageMetadata metadata = new StorageMetadata.Builder()
.setContentType("video/mp4")
.build();
if (photoType.equals(mContext.getString(R.string.new_photo))) {
Log.d(TAG, "uploadNewPhoto: uploading photo");
String user_id = FirebaseAuth.getInstance().getCurrentUser().getUid();
StorageReference storageReference = mStorageReference.child(filePaths.FIREBASE_VIDEO_STORAGE + "/" + user_id + "/videos" + (count + 1));
UploadTask uploadTask = null;
mcancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mStoragetask.cancel();
}
});
// mStoragetask = uploadTask = storageReference.putBytes(bytes);
mStoragetask = uploadTask = storageReference.putFile(parse,metadata);
mStoragetask = uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri firebaseUrl = taskSnapshot.getDownloadUrl();
// firebaseUrl.toString();
Toast.makeText(mContext, "photo upload sucess", Toast.LENGTH_SHORT).show();
mFirebaseMethods.AddVideoToDatabase(description, firebaseUrl.toString(),category,links);
Intent intent = new Intent(mContext, HomeActivity.class);
mContext.startActivity(intent);
((Activity) mContext).finish();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "onFailure: photo upload fail ");
Toast.makeText(mContext, "Photo upload failed " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
progressBar.setProgress((int) progress);
}
});
}
}
}