Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
旧android版本的进度通知_Android_Android Notifications - Fatal编程技术网

旧android版本的进度通知

旧android版本的进度通知,android,android-notifications,Android,Android Notifications,我尝试创建一个进度通知,如。这是我的密码: NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Builder mBuilder = new NotificationCompat.Builder(MyActivity.this); mBuilder.setContentTitle(getString(R.string.

我尝试创建一个进度通知,如。这是我的密码:

 NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Builder mBuilder = new NotificationCompat.Builder(MyActivity.this);
    mBuilder.setContentTitle(getString(R.string.download_title))
    .setContentText(getString(R.string.downloading))
    .setSmallIcon(R.drawable.ic_notify);

    Intent resultIntent = new Intent(this, MyActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MyActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
通知工作得很好,但是当我想要更新进度时,没有发生任何事情,它只显示通知文本

public void onRequestProgressUpdate(RequestProgress progress) {             
    mBuilder.setProgress(size, (int)(progress.getProgress() / size), false);
    mNotifyManager.notify(Constants.NOTIFICATION_ID, mBuilder.build());
}

我的应用程序使用android支持库android-support-v4.jar,并将最小Sdk版本设置为api 7。我想从api级别7显示所有android版本的进度通知。它只适用于新版本吗?是否必须为通知创建自定义视图?

必须使用NotificationCompat而不是notification类。试着这样做:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

builder.setContentIntent(pendInt)
  .setSmallIcon(R.drawable.ic_someicon)
  .setTicker("some title")
  .setOngoing(true)
  .setContentTitle("some content description title")
  .setContentText("some content description description");
Notification not = builder.build();

startForeground(NOTIFY_ID, not);

@Yume117他正在使用NotificationCompat。。。但正如不提供扩展通知的doc On platform版本中所述,依赖于扩展通知的方法无效。。。所以R4j,是的,您必须使用自定义视图。我的坏../无论如何,回答得不错Selvin@Selvin好的,我知道了。你能用定制通知的示例或教程链接回答我的问题,然后我可以接受吗?