电池信息检测(可拓展版)

电池块的功能要求:

1>.要求检测到安卓手机的电量,电压,连接状态,充电连接方式,以及当前的时间,而这些与电池相关的信息都会通过系统广播发出来,去注册相应广播接收即可,然后通过BatteryManager这个类来获取这些信息。

2.>首先通过TextView控件做展示;其次将这些信息保存到data/data/包名/files下,文件名为data;最后还得将这些数据通过listview控件展示(因为是要求电量发生变化就记录保存一次相应信息;相应每改变一次,listview里面就相应的增加一次改变的信息)

3>代码中写的虽然是通过定时器每隔30秒就去获取一下系统的电池变化,然后将每次变化信息保存到data/data/包名/files下,然后再将每次电池变化信息依次展示到listview里面。


时间块的功能要求:

1>.系统启动时间(不是系统当前的时间)展示;这个要通过注册开机广播,然后开服务,在服务里面获取时间。

2>.App启动时间展示;应用启动时获取当前的时间,在MainActivity里面完成。

3>.每隔10s获取一下系统当前时间,在TextView里面做即时展示,在ListView里面展示之前每10s所获取的所有数据。获取时间的数据在MainActivity里面完成,数据展示在Fragment里面完成,涉及到MainActivity向fragment传递数据


电池信息检测(可拓展版)demo下载


直接贴代码:

1.MainActivity里面代码

