0
プログラミングの新機能。私はギャラリーから画像を選択し、後で目的のためにそれらをfirebaseにアップロードしたいと思います。ギャラリーから画像を選択するオプションは機能していますが、データベースにアップロードされていません。Firebaseアップロード
package example.com.myapplication;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.Toast;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import java.io.File;
public class Profile extends AppCompatActivity {
private EditText t1,t2,t3,t4,t5;
private Button b1;
private static final int PICK_IMAGE_REQUEST = 234;
private Spinner s1,s2,s3,s4,s5;
ArrayAdapter<CharSequence> adapter;
Context cntx;
//Buttons
private ImageButton pb1;
// Context cntx;
private Uri filePath;
private StorageReference mStorageRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
pb1 = (ImageButton)findViewById(R.id.pickimage);
pb1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(Intent.createChooser(intent, "Select Image"), PICK_IMAGE_REQUEST);
}
});
b1 = (Button)findViewById(R.id.ProfSubmit);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
t1 = (EditText)findViewById(R.id.FirstNameField);
t2 = (EditText)findViewById(R.id.LastNameField);
t3 = (EditText)findViewById(R.id.AgeField);
t4 = (EditText)findViewById(R.id.WL1);
t5 = (EditText)findViewById(R.id.WL2);
s1 = (Spinner)findViewById(R.id.spinner);
s2 = (Spinner)findViewById(R.id.spinner2);
s3 = (Spinner)findViewById(R.id.spinner3);
s4 = (Spinner)findViewById(R.id.spinner5);
s5 = (Spinner) findViewById(R.id.spinner5);
adapter = ArrayAdapter.createFromResource(Profile.this,R.array.craftmenu,android.R.layout.simple_spinner_item);
s1.setAdapter(adapter);
s2.setAdapter(adapter);
s3.setAdapter(adapter);
s4.setAdapter(adapter);
s5.setAdapter(adapter);
FirebaseDatabase User1 = FirebaseDatabase.getInstance();
DatabaseReference Name = User1.getReference("Fname");
DatabaseReference LName = User1.getReference("LName");
DatabaseReference age = User1.getReference("age");
DatabaseReference Work1 = User1.getReference("WorkLink1");
DatabaseReference Work2 = User1.getReference("WorkLink2");
final DatabaseReference Craft1 = User1.getReference("Craft1");
final DatabaseReference Craft2 = User1.getReference("Craft2");
final DatabaseReference Craft3 = User1.getReference("Craft3");
final DatabaseReference Craft4 = User1.getReference("Craft4");
final DatabaseReference Craft5 = User1.getReference("Craft5");
mStorageRef = FirebaseStorage.getInstance().getReference();
Uri filePath = Uri.fromFile(new File("images/*"));
StorageReference profimg = mStorageRef.("refimage");
profimg.putFile(filePath).addOnCompleteListener(new OnSuccessListener<UploadTask.TaskSnapshot>(){
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri filepath = taskSnapshot.getDownloadUrl();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(cntx, "Upload Failed", Toast.LENGTH_SHORT).show();
}
});
Name.setValue(t1.getText().toString());
LName.setValue(t2.getText().toString());
age.setValue(t3.getText().toString());
Work1.setValue(t4.getText().toString());
Work2.setValue(t5.getText().toString());
/* Craft1.setValue(s1.getOnItemSelectedListener().toString());
Craft2.setValue(s2.getOnItemSelectedListener().toString());
Craft3.setValue(s3.getOnItemSelectedListener().toString());
Craft4.setValue(s4.getOnItemSelectedListener().toString());
Craft5.setValue(s5.getOnItemSelectedListener().toString()); */
s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Craft1.setValue(s1.getOnItemSelectedListener().toString());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Craft1.setValue(null);
}
});
s2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Craft2.setValue(s2.getOnItemSelectedListener().toString());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Craft2.setValue(null);
}
});
s3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Craft3.setValue(s3.getOnItemSelectedListener().toString());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Craft3.setValue(null);
}
});
s4.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Craft4.setValue(s4.getOnItemSelectedListener().toString());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Craft4.setValue(null);
}
});
s5.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Craft5.setValue(s5.getOnItemSelectedListener().toString());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Craft5.setValue(null);
}
});
startActivity(new Intent(Profile.this, HomeScreen.class));
}
});
// ...
}
}
uはuが応答したURLリンクを取得するよりも、Firebase上のファイルをアップロードするたびに...画像 –
いただきましたエラーを表示したり、ダウンロードするには、そのリンクを使用しますか?上にアップロードコードを作業しているようです。 –
@AawazGyawaliエラーはこれです 06-15 14:20:34.403 1641-1641/example.com.myapplication E/UncaughtException:java.lang.IllegalArgumentException:uriはnullにはできません –