0

in my emulator my program is success to install but going to stop processing when i send sms to trigger the program from another emulator, running gps program and send the location back to another emulator that send the sms trigger here is the code plz help me..

package feliks.skripsi;

import android.app.PendingIntent;
import android.os.Bundle;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.Criteria;

import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;

public class SmsIntentReceiver extends BroadcastReceiver {
    /** Called when the activity is first created. */
    double lat, lon;

    Context context;

        public void triggerApp (Context context){
        Intent broadcast = new Intent ("feliks.skripsi.WAKE_UP");
        broadcast.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity (new Intent(broadcast));
    }


    public void getLocation(){
        //Location loc;

        //LocationProvider locPro;
        //List<LocationProvider> proList;

        //setContentView(R.layout);

        LocationManager lm;


    lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setAccuracy (Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);

    String provider = lm.getBestProvider(criteria, true);

    Location location = lm.getLastKnownLocation(provider);

    updateWithNewLocation(location);

    lm.requestLocationUpdates(provider, 2000, 20, locationListener);    
    }

private final LocationListener locationListener = new LocationListener(){   
    public void onLocationChanged (Location location){
        updateWithNewLocation(location);
    }

    private void updateWithNewLocation(Location location) {
        // TODO Auto-generated method stub

    }

    public void onProviderDisabled (String provider){
        updateWithNewLocation(null);
    }

    public void onProviderEnabled (String provider) {

    }
    public void onStatusChanged (String provider, int status, Bundle extras){

    }

};

private void updateWithNewLocation(Location location) {
    // TODO Auto-generated method stub
    if (location != null){
        lat = location.getLatitude();
        lon = location.getLongitude();
    }

}

private void sendGPSData (Context context, Intent intent, SmsMessage inMessage){

    String sendData = "Loc: lat: "+lat+"long: "+lon;
    SmsManager mng = SmsManager.getDefault();
    PendingIntent dummyEvent = PendingIntent.getBroadcast(context, 0, new Intent("feliks.skripsi.IGNORE_ME"), 0);

    String addr = inMessage.getOriginatingAddress();
    if (addr ==null)

    {Log.i("SmsIntent", "Unable to receive Phone Number from Sent message");}

    try{
        mng.sendTextMessage(addr, null, sendData, dummyEvent, dummyEvent);
    }catch(Exception e){
        Log.e("SmsIntent", "SendException", e);
    }

}

private SmsMessage[] getMessagesFromIntent (Intent intent){

    SmsMessage retMsgs[] = null;
    Bundle bdl = intent.getExtras();
    try{
        Object[] pdus = (Object[]) bdl.get("pdus");
        retMsgs = new SmsMessage[pdus.length];
        for (int n=0; n <pdus.length; n++)
        {
            byte[] byteData = (byte[])pdus[n];
            retMsgs[n] = SmsMessage.createFromPdu(byteData);
    }
}catch (Exception e)
{
    Log.e("GetMessages", "fail", e);
}
return retMsgs;
}

@Override
public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        if (!intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
        {
            return;
        }
        SmsMessage msg[] = getMessagesFromIntent (intent);
        for (int i=0; i<msg.length; i++)
        {
            String message = msg[i].getDisplayMessageBody();
            if(message != null && message.length() >0)
            {
                Log.i("MessageListner:", message);
                //trigger message
                if (message.startsWith("SMSTrigger: Start Aplikasi "))
                {
                    triggerApp(context);
                }
                else if (message.startsWith("LBSLocatorOn"))
                {
                    getLocation();
                    sendGPSData(context, intent,msg[i]);
                }

            }
        }
    }
}

android manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="feliks.skripsi"
      android:versionCode="1"
      android:versionName="1.0">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.BROADCAST_SMS"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_SMS"></uses-permission>


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Screen"

                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="feliks.skripsi.WAKE_UP"/>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <uses-library android:name="com.google.android.maps"></uses-library>


<receiver android:name=".SmsIntentReceiver"
            android:enabled="true">
            <intent-filter>
                <action
                    android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
    </receiver>




    </application>
</manifest>

this is the new error log