package com.zhc.batte;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {
	private int oldbatteryLevel = 0;
	private int batteryLevel;
	private int BatteryT;
	private String BatteryTc;
	private int BatteryTcc;
	private String nul = "   ";
	private String inputtext;
	private int batteryScale;
	private Handler mHandler;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Button button = (Button) findViewById(R.id.lf_bt);
		Button button1 = (Button) findViewById(R.id.lf_button_time);
		button.setOnClickListener(this);
		button1.setOnClickListener(this);

		IntentFilter intentFilter = new IntentFilter(
				Intent.ACTION_BATTERY_CHANGED);
		// 1.1注册接收器以获取电量信息
		registerReceiver(broadcastReceiver, intentFilter);

		/**
		 * 2.2获取app启动时间,保存到sp里面
		 */
		ActivityManager am = (ActivityManager) getSystemService(MainActivity.ACTIVITY_SERVICE);
		List<RunningAppProcessInfo> appinfo = am.getRunningAppProcesses();
		for (RunningAppProcessInfo runningAppProcessInfo : appinfo) {
			if (runningAppProcessInfo.processName.equals("com.zhc.batte")) {// 注意包名
				Log.e("tag", System.currentTimeMillis() + "");
				/**
				 * 获取app time
				 */
				long currentTime = System.currentTimeMillis();
				SimpleDateFormat formatter = new SimpleDateFormat(
						"yyyy年MM月dd日HH时mm分ss秒");
				Date date = new Date(currentTime);
				/**
				 * 保存到sp
				 */
				SharedPreferences sharedPreferences = getSharedPreferences(
						"AppTime", Context.MODE_PRIVATE);
				Editor editor = sharedPreferences.edit();
				editor.putString("apptime", formatter.format(date) + "");
				editor.commit();// 别忘了提交
			}
		}

		/**
		 * 2.3.开子线程做了三件事: 1.每隔10s获取一下当前的时间; 2.将每隔10s的时间保存到到文件里面;
		 * 3.通过mhandler将每隔10s得到的当前时间由此MainActivity传到TimeRightFragment。
		 */
		new Thread(new Runnable() {
			@Override
			public void run() {
				// 每秒改变textview的值
				while (true) {
					try {
						Thread.sleep(10 * 1000); // 睡眠10s,这个睡眠10s不能放在本线程的末尾,如果放在末尾会在前4s作死的打印日志。
						Message msg = new Message();
						msg.what = 1;
						Bundle bundle = new Bundle();

						SimpleDateFormat formatter = new SimpleDateFormat(
								"yyyy年MM月dd日 HH:mm:ss ");
						Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
						String date = formatter.format(curDate);

						// 传入值
						bundle.putString("num", date);

						String inputText = date + "\r\n";
						// 保存数据
						save(inputText);

						msg.setData(bundle);
						// mHandler传递参数 ;mHandler为全局变量
						mHandler.sendMessage(msg);

					} catch (Exception e) {
						e.printStackTrace();
						System.out.println("thread error...");
					}
				}
			}

		}).start();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		unregisterReceiver(broadcastReceiver);// 注销广播
	}

	/**
	 * 设置Handler: 1.mHandler在子线程的里面通过sendMessage方法设置了数据;
	 * 该数据将由此MainActivity传到TimeRightFragment。
	 * 2.setHandler方法用于在TimeRightFragment中的回调函数onAttach
	 * ()中得到TimeRightFragment所在MainActivity;
	 * 并调用此setHandler方法得到mHandler,然后TimeRightFragment创建Handler对象
	 * ,通过标记拿到相应的Message;(第一种由MainActivity向Fragment传递数据的方式;)。 
	 * 3.mHandler要为全局变量。
	 * 
	 * @param handler
	 */
	public void setHandler(Handler handler) {
		mHandler = handler;
	}

	
	public void save(String inputText) {
		FileOutputStream out = null;
		BufferedWriter writer = null;
		try {
			out = openFileOutput("data", Context.MODE_APPEND);
			writer = new BufferedWriter(new OutputStreamWriter(out));
			writer.write(inputText);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (writer != null) {
					writer.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 点击加载相应的Fragment: 1.在加载Fragment时也可以往其中加入数据用于MainActivity与Fragment之间的数据的传递。
	 * 2.Fragment.setArguments(myBundle);第二种由MainActivity向Fragment传递数据的方式;
	 */
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.lf_bt:
			// 1.此Fragment里面传入了数据
			Bundle myBundle = new Bundle();// 放数据的容器
			myBundle.putString("data", inputtext);// 容器内放入数据
			AnotherRightFragment anotherfragment = new AnotherRightFragment();
			anotherfragment.setArguments(myBundle);// 把容器这个参数设置给Fragment
			FragmentManager fragmentManager = getFragmentManager();
			FragmentTransaction transaction = fragmentManager
					.beginTransaction();
			transaction.replace(R.id.right_layout, anotherfragment, "myTag");
			transaction.addToBackStack(null);
			transaction.commit();
			break;
		case R.id.lf_button_time:
			TimeRightFragment timefragment = new TimeRightFragment();
			FragmentManager fragmentManager1 = getFragmentManager();
			FragmentTransaction transaction1 = fragmentManager1
					.beginTransaction();
			transaction1.replace(R.id.right_layout, timefragment);
			transaction1.addToBackStack(null);
			transaction1.commit();
			break;
		default:
			break;
		}
	}

	/**
	 * 注册广播用于获取相应的电池变化信息
	 */
	private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			// 电池温度
			BatteryT = intent.getIntExtra("temperature", 0);
			// BatteryTc=(BatteryT+"").substring(0,3);
			BatteryTc = BatteryT + "";
			BatteryTcc = Integer.parseInt(BatteryTc);

			// 获取当前电量,如未获取具体数值,则默认为0
			batteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
			// 获取最大电量,如未获取到具体数值,则默认为100
			batteryScale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
			// 显示电量
			// textViewLevel.setText("电量" + (batteryLevel * 100 / batteryScale)
			// + "%");

			/**
			 * 时间
			 */
			// SimpleDateFormat sDateFormat = new SimpleDateFormat(
			// "yyyy-MM-dd hh:mm:ss:SSS ");
			// String date = sDateFormat.format(new java.util.Date());
			// textViewLevel1.setText("battery: date=" + date);

			SimpleDateFormat formatter = new SimpleDateFormat(
					"yyyy年MM月dd日 HH:mm:ss ");
			Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
			String date = formatter.format(curDate);

			/**
			 * 电池状态
			 */
			int status = intent.getIntExtra("status", 0);
			String statusString = "";
			switch (status) {
			case BatteryManager.BATTERY_STATUS_UNKNOWN:
				statusString = "未知状态";
				break;
			case BatteryManager.BATTERY_STATUS_CHARGING:
				statusString = "充电状态";
				break;
			case BatteryManager.BATTERY_STATUS_DISCHARGING:
				statusString = "放电状态";
				break;
			case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
				statusString = "未充电   ";
				break;
			case BatteryManager.BATTERY_STATUS_FULL:
				statusString = "充满状态";
				break;
			}

			// textViewLevel2.setText("status " + statusString);

			/**
			 * 电压
			 */
			int voltage = intent.getIntExtra("voltage", 0);
			// textViewLevel3.setText("voltage=" + voltage);

			/**
			 * Usb还是ac供电
			 */
			int plugged = intent.getIntExtra("plugged", 0);
			String acString = "";
			switch (plugged) {
			case BatteryManager.BATTERY_PLUGGED_AC:
				acString = "ac";
				break;
			case BatteryManager.BATTERY_PLUGGED_USB:
				acString = "usb";
				break;
			}
			// textViewLevel4.setText("acString=" + acString);

			String inputText = "\r\n" + "时间:" + date + nul + statusString + nul
					+ "电量:" + (batteryLevel * 100 / batteryScale) + "%" + nul
					+ "电压:" + voltage + "mV" + nul + "温度:" + (BatteryTcc * 0.1)
					+ "℃" + nul + "供电:" + acString + "\r\n";

			// 传入值
			inputtext = inputText;

			if (batteryLevel != oldbatteryLevel) {
				oldbatteryLevel = batteryLevel;
				// 保存电池信息数据数据
				save(inputText);

			}
			;

		}

		/**
		 * 保存电池信息数据到文件
		 * 
		 * @param inputText
		 */
		public void save(String inputText) {
			FileOutputStream out = null;
			BufferedWriter writer = null;
			try {
				out = openFileOutput("battdata", Context.MODE_APPEND);
				writer = new BufferedWriter(new OutputStreamWriter(out));
				writer.write(inputText);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					if (writer != null) {
						writer.close();
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

	};

}

2.AnotherRightFragment里面代码

package com.zhc.batte;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.app.Fragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class AnotherRightFragment extends Fragment {

	private Activity mActivity;// 宿主
	private TextView textViewLevel;
	private ListView ListViewBattery5;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mActivity = getActivity();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
	
		View view = View.inflate(mActivity, R.layout.another_right_fragment,
				null);
		return view;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		
		textViewLevel = (TextView) view.findViewById(R.id.textViewBattery);
		ListViewBattery5 = (ListView) view.findViewById(R.id.ListViewBattery5);
		
		/*Bundle bundle1 = getArguments();
		textViewLevel.setText(bundle1.getString("id"));*/
		//获得数据
		String data=getFragmentManager().findFragmentByTag("myTag").getArguments().getString("data");
		textViewLevel.setText(data);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
/*		broadcastManager = LocalBroadcastManager.getInstance(getActivity());
		intentFilter = new IntentFilter();
		intentFilter.addAction("android.intent.action.BATTERY_CHANGED");
		broadcastManager.registerReceiver(broadcastReceiver, intentFilter);*/
	/*String	type = getArguments().getString("type");
    textViewLevel.setText(type);
    */
    
		// 读取数据
		String inputText1 = load();
		if (!TextUtils.isEmpty(inputText1)) {
			ArrayAdapter<String> adapter = new ArrayAdapter<String>(
					getActivity().getBaseContext(),
					android.R.layout.simple_list_item_1);
			adapter.add(inputText1);
			ListViewBattery5.setAdapter(adapter);
		}
		
	}
	public String load() {
		FileInputStream in = null;
		BufferedReader reader = null;
		StringBuilder content = new StringBuilder();
		try {
			in = getActivity().openFileInput("battdata");
			reader = new BufferedReader(new InputStreamReader(in));
			String line = "";
			while ((line = reader.readLine()) != null) {
				line = line + "\n";
				content.append(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return content.toString();
	};
}

3.BatteryService里面代码

package com.zhc.batte;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class c extends Service {

    private static final String TAG = "BatteryService"; 
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    
    @Override  
    public void onCreate() {  
        super.onCreate(); 
        Toast.makeText(getBaseContext(), "onCreate complete222222222222222222",Toast.LENGTH_SHORT ).show();
        Log.d(TAG, "onCreate--------------");
     // 获取系统启动的当前时间
        SimpleDateFormat	formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss ");
     			Date curDate = new Date(System.currentTimeMillis());
     			String	date = formatter.format(curDate);
     			//保存到sp
     			SharedPreferences	sharedPreferences = getSharedPreferences("BootUpTime",
     					Context.MODE_PRIVATE);
     			Editor	editor = sharedPreferences.edit();
     			editor.putString("systemtimekey", date);
     			editor.commit();// 别忘了提交
      
    }
    
    @Override  
    public void onStart(Intent intent, int startId) {
    	 Log.d(TAG, "onStart--------------");
        super.onStart(intent, startId);  
    }
    
    @Override  
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG, "onStartCommand--------------");
        return Service.START_STICKY; 
    }
    
    @Override  
    public void onDestroy() {  
        Log.d(TAG, "onDestroy--------------");
        super.onDestroy(); 
    }
}

4.BootUpReceiver里面代码

package com.zhc.batte;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class BootUpReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		Toast.makeText(context, "Boot complete",Toast.LENGTH_SHORT ).show();
			System.out.println("------------222222BootUpReceiver22222------------");
			//跳转到服务
			Intent in0 = new Intent(context, BatteryService.class);
			context.startService(in0);
		}
}

