Android 点击通知栏跳转到应用程序


        NotificationManager manager = (NotificationManager) s_pContext.getSystemService(Context.NOTIFICATION_SERVICE); 
 
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setClass(s_pContext, CrossAppActivity.class);
        intent.setPackage("com.tencent.mobileqq");
        intent.setAction(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        
        ComponentName name = new ComponentName(s_pContext.getPackageName(), s_pContext.getPackageName()+"."+s_pContext.getLocalClassName());
        intent.setComponent(name);


        PendingIntent pendingIntent = PendingIntent.getActivity(CrossAppActivity.getContext(),0,intent,0);
        
        Notification notification = new Notification.Builder(s_pContext)    
        .setAutoCancel(true)  
        .setSmallIcon(0x7f020000)
        .setTicker(title)
        .setContentTitle(title)    
        .setContentText(content)       
        .setContentIntent(pendingIntent)
        .setWhen(System.currentTimeMillis())
        .setOngoing(false)
        .build();   
        
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.defaults = Notification.DEFAULT_SOUND;
        
    
        manager.notify(0, notification);

你可能感兴趣的:(android开发)