01-20 20:22:48.920: ERROR/ActivityManager(71): ANR in com.android.email
01-20 20:22:48.920: ERROR/ActivityManager(71): Reason: Broadcast of Intent { act=android.intent.action.BOOT_COMPLETED cmp=com.android.email/com.android.exchange.BootReceiver }
01-20 20:22:48.920: ERROR/ActivityManager(71): Load: 5.87 / 3.05 / 1.24
01-20 20:22:48.920: ERROR/ActivityManager(71): CPU usage from 82276ms to 268ms ago:
01-20 20:22:48.920: ERROR/ActivityManager(71):   system_server: 11% = 6% user + 4% kernel / faults: 2398 minor 16 major
01-20 20:22:48.920: ERROR/ActivityManager(71):   ndroid.launcher: 4% = 2% user + 1% kernel / faults: 3311 minor 20 major
01-20 20:22:48.920: ERROR/ActivityManager(71):   m.android.phone: 3% = 2% user + 1% kernel / faults: 826 minor 1 major
01-20 20:22:48.920: ERROR/ActivityManager(71):   zygote: 2% = 1% user + 0% kernel / faults: 1837 minor 16 major
01-20 20:22:48.920: ERROR/ActivityManager(71):   adbd: 0% = 0% user + 0% kernel / faults: 2 minor
01-20 20:22:48.920: ERROR/ActivityManager(71):   kswapd0: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71):   putmethod.latin: 0% = 0% user + 0% kernel / faults: 358 minor
01-20 20:22:48.920: ERROR/ActivityManager(71):   qemud: 0% = 0% user + 0% kernel / faults: 6 minor
01-20 20:22:48.920: ERROR/ActivityManager(71):   zygote: 0% = 0% user + 0% kernel / faults: 300 minor
01-20 20:22:48.920: ERROR/ActivityManager(71):   pdflush: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71):   installd: 0% = 0% user + 0% kernel / faults: 52 minor
01-20 20:22:48.920: ERROR/ActivityManager(71):   events/0: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71):   rild: 0% = 0% user + 0% kernel / faults: 35 minor
01-20 20:22:48.920: ERROR/ActivityManager(71):   netd: 0% = 0% user + 0% kernel / faults: 4 minor
01-20 20:22:48.920: ERROR/ActivityManager(71):  +roid.alarmclock: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71):  +com.android.mms: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71):  +d.process.media: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71):  +s:FriendService: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71):  +e.process.gapps: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71):  +m.android.email: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71):  +e.process.gapps: 0% = 0% user + 0% kernel
01-20 20:22:48.920: ERROR/ActivityManager(71): TOTAL: 100% = 70% user + 28% kernel + 0% iowait + 0% irq + 0% softirq
  • Hi Alexander, welcome to Stack Overflow! Please specify your problem more clearly. "Stop processing" can mean anything. Are there any exceptions? And what exactly are you trying to achieve? Why do you need 2 emulators? – THelper Jan 16 '12 at 12:31
  • thank you for the response, i want to make an application that can send gps location from emulator to another emulator using sms but it stop working when i send the sms for requesting gps location. for example emulator 5556 is requesting gps location from emulator 5554 (where the app installed) but when i debug the program nothing is wrong, what im missing? – Alexander Feliks Jan 16 '12 at 14:28
  • Ok, and "stop working" means the app is still running, but nothing happens? Or does the app shut itself down? Are you sure the 2nd emulator is receiving the sms? – THelper Jan 16 '12 at 14:35
  • yes the app is still running, but when the emulator receiving sms from another emulator there a pop up message that show the app process is stop working. after that message i repeat the same sms but had same respon. and iam sure the 2nd emulator is receiving the sms because it show sms notification on emulator screen. – Alexander Feliks Jan 16 '12 at 15:16
  • The pop-up message that "the app process is stop working" is most likely due to an error occuring in your application. Please check your log for errors and add the stacktrace of the error to your question. If you are using Eclipse you can find it in the logcat window, else check [this post on how to get the log](http://stackoverflow.com/q/2882253/741249). – THelper Jan 16 '12 at 15:20
  • 1
    I'd like to see your manifest.xml – Reno Jan 17 '12 at 12:58

1 Answers1

0

The stacktrace you've posted says that Android is looking for a class called feliks.skripsi.SmsIntentReceiver but it can't find it. This class is probably defined in your manifest.xml file as a receiver. Check if your app has a class with this exact name.

EDIT: the new error you got is an Application Not Responding (ANR). Android requires broadcast receivers to do all processing within 10 seconds. If the receiver's onReceive() method takes longer than that to complete then the process will be killed by Android. Make sure you do all processing that may take a while (e.g. networking operations) in a separate thread or service. More information on how to solve ANRs can be found here and here

Community
  • 1
  • 1
THelper
  • 15,333
  • 6
  • 64
  • 104
  • i have check the class name that defined in manifest.xml was redefined again to be class LBS for the receiver but it has same error again only this time not SmsIntentReceiver but LBS – Alexander Feliks Jan 20 '12 at 13:50
  • i have added few thing in my script and change the LBS class too, after rebuilding the app the process still working on first trigger but stop working in 2nd trigger – Alexander Feliks Jan 20 '12 at 14:32