Я только начинаю с Android (и программирую в целом)
Я хочу получить Uri из другого приложения, чтобы я мог передать этот Uri в Google Print Cloud.
Я пытаюсь следовать приведенным здесь инструкциям: https://developer.android.com/training/basics/intents/result#java
Однако я не могу разрешить 'PICK_FORM_REQUEST' во 2-й половине моего кода.
Что я делаю не так?
Вот мой код:
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// Called when the user taps the Pick button /
public void sendMessage(View view) {
// Do something in response to button
final int PICK_FORM_REQUEST = 1; // The request code
private void pickForm()
{
Intent pickFormIntent = new Intent(Intent.ACTION_PICK);
pickFormIntent.setType("vnd.android.cursor.dir/vnd.odk.form");
startActivityForResult(pickFormIntent, PICK_FORM_REQUEST);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode,resultCode,data);
// Check which request we're responding to
if (requestCode == PICK_FORM_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The Intent's data URI identifies which form was selected.
Uri formUri = data.getData();
// Do something with the form here
}
}
}
}
activity_main_ xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:hint="@string/edit_message"
android:inputType="textPersonName"
app:layout_constraintEnd_toStartOf="@+id/button"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:onClick="sendMessage"
android:text="@string/button_send"
app:layout_constraintBaseline_toBaselineOf="@+id/editText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/editText" />
</androidx.constraintlayout.widget.ConstraintLayout>