0

書き込もうとしているこの新しい通知のコードをいじっています。もっと簡単にできるように思えますが、何らかの理由で私に同意しません。それは私に何も与えていません。logcat がなく、エミュレーターに出力がありません。何もない。したがって、変更されたコードは次のとおりです。

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.os.Bundle;
import android.widget.RemoteViews;

public class kickStart extends Activity {
NotificationManager nm;
Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification();
    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.note);
    contentView.setImageViewResource(R.id.icon, R.drawable.ic_launcher);
    contentView.setTextViewText(R.id.title, "Custom notification");
    contentView.setTextViewText(R.id.text, "This is a custom layout");
    notification.contentView = contentView;
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.contentIntent = contentIntent;
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    nm.notify(R.id.layout, notification);
}
}

Logcatは私に何の情報も与えていません。インストールされていると言っているにもかかわらず、アプリが存在しないようです。

その他の有用な情報は次のとおりです。

[2012-07-22 12:57:21 - this1] Android Launch!
[2012-07-22 12:57:21 - this1] adb is running normally.
[2012-07-22 12:57:21 - this1] Performing com.example.this1.kickStart activity launch
[2012-07-22 12:57:21 - this1] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'test'
[2012-07-22 12:57:21 - this1] Uploading this1.apk onto device 'emulator-5554'
[2012-07-22 12:57:23 - this1] Installing this1.apk...
[2012-07-22 12:57:31 - this1] Success!
[2012-07-22 12:57:32 - this1] Starting activity com.example.this1.kickStart on device emulator-5554
[2012-07-22 12:57:33 - this1] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.this1/.kickStart }

そのため、実行できないランチャーを認識してインストールします...

4

1 に答える 1

1

アイコンと tickerText を通知に設定してみてください。

notification.icon = R.drawable.small_notification;
notification.tickerText = "Text that scrolls across the status bar";

さて、tickerText はオプションですが、アイコンは必須です。(ステータス バーに通知が表示されるとしたら、どのようにすればよいのでしょうか?)

通知のドキュメントから:

アイコン リソースが無効な通知は表示されません。

于 2012-07-22T17:17:12.730 に答える