実現したいこと
Chromeからテキストを共有して自作のアプリに表示させたい
前提
Android Studio 2022.3.1 patch 4
Gradle Plugin Version 8.1.4
Gradle Version 8.0
Compile Sdk Version 34
発生している問題・エラーメッセージ
共有した後にIntentにデータを入れる動作が行われない状況です。
d.receivingtest com.android.receivingtest W Redefining intrinsic method java.lang.Thread java.lang.Thread.currentThread(). This may cause the unexpected use of the original definition of java.lang.Thread java.lang.Thread.currentThread()in methods that have already been compiled. d.receivingtest com.android.receivingtest W Redefining intrinsic method boolean java.lang.Thread.interrupted(). This may cause the unexpected use of the original definition of boolean java.lang.Thread.interrupted()in methods that have already been compiled. Compatibil...geReporter com.android.receivingtest D Compat change id reported: 171979766; UID 10192; state: ENABLED Compatibil...geReporter com.android.receivingtest D Compat change id reported: 242716250; UID 10192; state: ENABLED ziparchive com.android.receivingtest W Unable to open '/data/app/~~W27E5yHhUYjgtf_pndsoTg==/com.android.receivingtest-6r0cKRxikUna-MM4eIXxRQ==/base.dm': No such file or directory ziparchive com.android.receivingtest W Unable to open '/data/app/~~W27E5yHhUYjgtf_pndsoTg==/com.android.receivingtest-6r0cKRxikUna-MM4eIXxRQ==/base.dm': No such file or directory nativeloader com.android.receivingtest D Configuring clns-6 for other apk /data/app/~~W27E5yHhUYjgtf_pndsoTg==/com.android.receivingtest-6r0cKRxikUna-MM4eIXxRQ==/base.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/~~W27E5yHhUYjgtf_pndsoTg==/com.android.receivingtest-6r0cKRxikUna-MM4eIXxRQ==/lib/x86_64, permitted_path=/data:/mnt/expand:/data/user/0/com.android.receivingtest GraphicsEnvironment com.android.receivingtest V Currently set values for: GraphicsEnvironment com.android.receivingtest V angle_gl_driver_selection_pkgs=[] GraphicsEnvironment com.android.receivingtest V angle_gl_driver_selection_values=[] GraphicsEnvironment com.android.receivingtest V ANGLE GameManagerService for com.android.receivingtest: false GraphicsEnvironment com.android.receivingtest V com.android.receivingtest is not listed in per-application setting GraphicsEnvironment com.android.receivingtest V Neither updatable production driver nor prerelease driver is supported. libEGL com.android.receivingtest D loaded /vendor/lib64/egl/libEGL_emulation.so libEGL com.android.receivingtest D loaded /vendor/lib64/egl/libGLESv1_CM_emulation.so libEGL com.android.receivingtest D loaded /vendor/lib64/egl/libGLESv2_emulation.so AppCompatDelegate com.android.receivingtest D Checking for metadata for AppLocalesMetadataHolderService : Service not found d.receivingtest com.android.receivingtest W Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (unsupported, reflection, allowed) d.receivingtest com.android.receivingtest W Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (unsupported, reflection, allowed) Compatibil...geReporter com.android.receivingtest D Compat change id reported: 210923482; UID 10192; state: ENABLED intent com.android.receivingtest D intent:Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.android.receivingtest/.MainActivity } Compatibil...geReporter com.android.receivingtest D Compat change id reported: 237531167; UID 10192; state: DISABLED OpenGLRenderer com.android.receivingtest W Unknown dataspace 0 OpenGLRenderer com.android.receivingtest W Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... OpenGLRenderer com.android.receivingtest W Failed to initialize 101010-2 format, error = EGL_SUCCESS Gralloc4 com.android.receivingtest I mapper 4.x is not supported OpenGLRenderer com.android.receivingtest E Unable to match the desired swap behavior. ProfileInstaller com.android.receivingtest D Installing profile for com.android.receivingtest //chromeから共有 OpenGLRenderer com.android.receivingtest E Unable to match the desired swap behavior.
emulatorなどを再起動してなぜか一度だけうまくいったログです //chromeから共有 AssistStructure com.android.receivingtest I Flattened final assist data: 1128 bytes, containing 1 windows, 11 views EGL_emulation com.android.receivingtest D app_time_stats: avg=2194.26ms min=0.84ms max=32670.24ms count=17 intent com.android.receivingtest D intent:Intent { act=android.intent.action.SEND typ=text/plain flg=0x1b080000 cmp=com.android.receivingtest/.MainActivity clip={text/plain {T(184)}} (has extras) } sharedText com.android.receivingtest D sharedText:"場合" https://news.yahoo.co.jp/articles/3d8cce9fbde19cd7d5bedbfec7b87e90d0e7a865#:~:text=%E3%82%92%E4%BD%BF%E3%81%86-,%E5%A0%B4%E5%90%88,-%E3%81%AF1%E3%83%9D%E3%82%A4%E3%83%B3%E3%83%88 OpenGLRenderer com.android.receivingtest W Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... OpenGLRenderer com.android.receivingtest W Failed to initialize 101010-2 format, error = EGL_SUCCESS OpenGLRenderer com.android.receivingtest E Unable to match the desired swap behavior. AutofillManager com.android.receivingtest D Fill dialog is enabled:false, hints=[]
該当のソースコード
AndroidManifest.xml
1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools"> 4 <application 5 android:allowBackup="true" 6 android:dataExtractionRules="@xml/data_extraction_rules" 7 android:fullBackupContent="@xml/backup_rules" 8 android:icon="@mipmap/ic_launcher" 9 android:label="@string/app_name" 10 android:roundIcon="@mipmap/ic_launcher_round" 11 android:supportsRtl="true" 12 android:theme="@style/Theme.ReceivingTest" 13 tools:targetApi="31"> 14 <activity 15 android:name=".MainActivity" 16 android:exported="true"> 17 <intent-filter> 18 <action android:name="android.intent.action.MAIN" /> 19 20 <category android:name="android.intent.category.LAUNCHER" /> 21 </intent-filter> 22 <intent-filter> 23 <action android:name="android.intent.action.SEND" /> 24 <category android:name="android.intent.category.DEFAULT" /> 25 <data android:mimeType="text/plain" /> 26 </intent-filter> 27 </activity> 28 </application> 29 30</manifest>
MainActivity.java
1public class MainActivity extends AppCompatActivity { 2 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.activity_main); 7 8 Intent intent = getIntent(); 9 String action = intent.getAction(); 10 String type = intent.getType(); 11 12 Log.d("intent","intent:"+intent); 13 14 if (Intent.ACTION_SEND.equals(action) && type != null) { 15 if ("text/plain".equals(type)) { 16 handleSendText(intent); 17 } 18 } 19 } 20 21 void handleSendText(Intent intent) { 22 String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); 23 Log.d("sharedText", "sharedText:"+sharedText); 24 if (sharedText != null) { 25 TextView sharedBox = findViewById(R.id.TextView); 26 sharedBox.setText(sharedText); 27 } 28 } 29}
activity_main.xml
1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity"> 8 9 <TextView 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:id="@+id/TextView" 13 app:layout_constraintBottom_toBottomOf="parent" 14 app:layout_constraintEnd_toEndOf="parent" 15 app:layout_constraintStart_toStartOf="parent" 16 app:layout_constraintTop_toTopOf="parent" /> 17 18</androidx.constraintlayout.widget.ConstraintLayout>
補足情報(FW/ツールのバージョンなど)

回答1件
あなたの回答
tips
プレビュー