错误:
java.lang.ClassCastException: DataCountUtilities cannot be cast to android.app.Activity
笔记:
我已经在我的清单中声明了以下内容 - 但我感觉它可能会崩溃,因为它不是一个活动 - 我只需要它在我调用它后在后台运行 - 所以我不确定如果它应该被定义为一项服务 - 或者只是像我拥有的那样作为一个类。
<activity
android:name="com.tracfone.generic.clientprovisioninghandler.DataCountUtilities">
</activity>
资源:
public class DataCountUtilities {
//swap the content of a string by switching place
//each pair of consecutive characters
//If string length is odd last character is left in place
public String swappedMdn(Context ctx){
TelephonyManager tm = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
//Extract the phone number from the TelephonyManager instance
String mdn = tm.getLine1Number();
//Insure MDN is 10 characters
if (mdn.length() < 10 || mdn == null) mdn ="0000000000";
//Extract last 10 digits of MDN
if (mdn.length() > 10) mdn = mdn.substring(mdn.length() - 10, mdn.length());
char data[] = mdn.toCharArray();
char digit;
for (int index = 0; index < mdn.length() - (mdn.length())%2; index+=2){
digit = data[index];
data[index] = data[index+1];
data[index+1] = digit;
Intent i = new Intent(ctx, DataCountService.class);
i.putExtra("key", mdn);
startActivity(i);
}
return String.valueOf(data);
}
private void startActivity(Intent i) {
// TODO Auto-generated method stub
}}