我希望我的应用能够在点击我的aboutus.xml中的联系信息时打开Facebook或电话拨号器 我该怎么做呢?我需要制作可点击的信息按钮吗?我很遗憾这个
MainActivity
package com.example.vitoriano_vaz.eastbayvapes;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
/*
This app is for a local Vape Shop
it's purpose is to increase customer flow, and provide a menu for Android users
the array is going to be called = da_menu
*/
public class MainActivity extends AppCompatActivity {
private static Intent java;
/*
called when the user clicks the send Button
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
This is new so i can send the user to the aboutUs.xml
once the button on the main menu ( activity_main.xml ) is clicked
*/
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, AboutActivity.class);
startActivity(intent);
}
});
populateListView();
}
private void populateListView() {
// Create the list of items
String[] juiceMenu= {
"#1 BLUEBERRY BOMBSHELL \nBlueberry Dessert",
"#2 RICHIE RICH\nStrawberry cream",
"#3 CHIQUITA\nCreamy Banana with a bready after taste",
"#4 AFTERNOON DELIGHT\nKiwi Strawberry Dessert",
"#5 POPPIN OTTERS\nMelted OtterPop",
"#6 VIVA LA SANGRIA\nFruit more Fruit and Wine",
"#7 OKOLE MALUNA\nPineapple fruit blend",
"#8 CARMEN MIRANDA\nVanilla custard with a crisp",
"#9 POMALADE\nIt's Bombalade!",
"#10 IZUAL\nWhirlwind of icy Fruits",
"#11 BUTTER STOTCH\nProfessor Chaos will surely get grounded for this one!",
"#12 BLUE BULLS\nGrab the bull by the horns",
"#13 GRAPE APE\nA grapple a day will keep the doctor away",
"#14 BRUCE JUICE\nPerfectly blended old fashioned",
"#15 DOC HOLIDAY\nN.E.T. Tabacco flavor",
"#16 PEACHY KEEN\nPeach Cobbler",
"#17 HULA\nStrawberry coconut ",
"#18 NEW YORK\nPeppermint paddy dipped in chocolate",
"#19 AL GORE\nFruit Loops plain and simple",
"#20 LUX CHARMS\nThey're magically delicious",
"#21 SAILOR JACK\nCracker Jack",
"#22 GET HIM TO THE GREEK\nGreek Yogurt with peach",
"#23 KEY WE LIE CHI\nFruit loving lychee",
"#24 SPRING FLING\nA trois of honeydew berries ",
"#25 GUMBY\nsour watermelon gummy",
"#26 CHAI\nMILK - Milk Chai Tea",
"#27 MR. BBEAN\nCappuccino cream",
"#28 50 SHADES OF ORANGE\nDelightful orange cream",
"#29 BLUE WAFFLES\nBlueberry Waffle",
"#30 ENIGMA\n Mystery",
"#31 MR. FREEZE\nPeppermint, Spearmint mainly just minty",
"#32 CUP OF JOE\nCup of French Vanilla",
"#33 BON JOVI\nVanilla Bourbon ",
};
// Build adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, // context for the activity
R.layout.da_menu, // Layout to create
juiceMenu); // Items to be displayed
//configure list view
ListView list = (ListView) findViewById(R.id.listViewMain);
list.setAdapter(adapter);
}
}
打开其他应用的信息
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E3E5E1"
android:inAnimation="@android:anim/slide_in_left">
<TextView
android:id="@+id/AboutUs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="About Us"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/AboutUs"
android:ems="10"
android:inputType="textEmailAddress"
android:text="eastbay@gmail.com"
android:textStyle="bold" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText2"
android:ems="10"
android:inputType="textPostalAddress"
android:text="1239 N Vasco RD Liver, Ca 94444"
android:textStyle="bold" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText3"
android:ems="10"
android:inputType="phone"
android:text="(925)-961-9999"
android:textStyle="bold" />
<EditText
android:id="@+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText4"
android:text="facebook.com/eastbay"
android:textStyle="bold" />
<EditText
android:id="@+id/editText6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText5"
android:text="Instagram: @eastbay"
android:textStyle="bold" />
<EditText
android:id="@+id/editText7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText6"
android:ems="10"
android:inputType="textMultiLine"
android:text="Monday - Saturday 10:00 am - 8:00 pm\n Sunday 10:00 am - 6:00 pm" />
</RelativeLayout>
答案 0 :(得分:0)
尝试了解如何使用Intent,例如,如果您希望用户使用特定的电话号码打开拨号器,您可以执行以下操作,并使用您想要的号码进行更改
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent);
检查此链接以了解其意图 http://developer.android.com/training/sharing/send.html
否则搜索堆栈溢出以执行特定操作
答案 1 :(得分:0)
for facebook,
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/eastbay"));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/eastbay"));
}
对于Instagram,
Uri uri = Uri.parse("http://instagram.com/_u/eastbay");
Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);
likeIng.setPackage("com.instagram.android");
try {
startActivity(likeIng);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://instagram.com/eastbay")));
}
发送电子邮件,
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "eastbay@gmail.com" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
拨号器,
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:9259619999"));
startActivity(intent);
用于地图,
String uri = "http://maps.google.co.in/maps?q=" + yourAddress;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
在此之前询问您应该使用Google。快乐的编码!