5.LeftFragment里面代码

package com.zhc.batte;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class LeftFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	View view=inflater.inflate(R.layout.left_fragment,container, false);
	return view;
}
}

6.RightFragment里面代码

package com.zhc.batte;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class RightFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view=inflater.inflate(R.layout.right_fragment, container, false);
		return view;
	}
}

7.TimeRightFragment里面代码

package com.zhc.batte;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Fragment;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class TimeRightFragment extends Fragment {
    private TextView tvShow;
    private ListView ListViewBattery5;
	private Activity mActivity;// 宿主
	private TextView boottimetextView;
	private TextView apptimetextView;
	
	@Override
	public void onAttach(Activity activity) {
	super.onAttach(activity);
	mActivity = (MainActivity) activity;
	((MainActivity) mActivity).setHandler(mHandler);
	}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mActivity = getActivity();
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = View.inflate(mActivity, R.layout.time_right_fragment,
				null);
		return view;
	}
	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		boottimetextView = (TextView) view.findViewById(R.id.boot_time_rf_tv);
		apptimetextView = (TextView) view.findViewById(R.id.app_time_rf_tv);
        ListViewBattery5 = (ListView) view.findViewById(R.id.ListViewBattery5);
        tvShow = (TextView) view.findViewById(R.id.tv_show);
	}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		/**
		 * 获取boot的sp的boot time数据
		 */
		SharedPreferences pre=getActivity().getSharedPreferences("BootUpTime",
					Context.MODE_PRIVATE);
		String time = pre.getString("systemtimekey","" );
		System.out.println("11111111boot time1111111111111"+time);
		boottimetextView.setText("1>.系统开机启动时间:"+time);
		
		
		/**
		 * 从sp里面获取apptime数据
		 */
		SharedPreferences apppre=getActivity().getSharedPreferences("AppTime",
					Context.MODE_PRIVATE);
		String apptime = apppre.getString("apptime","" );
		System.out.println("66666666app time666666"+apptime);
		apptimetextView.setText("2>.app启动时间:"+apptime);
		
		
	}
	
