凌的博客

您现在的位置是:首页  > 学无止境 > Android

Android

使用android打开网页,发短信

2015-10-17Android0
package com.example.calculator; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.Gravity; import android.view.View;
package com.example.calculator;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;

public class SecondActivity  extends Activity{
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.second_layout);
		
		//返回
		Button btn_second_back = (Button)findViewById(R.id.btn_second_back);
		btn_second_back.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				Toast toast = Toast.makeText(getApplicationContext(),"返回首页",Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				
				Intent intent = new Intent(SecondActivity.this,CalculatorActivity.class);
				
				startActivity(intent);
			}
		});
		
		//打开百度
		Button btn_web = (Button)findViewById(R.id.btn_web);
		btn_web.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				Toast toast = Toast.makeText(getApplicationContext(), "打开百度", Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				Uri baiduUri = Uri.parse("https://www.baidu.com");
				Intent goIntent = new Intent(Intent.ACTION_VIEW,baiduUri);
				startActivity(goIntent);
			}
			
		});
		
		//拨打10086
		Button btn_yidong = (Button)findViewById(R.id.btn_yidong);
		btn_yidong.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				Toast toast = Toast.makeText(getApplicationContext(),"拨打10086", Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				
				Uri callUri = Uri.parse("tel:1008611");
				Intent goIntent = new Intent(Intent.ACTION_DIAL,callUri);
				startActivity(goIntent);
			}
		});
		
		//发短信
		Button btn_sms = (Button)findViewById(R.id.btn_sms);
		btn_sms.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				Toast toast = Toast.makeText(getApplicationContext(), "发短信", Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				
				Uri smsUri = Uri.parse("smsto:10086");
				Intent smsIntent = new Intent(Intent.ACTION_SENDTO,smsUri);
				smsIntent.putExtra("sms_body","你好,我发的短信~");
				startActivity(smsIntent);
			}
		});
		//打电话
		Button btn_call = (Button)findViewById(R.id.btn_call);
		btn_call.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				Toast toast = Toast.makeText(getApplicationContext(), "拨打10086", Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER	, 0, 0);
				toast.show();
				
				Uri callUri = Uri.parse("tel:10086");
				Intent goIntent = new Intent(Intent.ACTION_CALL,callUri);
				startActivity(goIntent);
			}
		});
		/**
//请求拨打电话权限



               */
		
		
		
	}

	}


如果本文对您有所帮助,请支持下本站哦!!!^_^

文章评论

0条评论