質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

解決済

1回答

2102閲覧

KotlinのIntentで外部アプリを起動したい

HamaDroid

総合スコア22

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2022/02/27 05:11

実現したいこと
ImageButtonを押してアプリを起動できるようにする。(今回はRakuten Link)

環境
Android Studio Bumblebee | 2021.1.1 Patch 2
Kotlin Plugin Version 211-1.6.10-release-923-AS7442.40
Android 9.0

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 <LinearLayout 10 android:layout_width="match_parent" 11 android:layout_height="match_parent" 12 android:orientation="horizontal"> 13 14 <LinearLayout 15 android:layout_width="match_parent" 16 android:layout_height="match_parent" 17 android:orientation="vertical"> 18 19 <ImageButton 20 android:id="@+id/link" 21 android:layout_width="150dp" 22 android:layout_height="150dp" 23 android:layout_marginLeft="12dp" 24 android:layout_marginTop="12dp" 25 android:onClick="link" 26 app:srcCompat="@drawable/icon_link" 27 tools:ignore="SpeakableTextPresentCheck" /> 28 29 <TextView 30 android:id="@+id/textView" 31 android:layout_width="wrap_content" 32 android:layout_height="wrap_content" 33 android:layout_marginLeft="64dp" 34 android:text="@string/rakuten_link" 35 android:textAlignment="center" 36 android:textSize="20sp" 37 android:textStyle="bold" /> 38 </LinearLayout> 39 40 </LinearLayout> 41</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.kt

1package com.hamachi.rmini_home 2 3import android.content.Intent 4import android.net.Uri 5import androidx.appcompat.app.AppCompatActivity 6import android.os.Bundle 7import android.widget.Button 8import android.widget.ImageButton 9 10class MainActivity : AppCompatActivity() { 11 override fun onCreate(savedInstanceState: Bundle?) { 12 super.onCreate(savedInstanceState) 13 setContentView(R.layout.activity_main) 14 15 val button = findViewById<ImageButton>(R.id.link) 16 button.setOnClickListener { 17 18 val intent = Intent(Intent.ACTION_VIEW) 19 intent.setPackage("jp.co.rakuten.mobile.rcs") 20 startActivity(intent) 21 } 22 } 23}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

試しにやってみましたが、下記で出来ました。

kotlin

1var intent = packageManager.getLaunchIntentForPackage("jp.co.rakuten.mobile.rcs") 2startActivity(intent)

あと、Android11以降からは、Manifestに以下のように追加する必要があります。

xml

1 <queries> 2 <package android:name="jp.co.rakuten.mobile.rcs" /> 3 </queries>

投稿2022/03/03 03:58

daichi_mizuno

総合スコア47

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

HamaDroid

2022/03/04 08:11

解決しました。ご丁寧にお答えいただきありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問