DVa*_*lev 3 notifications android android-intent android-notifications
我现在有一个定期通知,跟踪下载(歌曲)的进度.一旦下载完成后,我想,这样如果用户按下通知它开辟了中,将处理该文件类型的默认应用程序中的歌曲文件,使之.
我试图寻找,但使用.setDataAndType()当我不确定要如何使用的PendingIntent和MIME类型的工作.有人可以解释或提供一些示例代码,以便我如何设置从默认应用程序中的特定文件路径打开文件的意图?
谢谢你,丹尼尔
Lib*_*bin 14
使用待定意图创建这样的通知以打开默认音频播放器
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("YOUR_SONG_URI"); // set your audio path
intent.setDataAndType(Uri.fromFile(file), "audio/*");
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new NotificationCompat.Builder(this)
.setContentTitle("Download completed")
.setContentText("Song name")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent).build();
noti.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6206 次 |
| 最近记录: |