Добрый день Новичок в android разработке, и я запутался в выводе данных на макет. Я пытаюсь распечатать URL-адрес в редактируемом окне с именем sharedText
. Цель состоит в том, чтобы отправить URL-адрес в мое редактируемое представление, нажав кнопку «Поделиться» в настройках браузера, и получить его в своем logcat, когда кнопка «Поделиться» нажата, но URL-адрес не отображается в приложении. '2020-04-30 12: 04: 59.730 3675-3675 / com.e.testshare D / MainActivity: sharedText: https://www.bbc.co.uk/news'
editview id является общим текстом
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
if (intent != null) {
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleReceivedText(intent); // Handle text being sent
}
}
void handleReceivedText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
Log.d("MainActivity", "sharedText : " + sharedText);
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("SHAREDTEXT", sharedText);
startActivity(i);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.e.testshare">
<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"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="Share Testing">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
</manifest>
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
<EditText
android:id="@+id/sharedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="UrlAddress"
tools:layout_editor_absoluteX="78dp"
tools:layout_editor_absoluteY="89dp" />