2

I have an BroadcastReciver that listens for incoming sms. When sms come, it shows notification. I want, when user open notification, it's go to result activity, and it's open google map via intent. I think I wrote everything ok, but it doesn't work. When the notification is clicked, it opens a blank page.

My incomingSms BroadcastReciver :

public void ShowNotif(String from , String body , Context con){

    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(con)
                    .setSmallIcon(R.drawable.ic_search)
                    .setContentTitle(from)
                    .setContentText(body);
    int NOTIFICATION_ID = 12345;

    Intent targetIntent = new Intent(con,Resualt.class );
    targetIntent.putExtra("loc",body);
    PendingIntent contentIntent = PendingIntent.getActivity(con, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);
    NotificationManager nManager = (NotificationManager) con.getSystemService(Context.NOTIFICATION_SERVICE);
    nManager.notify(NOTIFICATION_ID, builder.build());
    Intent goResIntent = new Intent(con , Resualt.class);
    con.startActivity(goResIntent);


    // gogole map intent :


}

and Resualt acitivty :

public class Resualt extends Activity {
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
    super.onCreate(savedInstanceState, persistentState);
    setContentView(R.layout.resualt);
     double Mylatitude = 12;
     double Mylongitude = 11;
    GPSTracker tracker = new GPSTracker(this);
    if (tracker.canGetLocation()) {
        Mylatitude = tracker.getLatitude();
        Mylongitude = tracker.getLongitude();
    }
    Intent intent = getIntent();
    String location = intent.getStringExtra("loc");
    String ACC_lat = location.substring(0, location.indexOf(","));
    String ACC_lang = location.substring(location.indexOf(",") + 1, location.length());
    Toast.makeText(this, ACC_lang + " ^ " + ACC_lat, Toast.LENGTH_LONG).show();
    Intent mapIntent = new Intent(android.content.Intent.ACTION_VIEW,
            Uri.parse("http://maps.google.com/maps?saddr="+Mylatitude +","+ Mylongitude+"&daddr="+ACC_lat+","+ACC_lang));
    startActivity(mapIntent);
  // this.finish();
}

thanks for any help .

Michael Spitsin
  • 2,539
  • 2
  • 19
  • 29
amir
  • 2,443
  • 3
  • 22
  • 49

1 Answers1

0

You can open a single blank activity through pending intent in notification service and then on that blank activity open a map intent and finish that blank activity. the link receiving from notification data can be sent through intent as extras

Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("location_link", link);
Md.Sukel Ali
  • 2,987
  • 5
  • 22
  • 34
Ahsan Ch
  • 1
  • 1