I went through many pages, but couldn't understand properly how to declare a class to contain global variables and its declaration in manifest file (most important thing, need some extra concentration on that)
The class
global file
/**
*
*/
package com.furniture;
/**
* @author sanketh
*
*/
public class Gloabal extends ap{
public String refer="";
public int set=0;
public String getData(){
return this.refer;
}
public void setData(String d,int i){
this.refer=d;
set=i;
}
}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.furniture"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".Gloabal">
<activity
android:name="com.furniture.login"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"></activity>
<activity android:name=".passforgot"></activity>
<activity android:name=".newuser"></activity>
<activity android:name=".settings"></activity>
<receiver android:name=".smsreciever">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
</manifest>
somefile
package com.furniture;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class smsreciever extends BroadcastReceiver
{
public String value;
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
//---display the new SMS message---
// Intent i1=new Intent();
//((Gloabal)this.get).setData(str);
// Gloabal g1=new Gloabal();
Global g = (Global)getApplication();
int data=g.getData();
Log.v("sanketh","smsreciver value of str:"+str);
int a=1;
g1.setData(str,a);
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}
}
Here i want to set the data to it...
Global g = (Global)getApplication(); // this line gives error for get application