//	public Handler mHandler = new Handler() {
//		public void handleMessage(android.os.Message msg) {
//		switch (msg.what) {
//		case 1:
//		text.setText((String) msg.obj);
//		break;
//		}
//		};
//		};
	 // handler类接收数据  
		  Handler mHandler = new Handler() {  
	        public void handleMessage(Message msg) {  
	            if (msg.what == 1) {  
	                // 动态更新UI界面  
	                String str = msg.getData().getString("num") + "";  
	                tvShow.setText("3>."+str);  
	                
	              //读取数据
					String inputText1 = load();
					if (!TextUtils.isEmpty(inputText1)) {
						ArrayAdapter<String> adapter = new ArrayAdapter<String>(
								getActivity().getBaseContext(), android.R.layout.simple_list_item_1
								);
						adapter.add(inputText1);
						ListViewBattery5.setAdapter(adapter);
					}
	              
	            } 
	        }; 
	        public String load() {
	 			FileInputStream in = null;
	 			BufferedReader reader = null;
	 			StringBuilder content = new StringBuilder();
	 			try {
	 				in = getActivity().openFileInput("data");
	 				reader = new BufferedReader(new InputStreamReader(in));
	 				String line = "";
	 				while ((line = reader.readLine()) != null) {
	 					line= line + "\n";
	 					content.append(line);
	 				}
	 			} catch (IOException e) {
	 				e.printStackTrace();
	 			} finally {
	 				if (reader != null) {
	 					try {
	 						reader.close();
	 					} catch (IOException e) {
	 						e.printStackTrace();
	 					}
	 				}
	 			}
	 			return content.toString();
	 		};
	    };  

}

8.activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/left_frgment"
        android:name="com.zhc.batte.LeftFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <FrameLayout
        android:id="@+id/right_layout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="8" >

        <fragment
            android:id="@+id/right_frgment"
            android:name="com.zhc.batte.RightFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>

</LinearLayout>

9.another_right_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textViewBattery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="haha" />

    <ListView
        android:id="@+id/ListViewBattery5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textViewBattery"
        android:transcriptMode="alwaysScroll" />

</RelativeLayout>

10.left_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <Button 
        android:id="@+id/lf_bt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="电池"/>
    <Button 
        android:id="@+id/lf_button_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="时间"/>
</LinearLayout>

11. right_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
<TextView 
    android:id="@+id/another_rf_tv"
   android:layout_width="match_parent"
    android:layout_height="match_parent"
     />
</LinearLayout>

12.time_right_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/boot_time_rf_tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="haha"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/app_time_rf_tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="hehehehehheheh"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/tv_show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
        android:textSize="18sp" />

    <ListView
        android:id="@+id/ListViewBattery5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:transcriptMode="alwaysScroll" />

</LinearLayout>

13.清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.zhc.batte"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="16" />
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
         <service
            android:name = ".BatteryService">                     
        </service>
        <receiver android:name=".BootUpReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                 <category android:name="android.intent.category.LAUNCHER" /> 
            </intent-filter>
        </receiver>
        <activity
            android:name="com.zhc.batte.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值