解决方案 »
- 问个基础问题!
- [Android] OpenGL eglSwapBuffers failed: EGL_BAD_ALLOC?
- 求助:在代码中如何打开GPS
- android framework层的网络选择问题!!!!!
- PackageManager的Features设置问题
- 关于libgdx引擎的camera,用过libgdx的大神们进来帮帮忙
- listview下拉刷新,下拉的时候很卡,一钝一钝的
- wcf做服务器端时如何接收和处理android客户端base64编码过的图片?
- 左滑带出页面如何实现
- 自定义actionbar的问题
- 求助,为什么Fragment里Button点击事件没反应
- httpclient() post的奇葩问题!
//操作。。
return null;} }
public class SIMCardInfo { private TelephonyManager telephonyManager;
public SIMCardInfo(Context context) {
telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
} public String getNativePhoneNumber() {
String NativePhoneNumber = null;
try{
NativePhoneNumber = telephonyManager.getLine1Number();
}
catch (Exception e) {
e.printStackTrace();
}
return NativePhoneNumber;
}
}
主要是将Context context作为参数传进去,调用的时候如下调用即可:SIMCardInfo siminfo = new SIMCardInfo(MainActivity.this);
String phoneNum = siminfo.getNativePhoneNumber();
如果你上面那个类继承至Activity的话,会报错的.因为您一个类变量的构造函数需要激活系统服务,而这个类变量的实例化是直接在Activity类里面,而不是在OnCreate函数里面,需要放到OnCreate。
如果是banner类型广告比较简单,继承一下RelativeLayout什么的 public class BannerAdView extends RelativeLayout
然后通过addView把广告(一般是一个html页面放了一个banner,所以用webview)添加进去
WebView web = new CustomWebView(context);
LayoutParams params = getBannerLayoutParams();
addView(web, params);
web.loadUrl(adUrl);
// 顶层布局
mainLayout = new RelativeLayout(context);
RelativeLayout.LayoutParams mainParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
mainLayout.setBackgroundColor(0xffffffff);
// 将顶层布局添加至Activity
addContentView(mainLayout, mainParams); // 顶部显示进度条
mProgressBar = new ProgressBar(context, null,
android.R.attr.progressBarStyleHorizontal);
LinearLayout.LayoutParams progressBarParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT, UnitUtil.dip2px(context,
2));
mProgressBar.setMax(100);
mProgressBar.setMinimumHeight(UnitUtil.dip2px(context, 2));
mainLayout.addView(mProgressBar, progressBarParams); // 底部显示按钮
mBottomBarLayout = new LinearLayout(context);
RelativeLayout.LayoutParams bottomParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT, UnitUtil.dip2px(
context, 45));
bottomParams.alignWithParent = true;
bottomParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,
RelativeLayout.TRUE);
mBottomBarLayout.setBackgroundColor(0xffececec);
而图片什么的放到assets文件夹使用,如: try {
Bitmap bm = BitmapFactory.decodeStream(context.getAssets().open(
"a.png"));
mPreviousImg.setImageBitmap(bm);
} catch (IOException e) {
e.printStackTrace();
}