Activity起動システムサービス
3851 ワード
*1、ブラウザを起動する:
*
intent.setsアクションVIEW);
*
Uri uri=Uri.parse("http://www.sina.com");
*
intent.set Data(uri);
*
startActivity(intent)
*
* 2、アルバムを起動する:
*
intent.setsアクションGET_CONTENT)
*
intent.setType(「イメージ/*」)
*
startActivity(intent)
*
* 3、起動メッセージ:
*
intent.setsアクションSEND);
*
intent.setType(「text/plin」)
*
intent.put Extra(Intent.EXTRA_)TEXT「これはメッセージです!」
*
startActivity(intent)
* 4、電話画面を起動する:
*
intent.setsアクションVIEW);
*
Uri uri 2=Uri.parse(「ホテル:10010」)
*
intent.set Data(uri 2);
* startActivity(intent)
*
intent.setsアクションVIEW);
*
Uri uri=Uri.parse("http://www.sina.com");
*
intent.set Data(uri);
*
startActivity(intent)
*
* 2、アルバムを起動する:
*
intent.setsアクションGET_CONTENT)
*
intent.setType(「イメージ/*」)
*
startActivity(intent)
*
* 3、起動メッセージ:
*
intent.setsアクションSEND);
*
intent.setType(「text/plin」)
*
intent.put Extra(Intent.EXTRA_)TEXT「これはメッセージです!」
*
startActivity(intent)
* 4、電話画面を起動する:
*
intent.setsアクションVIEW);
*
Uri uri 2=Uri.parse(「ホテル:10010」)
*
intent.set Data(uri 2);
* startActivity(intent)
public class StartSystemActivity extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_system);
Button btn_switch1 = (Button) findViewById(R.id.btn_switch1);
btn_switch1.setOnClickListener(this);
Button btn_switch2 = (Button) findViewById(R.id.btn_switch2);
btn_switch2.setOnClickListener(this);
Button btn_switch3 = (Button) findViewById(R.id.btn_switch3);
btn_switch3.setOnClickListener(this);
Button btn_switch4 = (Button) findViewById(R.id.btn_switch4);
btn_switch4.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent = new Intent();
switch(v.getId()){
case R.id.btn_switch1:
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.sina.com");
intent.setData(uri);
startActivity(intent);
break;
case R.id.btn_switch2:
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivity(intent);
break;
case R.id.btn_switch3:
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, " !");
startActivity(intent);
break;
case R.id.btn_switch4:
intent.setAction(Intent.ACTION_VIEW);
Uri uri2 = Uri.parse("tel:10010");
intent.setData(uri2);
startActivity(intent);
break;
}
}
}
activitystartsystem.xml<RelativeLayout 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"
tools:context="com.imooc.activitystudy.OneActivity" >
<Button
android:id="@+id/btn_switch1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" " />
<Button
android:layout_below="@id/btn_switch1"
android:id="@+id/btn_switch2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" " />
<Button
android:layout_below="@id/btn_switch2"
android:id="@+id/btn_switch3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" " />
<Button
android:layout_below="@id/btn_switch3"
android:id="@+id/btn_switch4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" " />
</RelativeLayout>