2011-12-16 14 views
0

通知を確認するサービスを起動するアプリを開発しています。クリックしてアンドロイドでアクティビティを表示する方法を隠す方法

public class ServiceNotification extends Service{ 
private ThreadNotification notifica; 
private NotificationManager mManager; 
private String id; 
@Override 
public void onCreate() { 
    super.onCreate(); 
    SharedPreferences settings = getSharedPreferences("setting", 0); 
    String id = settings.getString("id", "no"); 
    this.id=id; 
    mManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    //notifica = new ThreadNotification(id,getApplicationContext(),getBaseContext()); 
} 
private void showNotification(int id, String client, String notifica) { 
    Notification notification = new Notification(R.drawable.icon, "Notifica da "+client, 10000); 
    CharSequence contentTitle = "Notifica da "+client; 
    CharSequence contentText = notifica; 
    Intent notificationIntent = new Intent(); 
    notificationIntent.setClassName("package", "package.ActivityNotification"); 
    notificationIntent.putExtra("title",title); 
    notificationIntent.putExtra("notification",notification); 
    PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent,Notification.FLAG_AUTO_CANCEL); 
    notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent); 
    mManager.notify(id, notification); 
} 
@Override 
public void onStart(Intent intent, int startId) { 
    Thread t = new Thread(new Runnable(){ 
     public void run(){ 
      int i =0; 
      while(true){ 
       String page = "http://mysite.com/notification.php?"+id; 
       String risposta = ""; 
       try { 
        URL url = new URL(page); 
        URLConnection connection = url.openConnection(); 
        BufferedReader in = new BufferedReader(
          new InputStreamReader(
            connection.getInputStream())); 
        risposta = in.readLine(); 
        in.close(); 
         String[] all = risposta.split("@@@"); 
         String notification = all[0]; 
         String title = all[1]; 
         showNotification(i++, title, notification); 
       } catch (MalformedURLException e) { 
        e.printStackTrace(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       }finally{ 
        try { 
         Thread.sleep(20000); 
        } catch (InterruptedException e) { 
         e.printStackTrace(); 
        } 
       } 

      } 
     } 
    }); 
    t.start(); 
} 
@Override 
public void onDestroy() { 
} 

@Override 
public IBinder onBind(Intent intent) { 
    return null; 
} 

} 

と、この通知がクリックされたときに、私はロードしたい活動が

public class ActivityNotification extends Activity{ 
private String title,notification; 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //this.c=this; 
    title = getIntent().getStringExtra("title"); 
    notification = getIntent().getStringExtra("notification"); 
    final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
    alertDialog.setTitle("Notifica da "+title); 
    alertDialog.setMessage(notification); 
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      alertDialog.cancel(); 
     } 
    }); 
    alertDialog.setIcon(R.drawable.errore_icon); 
    alertDialog.show(); 
} 

}

通知が示されているが、私は何も起こりません通知をクリックするとされます。通知は残っており、アクティビティは読み込まれません。私に何ができる?私を助けることができますpls?

EDIT:

notification.flags |=Notification.FLAG_AUTO_CANCEL; 

通知を使用するには、クリック時に隠してされますが、活動は今も示されています!

+1

あなたは 'notificationIntent.setClassName(" packageName "、" ActivityNotification ");'を試しましたか? – futtetennista

+0

しかし、方法はありません。 – JackTurky

+0

うん、実際にあなたの意図で起動するクラスを渡すことはないようです。それを加えて、すべてうまくいくはずです。 – AedonEtLIRA

答えて

0

解決済み!私の責任です。私は私のマニフェストに私の活動を追加するのを忘れました。

関連する問題