前提・実現したいこと
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でインストールしてテストを行っています。
あなたの回答
tips
プレビュー