我可以为apk添加闹钟声音或铃声吗? 我需要为我们开发的应用程序添加警报声。 谢谢!
答案 0 :(得分:0)
您需要执行的步骤:
添加要添加到res->原始文件夹中的歌曲。
然后在您的活动中写下:
Intent AlarmIntent = new Intent(getApplicationContext(), AlarmReceiver.class);
AlarmIntent.putExtra("Ringtone",
Uri.parse("getResources().getResourceName(R.raw.shankh_final_mid)"));
PendingIntent Sender = PendingIntent.getBroadcast(this, 0, AlarmIntent, 0);
AlarmManager AlmMgr = (AlarmManager)getSystemService(ALARM_SERVICE);
AlmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() +
(60 * 1000), (24 * 60 * 60 * 1000), Sender);
然后在你的接收器类中添加以下代码行:
public void onReceive(Context context, Intent intent) {
Intent in = new Intent(context, SnoozeEvent.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent Sender = PendingIntent.getActivity(context, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notification = new Notification(R.drawable.icon, "Wake up alarm", System.currentTimeMillis());
notification.setLatestEventInfo(context, "Hanuman Chalisa", "Wake Up...", Sender);
notification.flags = Notification.FLAG_INSISTENT;
notification.sound = Uri.parse("android.resource://my.package.name/raw/notification");
manager.notify(1, notification); }