2017-04-11 7 views
0

に通知にURLを渡しビーコンが検出されたときに、この方法は、通知を作成します。私は、Android Studioで書かれた次のメソッドを持っているのAndriod

public void showNotification(Beacon beacon) { 

    Resources r = getResources(); 
    int random = (int) System.currentTimeMillis(); 
    Notification notification = new NotificationCompat.Builder(this) 
      .setSmallIcon(android.R.drawable.ic_popup_reminder) 
      .setContentTitle("You have reached area:") 
      .setContentText(retrieveLocation(beacon.get())) 
      .setPriority(Notification.PRIORITY_MAX) 
      .setVibrate(new long[0]) 
      .setAutoCancel(true) 
      .setLights(0xff00ff00, 300, 100) 
      .build(); 

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    notificationManager.notify(random, notification); 
    } 

を今、私は、この中にWebリンクを含めますお知らせ。私はオンラインでいくつかのリサーチを行い、コンテキストクラスを作成する必要があることを理解しています。しかし、私はこのメソッドにリンクをどのように渡すことができるかに関して、今でも本当に混乱しています。私は非常にjavaに新しいですので、どんな助けも大歓迎です。

答えて

0

receieverの終わりに通知意図

public void showNotification(Beacon beacon) { 
Bundle bundle = new Bundle(); 
bundle.putString("url", "www.google.com"); 
    Resources r = getResources(); 
    int random = (int) System.currentTimeMillis(); 
    Notification notification = new NotificationCompat.Builder(this) 
      .setSmallIcon(android.R.drawable.ic_popup_reminder) 
      .setContentTitle("You have reached area:") 
      .setContentText(retrieveLocation(beacon.get())) 
      .setPriority(Notification.PRIORITY_MAX) 
      .setVibrate(new long[0]) 
         .putExtras(bundle); 
      .setAutoCancel(true) 
      .setLights(0xff00ff00, 300, 100) 
      .build(); 

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    notificationManager.notify(random, notification); 
    } 

に文字列としてURLを送るには、文字列、あなたの活動でそれを読み込むようにそれを得ます。

String url = getArguments.getString("url"); 
Url myUrl = new Url(url); 
関連する問題