-1
2つのボタンを使って2つのURLリンクを開きます。私はボタンを押すとブラウザに行きます。しかし、私は自分のアプリケーション内でこれらのURLリンクを開きたいと思います。誰かが私の問題を解決するのを助けることができますか?以下のように私のコード:私のアンドロイドアプリケーション内でURLリンクを開く方法
活動メイン:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.vkumar.myapplication.MainActivity"
android:background="#d3a7a7">
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="GOOGLE"
android:onClick="browser1"
android:id="@+id/browser1"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="@android:color/holo_blue_dark" />
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="MAIL"
android:id="@+id/browser2"
android:onClick="browser2"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="@android:color/holo_blue_dark" />
</LinearLayout>
主な活動:
package com.example.vkumar.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button browser1 = (Button) findViewById(R.id.browser1);
Button browser2 = (Button) findViewById(R.id.browser2);
Button browser3 = (Button) findViewById(R.id.browser3);
Button browser4 = (Button) findViewById(R.id.browser4);
Button browser5 = (Button) findViewById(R.id.browser5);
}
public void browser1 (View view) {
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.google.co.in/"));
startActivity(intent);
}
public void browser2 (View v) {
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.gmail.com/"));
startActivity(intent);
}
}
Androidのマニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.vkumar.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="MY APP" android:supportsRtl="true" android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
は、「しかし、私は自分のアプリケーション内でこれらのURLリンクを開きたい」WebViewの活動へのURLを渡す - これは何を意味するのでしょうか?あなたはどこかに 'WebView'を持っていますか? – CommonsWare
私はこのAndroidアプリケーションを自分の携帯電話の1つのプロジェクトに使用します。私はボタンをクリックすると、それは私のアプリケーション内の指定されたURLのWebサイトに移動する必要がありますが、今それは電話のインターネットブラウザに移動します。 – vkumar
詳細を**に、**私のアプリケーションの中の与えられたURLのウェブサイトに行くべきであることを意味してください。 – CommonsWare