в моем эмуляторе моя программа успешно установлена, но остановится, когда я отправлю смс для запуска программы из другого эмулятора, запустив программу gps и отправлю местоположение обратно в другой эмулятор, который отправит триггер смс
Вот код PLZ, помогите мне ..
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>
это новый журнал ошибок
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