質問するログイン新規登録

Q&A

0回答

1288閲覧

Intentを自分のアプリで受け取ることができない

abushi

総合スコア13

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

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

Android Studio

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

0グッド

1クリップ

投稿2018/10/10 02:59

0

1

前提・実現したいこと

Androidアプリを作っています。
URLのリンクを開く際に、自分のアプリで開いてWebViewを使いたいのですが、
AndroidManifestを設定したのにIntentを受けとる事ができません。
ソースについて見ていただけないでしょうか。

該当のソースコード

MainActivity

1 2import android.content.Intent; 3import android.support.v7.app.AppCompatActivity; 4import android.os.Bundle; 5import android.view.Menu; 6import android.view.MenuItem; 7import android.util.Log; 8 9import android.view.Window; 10import android.webkit.WebResourceRequest; 11import android.webkit.WebSettings; 12import android.webkit.WebView; 13import android.webkit.WebViewClient; 14import android.widget.TextView; 15 16public class MainActivity extends AppCompatActivity { 17 18 @Override 19 protected void onCreate(Bundle savedInstanceState) { 20 super.onCreate(savedInstanceState); 21 setContentView(R.layout.activity_main); 22// requestWindowFeature(Window.FEATURE_NO_TITLE); //タイトルバーを非表示にする 23 24 // Webビューの作成 25 WebView webView = (WebView) findViewById(R.id.webview); 26 27 WebSettings settings = webView.getSettings(); 28 settings.setJavaScriptEnabled(true); 29 settings.setSupportMultipleWindows(true); 30 settings.setLoadsImagesAutomatically(true); 31 webView.setWebViewClient(new WebViewClient() { 32 @Override 33 public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { 34 return false; 35 } 36 }); 37 38 //インテントから飛んできたときの動作 39 Intent intent = getIntent(); 40 String action = intent.getAction(); 41 if (Intent.ACTION_VIEW.equals(action)){ 42 Log.v("INTENT",action.toString()); 43 android.net.Uri uri = intent.getData(); 44 webView.loadUrl(uri.toString()); 45 }else{ 46 //デフォルトのページの処理 47 webView.loadUrl("https://www.google.com/"); 48 } 49 } 50 51 @Override 52 public boolean onCreateOptionsMenu(Menu menu) { 53 // Inflate the menu; this adds items to the action bar if it is present. 54 getMenuInflater().inflate(R.menu.menu_main, menu); 55 return true; 56 } 57// 58 @Override 59 public void onResume() { 60 super.onResume(); // Always call the superclass method first 61 Log.d("test","onResume Started"); 62 } 63 64 @Override 65 public boolean onOptionsItemSelected(MenuItem item) { 66 // Handle action bar item clicks here. The action bar will 67 // automatically handle clicks on the Home/Up button, so long 68 // as you specify a parent activity in AndroidManifest.xml. 69 int id = item.getItemId(); 70 71 //noinspection SimplifiableIfStatement 72 if (id == R.id.action_settings) { 73 return true; 74 } 75 76 return super.onOptionsItemSelected(item); 77 } 78} 79

AndroidManifest

1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="xx.xx.xxxx" > 4 <uses-permission android:name="android.permission.INTERNET"/> 5 <application 6 android:allowBackup="true" 7 android:icon="@mipmap/ic_launcher" 8 android:label="@string/app_name" 9 android:theme="@style/AppTheme" > 10 <activity 11 android:name=".MainActivity" 12 android:label="@string/app_name" > 13 <intent-filter> 14 <action android:name="android.intent.action.MAIN" /> 15 <category android:name="android.intent.category.LAUNCHER" /> 16 <action android:name="android.intent.action.VIEW" /> 17 <category android:name="android.intent.category.DEFAULT" /> 18 <category android:name="android.intent.category.BROWSABLE"/> 19 <action android:name="android.intent.action.SEND" /> 20 <data android:mimeType="text/plain" /> 21 <data android:scheme="http" /> 22 <data android:scheme="https" /> 23 </intent-filter> 24 </activity> 25 </application> 26 27</manifest> 28

試したこと

実機をパソコンにつないでデバッグしています。
実行ファイルを発行しようとしましたが、無署名だと発行できないため、
AndroidStudioからUSBでインストールしてテストを行っています。

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.29%

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

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

質問する

関連した質問