Javascript 在后台播放音频的警报不规则?
我用过AlarmManager,所以它每分钟都工作 每一分钟,服务类都会被调用 即使关机,它仍能继续工作 设备后面有声音 当我在设备5.1.1上的Android Studio中运行应用程序时,这个想法就起作用了 但我注意到,当我断开设备与电缆的连接时。 警报是不规则的,音频工作正常 其他时间Javascript 在后台播放音频的警报不规则?,javascript,android,Javascript,Android,我用过AlarmManager,所以它每分钟都工作 每一分钟,服务类都会被调用 即使关机,它仍能继续工作 设备后面有声音 当我在设备5.1.1上的Android Studio中运行应用程序时,这个想法就起作用了 但我注意到,当我断开设备与电缆的连接时。 警报是不规则的,音频工作正常 其他时间 // public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bun
//
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(getApplicationContext(), RingAlarm.class);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(),
12345, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(),
1 * 60 * 100 , pendingIntent);
}
}
// ---
public class RingAlarm extends Service {
MediaPlayer sound2;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(getApplicationContext(), "الحمد لله", Toast.LENGTH_LONG).show();
sound2 = (MediaPlayer) MediaPlayer.create(RingAlarm.this,R.raw.a2);
sound2.start();
return START_STICKY;
}
@Override
public IBinder onBind(Intent arg0){
// TODO Auto-generated method stub
return null;
}
}
//
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ahmedco.testcode">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".RingAlarm" />
</application>
</manifest>
//
公共类MainActivity扩展了AppCompatActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent Intent=新的Intent(getApplicationContext(),RingAlarm.class);
PendingEvent PendingEvent=PendingEvent.getService(getApplicationContext(),
12345,意向,待定内容。标志(更新(当前);
AlarmManager am=(AlarmManager)getSystemService(Activity.ALARM\u服务);
am.setInexactRepeating(AlarmManager.RTC_唤醒,SystemClock.elapsedRealtime(),
1*60*100,悬挂式);
}
}
// ---
公共类RingAlarm扩展服务{
MediaPlayer sound2;
@凌驾
公共int onStartCommand(Intent Intent、int标志、int startId){
Toast.makeText(getApplicationContext(),“Toast.LENGTH”show();
sound2=(MediaPlayer)MediaPlayer.create(RingAlarm.this,R.raw.a2);
sound2.start();
返回开始时间;
}
@凌驾
公共IBinder onBind(意图arg0){
//TODO自动生成的方法存根
返回null;
}
}
//
您的服务是否继续运行?您是如何停止报警的?您可以显示代码吗?这是Log.e,在我删除电缆后:01-02 11:43:07.762 26397-26397/?E/memtrack:无法加载memtrack模块(没有这样的文件或目录)01-02 11:43:07.762 26397-26397/?E/android.os.Debug:未能加载memtrack模块:-2 01-02 11:43:07.822 741-790/?E/InputDispatcher:通道“10c7ca1a com.ahmedco.testcode/com.ahmedco.testcode.MainActivity(服务器)”~通道已不可恢复地断开,将被处置!01-02 11:43:08.383 855-855/? E/LSO:LSO服务尚未就绪!!!太:01-02 11:43:31.735741-991/?E/看门狗:@同步471[01-02 11:43:31.742]01-02 11:43:43.627 24180-24180/?E/MtpServerJNI:send_object_removed 01-02 11:44:01.735 741-991/中的服务器为空?E/看门狗:@同步472[01-02 11:44:01.743]01-02 11:44:31.734 741-991/?E/看门狗:@同步473[01-02 11:44:31.744]