2012-04-22 67 views
0

我希望这个问题只是与模拟器有关,基本上我得到一个服务,设置一个计时器,只要timertask运行下面的代码应该执行:Android状态栏通知不加载

 String ns = Context.NOTIFICATION_SERVICE; 
     NotificationManager mNotificationManager = (NotificationManager)getSystemService(ns); 

     int icon = R.drawable.androidapplogo; 
     CharSequence tickerText = "Ticker Text"; 
     long when = System.currentTimeMillis(); 

     Notification notification = new Notification(icon, tickerText, when); 
     Context context = getApplicationContext(); 
     CharSequence contentTitle = "My Notification"; 
     CharSequence contentText = "Hello World!";   

     //Do i need this? 
     Intent notificationIntent = new Intent(); 
     PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, notificationIntent, 0);   

     notification.setLatestEventInfo(context, contentTitle, contentText, null); 
     mNotificationManager.notify(1, notification); 

我遇到的问题是,当通知被调用时,它会出现在状态栏中,但是当我点击图标时,它只是一个蓝色圆圈。我没有自己的android手机,所以即时猜测,这意味着它试图加载的东西。

顺便说一句,我已经几乎取消了代码从这里:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

所以我的问题是双重的: - 这是怎么回事,难道是无法加载的东西吗? - 有关如何解决它的任何想法,或者是否值得寻找新的通知形式

编辑:我很抱歉家伙,发现问题是,你需要拖下通知窗口 - 我很少使用android x )

回答

0
package com.androidtest.notification; 

import android.app.Activity; 
import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class SimpleNotification extends Activity { 

    private NotificationManager mNotificationManager; 
    private int SIMPLE_NOTFICATION_ID; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     final Notification notifyDetails = new Notification(R.drawable.android, 
       "New Alert, Click Me!", System.currentTimeMillis()); 

     Button start = (Button) findViewById(R.id.notifyButton); 
     Button cancel = (Button) findViewById(R.id.cancelButton); 

     start.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 

       Context context = getApplicationContext(); 
       CharSequence contentTitle = "TITLES...."; 
       CharSequence contentText = "TEXT FOR DETAIL"; 
       Intent notifyIntent = new Intent(
         android.content.Intent.ACTION_VIEW, Uri 
           .parse("CONTACT NO/OR ANY OTHER ACTION WHICH YOU WANT ON NOTIfic. ICON TAP")); 
       PendingIntent intent = PendingIntent.getActivity(
         SimpleNotification.this, 0, notifyIntent, 
         android.content.Intent.FLAG_ACTIVITY_NEW_TASK); 

       notifyDetails.setLatestEventInfo(context, contentTitle, 
         contentText, intent); 
       mNotificationManager.notify(SIMPLE_NOTFICATION_ID, 
         notifyDetails); 
      } 
     }); 

     cancel.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 

       mNotificationManager.cancel(SIMPLE_NOTFICATION_ID); 
      } 
     }); 
    } 
} 


XML文件测试

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <Button 
     android:id="@+id/notifyButton" 
     android:text="@string/notify" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
    ></Button> 
    <Button 
     android:id="@+id/cancelButton" 
     android:text="@string/cancel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal"  
    ></Button> 
</LinearLayout> 

未决的意图致电通知一些意向性tap..gve ANS FRM whtevr我明白乌尔追求 休假COMM如果有任何问题与代码...