package com.propviewer; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.os.Bundle; import android.os.Environment; import android.telephony.TelephonyManager; import android.util.DisplayMetrics; import android.util.Log; import android.widget.TextView; public class MainActivity extends Activity { private StringBuffer info = new StringBuffer(); FileOutputStream fos = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = (TextView) findViewById(R.id.text); String ss = Environment.getExternalStorageDirectory().toString(); File f = new File(ss + "/phonemsg.txt"); if (!f.exists()) { try { f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } // android.os.Build info.append("android.os.Build.MODEL:" + android.os.Build.MODEL + "\n"); info.append("android.os.Build.VERSION.SDK:" + android.os.Build.VERSION.SDK + "\n"); info.append("android.os.Build.VERSION.RELEASE:" + android.os.Build.VERSION.RELEASE + "\n"); info.append("android.os.Build.BRAND:" + android.os.Build.BRAND + "\n"); info .append("android.os.Build.DEVICE:" + android.os.Build.DEVICE + "\n"); // Log.v("test","android.os.Build.MODEL:" // + android.os.Build.MODEL + "\n"); try { fos = new FileOutputStream(f); try { fos .write(("android.os.Build.MODEL:" + android.os.Build.MODEL + "\n").getBytes()); fos.write(("android.os.Build.VERSION.SDK:" + android.os.Build.VERSION.SDK + "\n").getBytes()); fos.write(("android.os.Build.VERSION.RELEASE:" + android.os.Build.VERSION.RELEASE + "\n").getBytes()); fos .write(("android.os.Build.BRAND:" + android.os.Build.BRAND + "\n").getBytes()); fos .write(("android.os.Build.DEVICE:" + android.os.Build.DEVICE + "\n").getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } // Screen Metric INFO ShowScreenMetricInfo(); // TELEPHONE info.append("\nTELEPHONE INFO\n"); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); info.append("DEVICE ID(MEID/IMEI):" + tm.getDeviceId() + "\n"); info.append("Subscriber ID:").append(tm.getSubscriberId()).append("\n"); info.append("DEVICE Software Version:" + tm.getDeviceSoftwareVersion() + "\n"); info.append("Line1 Number:" + tm.getLine1Number() + "\n"); info.append("Network Country ISO:" + tm.getNetworkCountryIso() + "\n"); info.append("Network Operator:" + tm.getNetworkOperator() + "\n"); info.append("Network Operator Name:" + tm.getNetworkOperatorName() + "\n"); // info.append("Network Type:"); info.append(getNetworkTypeStr(tm.getNetworkType())); info.append("\n"); // info.append("Phone Type:"); info.append(getPhoneTypeStr(tm.getPhoneType())); info.append("\n"); // System.getProperty info.append("\nSystem.getProperty\n"); for (int i = 0; i < SYS_PROP.length; ++i) { String pn = SYS_PROP[i]; info.append(pn + ":" + System.getProperty(pn) + "\n"); } info.append("\nMEMORY USAGE" + "\n"); try { fos.write(("\nTELEPHONE INFO\n").getBytes()); fos.write(("DEVICE ID(MEID/IMEI):" + tm.getDeviceId() + "\n") .getBytes()); fos .write((("Subscriber ID:") + (tm.getSubscriberId()) + ("\n")) .getBytes()); fos.write((("DEVICE Software Version:" + tm.getDeviceSoftwareVersion() + "\n")).getBytes()); fos.write(("Line1 Number:" + tm.getLine1Number() + "\n") .getBytes()); fos .write((("Network Country ISO:" + tm.getNetworkCountryIso() + "\n").getBytes())); fos .write((("Network Operator:" + tm.getNetworkOperator() + "\n")) .getBytes()); fos .write((("Network Type:") + getPhoneTypeStr(tm.getPhoneType()) + "\n") .getBytes()); fos .write((("Phone Type:") + getPhoneTypeStr(tm.getPhoneType()) + "\n") .getBytes()); fos.write("\nSystem.getProperty\n".getBytes()); for (int i = 0; i < SYS_PROP.length; ++i) { String pn = SYS_PROP[i]; fos.write((pn + ":" + System.getProperty(pn) + "\n") .getBytes()); } fos.write(("\nMEMORY USAGE" + "\n").getBytes()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // Memory Usage ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); ActivityManager.MemoryInfo mf = new ActivityManager.MemoryInfo(); am.getMemoryInfo(mf); info.append("剩余内存: ").append(mf.availMem >> 10).append("K\n"); ; info.append("剩余内存: ").append(mf.availMem >> 20).append("M\n"); ; info.append("是否处于低内存状态:").append(mf.lowMemory); info.append("" + "\n"); info.append("" + "\n"); try { fos.write((("剩余内存: ") + (mf.availMem >> 10) + ("K\n")).getBytes()); fos.write((("剩余内存: ") + (mf.availMem >> 20) + ("M\n")).getBytes()); fos.write((("是否处于低内存状态:") + (mf.lowMemory)).getBytes()); fos.write(("" + "\n").getBytes()); fos.write(("" + "\n").getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } tv.setText(info.toString()); } public void ShowScreenMetricInfo() { // Screen Metric INFO DisplayMetrics dm = this.getApplicationContext().getResources() .getDisplayMetrics(); info.append("\nScreen Metric INFO" + "\n"); info.append("The absolute width of the display in pixels: ").append( dm.widthPixels).append("\n"); info.append("The absolute height of the display in pixels: ").append( dm.heightPixels).append("\n"); info.append("The logical density of the display.: ").append(dm.xdpi) .append("\n"); info .append( "The exact physical pixels per inch of the screen in the Y dimension:") .append(dm.ydpi).append("\n"); info.append("The screen density expressed as dots-per-inch:").append( dm.density).append("\n"); info .append( "The exact physical pixels per inch of the screen in the X dimension:") .append(dm.densityDpi).append("\n"); info.append("A scaling factor for fonts displayed on the display:") .append(dm.scaledDensity).append("\n"); try { fos.write(("\nScreen Metric INFO" + "\n").getBytes()); fos.write((("The absolute width of the display in pixels: ") + dm.widthPixels + "\n").getBytes()); fos.write((("The absolute height of the display in pixels: ") + dm.heightPixels + "\n").getBytes()); fos .write((("The logical density of the display.: ") + dm.xdpi + "\n") .getBytes()); fos .write((("The exact physical pixels per inch of the screen in the Y dimension:") + dm.ydpi + "\n").getBytes()); fos.write((("The screen density expressed as dots-per-inch:") + dm.density + "\n").getBytes()); fos .write((("The exact physical pixels per inch of the screen in the X dimension:") + dm.densityDpi + "\n").getBytes()); fos.write((("A scaling factor for fonts displayed on the display:") + dm.scaledDensity + "\n").getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static String getPhoneTypeStr(int type) { switch (type) { case TelephonyManager.PHONE_TYPE_NONE: return "PHONE_TYPE_NONE"; case TelephonyManager.PHONE_TYPE_GSM: return "PHONE_TYPE_GSM"; case TelephonyManager.PHONE_TYPE_CDMA: return "PHONE_TYPE_CDMA"; default: return "unknow phone type:[" + type + "]"; } } public static String getNetworkTypeStr(int type) { switch (type) { case TelephonyManager.NETWORK_TYPE_UNKNOWN: return "NETWORK_TYPE_UNKNOWN"; case TelephonyManager.NETWORK_TYPE_GPRS: return "NETWORK_TYPE_GPRS"; case TelephonyManager.NETWORK_TYPE_EDGE: return "NETWORK_TYPE_EDGE"; case TelephonyManager.NETWORK_TYPE_UMTS: return "NETWORK_TYPE_UMTS"; case TelephonyManager.NETWORK_TYPE_HSDPA: return "NETWORK_TYPE_HSDPA"; case TelephonyManager.NETWORK_TYPE_HSUPA: return "NETWORK_TYPE_HSUPA"; case TelephonyManager.NETWORK_TYPE_HSPA: return "NETWORK_TYPE_HSPA"; case TelephonyManager.NETWORK_TYPE_CDMA: return "NETWORK_TYPE_CDMA"; case TelephonyManager.NETWORK_TYPE_EVDO_0: return "NETWORK_TYPE_EVDO_0"; case TelephonyManager.NETWORK_TYPE_EVDO_A: return "NETWORK_TYPE_EVDO_A"; case TelephonyManager.NETWORK_TYPE_1xRTT: return "NETWORK_TYPE_1xRTT"; default: return "unknow network type:[" + type + "]"; } } public static final String[] SYS_PROP = { "os.name", "os.version", "os.arch", "user.name", "user.home", "user.dir", "user.timezone", "java.home", "java.version", "java.class.version", "java.vendor", "java.vendor.url", "java.class.path", "path.separator", "line.separator", "file.separator", }; }// END OF CLASS MainActivity
获取手机的参数,展示,并保存到sdcard中的代码。
在.h中实现代码:
@interface ShowTextfieldUnderKeyboardViewController : UIViewController <UITextViewDelegate>{
IBOutlet UITextView *myTextView;
IBOutlet UIScrollView *myScrollView;
}
@property(nonatomic,retain) UITextView *myTextView;
@property(nonatomic,retain) UIScrollView *myScrollView;
-(IBAction)Click;
@end
注意添加<UITextViewDelegate>协议。
在.m中实现代码:
#import “ShowTextfieldUnderKeyboardViewController.h”
@implementation ShowTextfieldUnderKeyboardViewController
@synthesize myTextView,myScrollView;
- (void)viewDidLoad {
[self.myScrollView setFrame:CGRectMake(0, 0, 320, 480)];
[myScrollView setContentSize:CGSizeMake(320, 481)];
myTextView.text = @”Please input:”;
myTextView.delegate = self;
}
-(void)Click{
[myTextView resignFirstResponder];
}
-(void)textViewDidBeginEditing:(UITextView *)textView
{
[UIView beginAnimations:@"showKeyboardAnimation" context:nil];
[UIView setAnimationDuration:0.30];
self.view.frame = CGRectMake(self.view.frame.origin.x,
self.view.frame.origin.y- 100, self.view.frame.size.width,
self.view.frame.size.height);
[UIView commitAnimations];
}
- (void)textViewDidChange:(UITextView *)textView{
}
- (void)textViewDidEndEditing:(UITextView *)textView{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30];
CGRect rect = self.view.frame;
rect.origin.y += 100;
self.view.frame = rect;
[UIView commitAnimations];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[myTextView release];
[super dealloc];
}
@end
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// messageLabel.text =@"Touches Began";
// [self updateLabelsFromTouches:touches];
NSUInteger numTouches = [touches count];
NSUInteger numTags = [[touches anyObject] tapCount];
}
numTags 获取轻击次数 .
touches 的个数表示当前按压屏幕的手指数量.