Android 我在应用程序上设置的闹钟没有';在实际设备上不工作,声音也不';不要在模拟器上玩
我在我的应用程序中设置了一个闹钟,每天下午6点响,我在模拟器上运行它,它工作了,但不是实时的,而且我设置的声音也没有播放。所以我想看看它在实际手机上是如何工作的。我把它下载到一个实际的设备(API 15)上,设置警报的时间到了,什么也没发生?我知道我的代码是正确的,因为它可以在模拟器上运行,但为什么它不能在我的设备上运行呢?有人能在他们自己的设备上测试这个功能吗?求你了 这是我的MyReceiver.java文件Android 我在应用程序上设置的闹钟没有';在实际设备上不工作,声音也不';不要在模拟器上玩,android,broadcastreceiver,alarmmanager,android-pendingintent,repeatingalarm,Android,Broadcastreceiver,Alarmmanager,Android Pendingintent,Repeatingalarm,我在我的应用程序中设置了一个闹钟,每天下午6点响,我在模拟器上运行它,它工作了,但不是实时的,而且我设置的声音也没有播放。所以我想看看它在实际手机上是如何工作的。我把它下载到一个实际的设备(API 15)上,设置警报的时间到了,什么也没发生?我知道我的代码是正确的,因为它可以在模拟器上运行,但为什么它不能在我的设备上运行呢?有人能在他们自己的设备上测试这个功能吗?求你了 这是我的MyReceiver.java文件 import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Intent service1 = new Intent(context, Alarm.class);
context.startService(service1);
}
}
import android.app.Activity;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import java.util.Calendar;
public class Alarm extends Service {
NotificationManager nm;
Notification notify;
CharSequence from="Almost here!";
CharSequence message="Check out when!";
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
from="Almost here!";
message="Check out when!";
Uri path=Uri.parse("com.example.kn.b" + R.raw.bl);
Intent intent1=new Intent(Alarm.this,NotificationPage.class);
PendingIntent pendingIntent=PendingIntent.getActivity(Alarm.this,1,intent1,0);
Notification.Builder builder=new Notification.Builder(Alarm.this);
builder.setAutoCancel(false);
builder.setContentTitle(from);
builder.setContentText(message);
builder.setSmallIcon(R.drawable.ft);
builder.setContentIntent(pendingIntent);
builder.setSound(path);
builder.build();
nm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notify=builder.getNotification();
notify.flags=Notification.FLAG_AUTO_CANCEL;
nm.notify(0, notify);
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
这是我的Alarm.java文件
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Intent service1 = new Intent(context, Alarm.class);
context.startService(service1);
}
}
import android.app.Activity;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import java.util.Calendar;
public class Alarm extends Service {
NotificationManager nm;
Notification notify;
CharSequence from="Almost here!";
CharSequence message="Check out when!";
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
from="Almost here!";
message="Check out when!";
Uri path=Uri.parse("com.example.kn.b" + R.raw.bl);
Intent intent1=new Intent(Alarm.this,NotificationPage.class);
PendingIntent pendingIntent=PendingIntent.getActivity(Alarm.this,1,intent1,0);
Notification.Builder builder=new Notification.Builder(Alarm.this);
builder.setAutoCancel(false);
builder.setContentTitle(from);
builder.setContentText(message);
builder.setSmallIcon(R.drawable.ft);
builder.setContentIntent(pendingIntent);
builder.setSound(path);
builder.build();
nm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notify=builder.getNotification();
notify.flags=Notification.FLAG_AUTO_CANCEL;
nm.notify(0, notify);
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
这是我放在Main.java中设置报警时间的代码片段
today.set(Calendar.HOUR_OF_DAY, 18);
today.set(Calendar.MINUTE, 00);
today.set(Calendar.SECOND, 0);
Intent myIntent=new Intent(Main.this, MyReceiver.class);
PendingIntent pendingIntent=PendingIntent.getBroadcast(Main.this,0,myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,today.getTimeInMillis(),24*60*60*1000,pendingIntent);
如果您有任何帮助,我们将不胜感激 这真的有效吗?uripath=Uri.parse(“com.example.kn.b”+R.raw.bl);这怎么会是一个有效的URI?另外,请具体说明哪些有效,哪些无效。您的帖子对设备/模拟器之间的区别非常含糊不清。是的,确实如此。我看到了一个解析原始文件夹路径的示例,这就是我所做的。另外,我说警报在我的模拟器上工作,但不是实时的,但声音没有播放。然而,当我在一台真正的android设备上试用该应用程序时,时间来了又过去了,而闹钟什么也没响。抱歉搞混了。这真的有效吗?uripath=Uri.parse(“com.example.kn.b”+R.raw.bl);这怎么会是一个有效的URI?另外,请具体说明哪些有效,哪些无效。您的帖子对设备/模拟器之间的区别非常含糊不清。是的,确实如此。我看到了一个解析原始文件夹路径的示例,这就是我所做的。另外,我说警报在我的模拟器上工作,但不是实时的,但声音没有播放。然而,当我在一台真正的android设备上试用该应用程序时,时间来了又过去了,而闹钟什么也没响。很抱歉给你带来了困惑。