Click here to Skip to main content
15,935,728 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Class code
C#
package com.example.vetriselvanv.myapplication;
/**
 * Created by vetriselvan.v on 5/16/2015.
 */
public class DeviceDetails extends MainActivity {

    private String PhoneNumber;
    private String IMEI;
    private String BatteryLevel;


    public String getPhoneNumber() {
        return PhoneNumber;
    }
    public void setPhoneNumber(String aPhoneNumber) {
        PhoneNumber =aPhoneNumber ;
    }
    public String getIMEI() {

        return IMEI;
    }
    public void setIMEI(String aIMEI) {
        IMEI=aIMEI;
    }
    public String getBatteryLevel()
    {
        return  BatteryLevel;
    }
    public void setBatteryLevel(String aBatteryLevel)
    {
        BatteryLevel =aBatteryLevel;
    }

}


Main Activity
package com.example.vetriselvanv.myapplication;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.telephony.TelephonyManager;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity {
String string,mPhoneNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DeviceDetails device=(DeviceDetails)getApplicationContext();//here
device.setIMEI(string);
device.setBatteryLevel(mPhoneNumber);
final String IMEI=device.getIMEI();
final String Phone=device.getPhoneNumber();
Toast.makeText(getApplicationContext(),"Device ID"+IMEI+"\nMobile Number"+Phone, Toast.LENGTH_LONG).show();
Intent i = new Intent(getBaseContext(), DeviceDetails.class);
startActivity(i);
Vetri();
Toast();
}
public void Vetri()
{

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
string = tm.getDeviceId();
mPhoneNumber = tm.getLine1Number();
EditText et=(EditText)findViewById(R.id.editText);
EditText ett=(EditText)findViewById(R.id.editText2);
ett.setText(mPhoneNumber);
et.setText(string);



}
Manifest code

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
package="com.example.vetriselvanv.myapplication" >

<application>
android:name="com.example.vetriselvanv.myapplication.DeviceDetails"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity>
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN">

<category android:name="android.intent.category.LAUNCHER">


<activity android:name=".DeviceDetails">


Posted
Updated 15-May-15 23:21pm
v2
Comments
Richard MacCutchan 16-May-15 4:34am    
Where?

1 solution

getApplicationContext[^] returns the context of the single, global Application object of the current process. You cannot randomly cast that to a different class type.
 
Share this answer
 
Comments
Member 11420908 16-May-15 5:57am    
How can i solve this problem
Richard MacCutchan 16-May-15 6:26am    
What problem? You cannot use random casts in this way, I suggest you go back to your Java reference and study their usage.
Member 11420908 16-May-15 6:43am    
okay thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900