Я хочу отправить текст и изображение через намерение, но ничего не отправляется, код, который я использовал, упоминается здесь; я пытаюсь отправить детали ввода и нажал на изображение через намерение; Скажите, пожалуйста, в чем дело, и есть ли другой способ отправки кликнувшего изображения?
MAINACTIVITY. JAVA:
public class MainActivity extends AppCompatActivity {
CheckBox cb1, cb2;
Button export, button;
//ImageView img;
Uri file;
EditText name, age, address, phone;
String genderr, namee, agee, addr, num;
private static final int CAMERA_REQUEST = 1888;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
export = findViewById(R.id.button);
cb1 = findViewById(R.id.male);
cb2 = findViewById(R.id.female);
imageView = (ImageView) this.findViewById(R.id.imageView1);
Button photoButton = (Button) this.findViewById(R.id.button1);
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
export.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
name = findViewById(R.id.et_name);
name.setTypeface(null, Typeface.BOLD);
age = findViewById(R.id.et_age);
age.setTypeface(null, Typeface.BOLD);
address = findViewById(R.id.address);
phone = findViewById(R.id.phone);
if (cb1.isChecked()) {
cb2.setChecked(false);
genderr = cb1.getText().toString();
} else if (cb2.isChecked()) {
cb1.setChecked(false);
genderr = cb2.getText().toString();
}
final String content = "NAME: " + name.getText().toString() + "\n AGE: " + age.getText().toString() + "\n Gender: " + genderr + "\n ADDRESS: " + address.getText().toString() + "\n Phone: " + phone.getText().toString()+"\n IMAGE:";
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
sendIntent.putExtra(Intent.EXTRA_STREAM, (Parcelable) imageView);
// Intent sendIntent = new Intent(Intent.ACTION_PICK);
sendIntent.setType("image/*");
// startActivityForResult(in, imageView);
// sendIntent.putExtra(Intent.EXTRA_TEXT, extraParams);
startActivity(Intent.createChooser(sendIntent, "Send Using.."));
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
ACTIVITY_MAIN:
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#72C8E8"
android:padding="4sp"
android:paddingLeft="4sp"
android:paddingTop="4sp"
android:paddingRight="4sp"
android:paddingBottom="4sp"
android:text="@string/name"
android:textColor="@color/colorPrimaryDark"
android:textSize="30sp"
android:textStyle="bold" />
<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<TextView
android:id="@+id/textView2"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#72C8E8"
android:text="@string/age"
android:padding="4sp"
android:paddingLeft="4sp"
android:paddingTop="4sp"
android:paddingRight="4sp"
android:paddingBottom="4sp"
android:textColor="@color/colorPrimaryDark"
android:textSize="30sp"
android:textStyle="bold" />
<EditText
android:id="@+id/et_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<TextView
android:id="@+id/textView3"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#72C8E8"
android:padding="4sp"
android:paddingLeft="4sp"
android:paddingTop="4sp"
android:paddingRight="4sp"
android:paddingBottom="4sp"
android:text="@string/gender"
android:textColor="@color/colorPrimaryDark"
android:textSize="30sp"
android:textStyle="bold" />
<CheckBox
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:onClick="onCheckboxClicked"
android:text="@string/m"
android:textSize="24sp" />
<CheckBox
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onCheckboxClicked"
android:text="@string/f"
android:textSize="24sp" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#72C8E8"
android:padding="4sp"
android:paddingLeft="4sp"
android:paddingTop="4sp"
android:paddingRight="4sp"
android:paddingBottom="4sp"
android:text="@string/address"
android:textColor="@color/colorPrimaryDark"
android:textSize="30sp"
android:textStyle="bold" />
<EditText
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPostalAddress" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:text="@string/phone"
android:background="#72C8E8"
android:padding="4sp"
android:paddingLeft="4sp"
android:paddingTop="4sp"
android:paddingRight="4sp"
android:paddingBottom="4sp"
android:textColor="@color/colorPrimaryDark"
android:textSize="30sp"
android:textStyle="bold" />
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/camera"
android:background="#72C8E8"
android:padding="4sp"
android:paddingLeft="4sp"
android:paddingTop="4sp"
android:paddingRight="4sp"
android:paddingBottom="4sp"
android:textColor="@color/colorPrimaryDark"
android:textSize="30sp"
android:textStyle="bold"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="281dp"
android:layout_height="154dp"
android:layout_above="@+id/button1"
android:layout_alignParentTop="false"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/ic_launcher_background" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="24dp"
android:background="#72C8E8"
android:padding="4sp"
android:paddingLeft="4sp"
android:paddingTop="4sp"
android:paddingRight="4sp"
android:paddingBottom="4sp"
android:text="@string/img"
android:textSize="24sp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="24dp"
android:background="#72C8E8"
android:padding="4sp"
android:paddingLeft="4sp"
android:paddingTop="4sp"
android:paddingRight="4sp"
android:paddingBottom="4sp"
android:text="@string/export"
android:textSize="24sp" />
</LinearLayout>
</ScrollView>
МАНИФЕСТ:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission-sdk-23 android:name="android.permission.CAMERA"/>
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:name="android.hardware.camera"
android:required="false"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>