В моем приложении рецепта намерение не будет распознавать какие-либо из моих действий, действие загружается в приложение, но намерение не может распознать его, также, когда я запускаю приложение, изображение не будет отображаться в представлении переработчика, я подозреваю, что намерение не передает данные, так как не может распознать какие-либо из моих действий, изображение было загружено в мой FireBase, но оно не будет отображаться в окне рециркулятора при запуске приложения.
Ошибка :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.recipeapp, PID: 12376
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=class com.example.recipeapp.DetailActivity (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2051)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1709)
at android.app.Activity.startActivityForResult(Activity.java:5192)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
at android.app.Activity.startActivityForResult(Activity.java:5150)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
at android.app.Activity.startActivity(Activity.java:5521)
at android.app.Activity.startActivity(Activity.java:5489)
at com.example.recipeapp.MyAdapter$1.onClick(MyAdapter.java:59)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Activity_Detail. xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".DetailActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/ivImage2"
android:src="@drawable/feijoada"
android:scaleType="centerCrop"
android:contentDescription="@string/todo" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="20dp"
android:text="@string/description_feijoada"
android:textSize="19sp"
android:id="@+id/txtDescription"
/>
</LinearLayout>
DetailActivity:
package com.example.recipeapp;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.bumptech.glide.Glide;
public class DetailActivity extends AppCompatActivity {
TextView foodDescription;
ImageView foodImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
foodDescription = (TextView) findViewById(R.id.txtDescription);
foodImage = (ImageView) findViewById(R.id.ivImage2);
Bundle mBundle = getIntent().getExtras();
if (mBundle != null) {
foodDescription.setText(mBundle.getString("Description"));
foodImage.setImageResource(mBundle.getInt("Image"));
Glide.with(this)
.load(mBundle.getString("Image"))
.into(foodImage);
}
}
}
MyAdapter:
package com.example.recipeapp;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.List;
public class MyAdapter extends RecyclerView.Adapter<FoodViewHolder> {
private Context mContext;
private List<FoodData> myFoodList;
public MyAdapter(Context mContext, List<FoodData> myFoodList) {
this.mContext = mContext;
this.myFoodList = myFoodList;
}
@NonNull
@Override
public FoodViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View mView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recycler_row_item, viewGroup, false);
return new FoodViewHolder(mView);
}
@Override
public void onBindViewHolder(@NonNull final FoodViewHolder foodViewHolder, int i) {
Glide.with(mContext)
.load(myFoodList.get(i).getItemName())
.into(foodViewHolder.imageView);
//foodViewHolder.imageView.setImageResource(myFoodList.get(i).getItemImage());
foodViewHolder.mTitle.setText(myFoodList.get(i).getItemName());
foodViewHolder.mDescription.setText(myFoodList.get(i).getItemDescription());
foodViewHolder.mPrice.setText(myFoodList.get(i).getItemPrice());
foodViewHolder.mCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(String.valueOf(DetailActivity.class));
intent.putExtra("Image", myFoodList.get(foodViewHolder.getAdapterPosition()).getItemImage());
intent.putExtra("Description", myFoodList.get(foodViewHolder.getAdapterPosition()).getItemDescription());
mContext.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return myFoodList.size();
}
public void filteredList(ArrayList<FoodData> filterList) {
myFoodList = filterList;
notifyDataSetChanged();
}
}
class FoodViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
TextView mTitle, mDescription, mPrice;
CardView mCardView;
public FoodViewHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.ivImage);
mTitle = itemView.findViewById(R.id.tvTitle);
mDescription = itemView.findViewById(R.id.tvDescription);
mPrice = itemView.findViewById(R.id.tvPrice);
mCardView = itemView.findViewById(R.id.myCardView);
}
}
MainActivity:
package com.example.recipeapp;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
RecyclerView mRecyclerView;
List<FoodData> myFoodList;
FoodData mFoodData;
ProgressDialog progressDialog;
MyAdapter myAdapter;
EditText txt_search;
private DatabaseReference databaseReference;
private ValueEventListener eventListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = findViewById(R.id.RecyclerView);
GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity.this, 1);
mRecyclerView.setLayoutManager(gridLayoutManager);
txt_search = (EditText) findViewById(R.id.txt_searchtext);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Carregando Itens...");
myFoodList = new ArrayList<>();
final MyAdapter myAdapter = new MyAdapter(MainActivity.this, myFoodList);
mRecyclerView.setAdapter(myAdapter);
databaseReference = FirebaseDatabase.getInstance().getReference("Recipe");
progressDialog.show();
eventListener = databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
myFoodList.clear();
for (DataSnapshot itemSnapshot : dataSnapshot.getChildren()) {
FoodData foodData = itemSnapshot.getValue(FoodData.class);
myFoodList.add(foodData);
}
myAdapter.notifyDataSetChanged();
progressDialog.dismiss();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
progressDialog.dismiss();
}
});
txt_search.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
filter(s.toString());
}
});
}
private void filter(String text) {
ArrayList<FoodData> filterList = new ArrayList<>();
for (FoodData item : myFoodList) {
if (item.getItemName().toLowerCase().contains(text.toLowerCase())) ;
{
filterList.add(item);
}
}
myAdapter.filteredList(filterList);
}
public void btn_uploadActivity(View view) {
startActivity(new Intent(this, Upload_Recipe.class));
}
}
Upload_Recipe:
package com.example.recipeapp;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
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.text.DateFormat;
import java.util.Calendar;
public class Upload_Recipe extends AppCompatActivity {
ImageView recipeImage;
Uri uri;
EditText txt_name, txt_description, txt_price;
String imageUrl;
Object progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload__recipe);
recipeImage = (ImageView) findViewById(R.id.iv_foodImage);
txt_name = (EditText) findViewById(R.id.txt_recipe_name);
txt_description = (EditText) findViewById(R.id.text_description);
txt_price = (EditText) findViewById(R.id.text_price);
}
public void btnSelectImage(View view) {
Intent photoPicker = new Intent(Intent.ACTION_PICK);
photoPicker.setType("image/*");
startActivityForResult(photoPicker, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
uri = data.getData();
recipeImage.setImageURI(uri);
} else Toast.makeText(this, "Você não selecionou uma imagem", Toast.LENGTH_SHORT).show();
}
public void uploadImage() {
StorageReference storageReference = FirebaseStorage.getInstance()
.getReference()
.child("RecipeImage")
.child(uri.getLastPathSegment());
storageReference.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Task<Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl();
while (!uriTask.isComplete()) ;
Uri urlImage = uriTask.getResult();
if (urlImage != null) {
imageUrl = urlImage.toString();
}
uploadRecipe();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
public void btnUploadRecipe(View view) {
uploadImage();
}
public void uploadRecipe() {
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Enviando Receita...");
progressDialog.show();
progressDialog.dismiss();
finish();
FoodData foodData = new FoodData(txt_name.getText().toString()
, txt_description.getText().toString(), txt_price.getText().toString()
, imageUrl);
String myCurrentDateTime = DateFormat.getDateTimeInstance()
.format(Calendar.getInstance().getTime());
FirebaseDatabase.getInstance()
.getReference("Recipe")
.child(myCurrentDateTime).setValue(foodData).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(Upload_Recipe.this, "Receita Enviada", Toast.LENGTH_SHORT).show();
finish();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Upload_Recipe.this, "Falha ao Enviar", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
});
}
private void ProgressDialog(Object progressDialog) {
this.progressDialog = progressDialog;
ProgressDialog(progressDialog);
}
}