0

この問題が単にエミュレーターに関係していることを願っています。基本的に、タイマーを設定するサービスを取得しました。タイマータスクが実行されるとすぐに、次のコードが実行されるはずです。

        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

だから私の質問は2つあります: - 何が起こっているのですか? - 修正方法に関するアイデア、または新しい形式の通知を見つける価値があるかどうか

編集:申し訳ありませんが、通知ウィンドウを下にドラッグする必要があることが問題であることがわかりました-私はめったにAndroid xを使用しません)

4

1 に答える 1

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>

通知タップで何らかの意図を呼び出す保留中の意図..gve ans frm whtevrコードに問題がある場合は、あなたのクエストがコメントを残すことを理解しています...

于 2012-04-22T14:12:41.067 に答える