API26以降の同じ通知をif-elseで書いており、Alarm_ReceiverとManifestがあります。 (私のレシーバーのAndroid名とインテントフィルターと私のサービスアンドロイドの名前)。 26未満の通知は正常に機能しますが、API 26とAPI 27ではアプリが開いているときにのみ機能し、アプリを終了するとアラーム時に「アプリが停止しました」というエラーが表示され、通知はショーにはなりません。 私は何をすべきですか?API26以降の通知は表示されませんが、APIの下位に表示されます
私のエミュレータがAPI 27で起動すると、「システムが応答していません」というエラーが表示されます。アプリを閉じるか、待ってください。 私が待っていると、私のアプリは実行され、アプリが開いている間は通知が出ますが、私がアプリを閉じると、通知が表示されず、「アプリが停止しました」というエラーが表示されます。 エミュレータは5.1 WVGA は私がプロないです解像度480X800やRAM 512
を持っています。私はAndroid Studioの新機能です。最初
public int onStartCommand(Intent intent, int flags, int startId) {
if(Build.VERSION.SDK_INT >= 26){
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String idsh = "my_channel_01";
int notificationID = 1;
CharSequence name = getString(R.string.hello_world);
String description = getString(R.string.hello_world);
int importance = NotificationManager.IMPORTANCE_HIGH;
Uri sounduri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationChannel mChannel = new NotificationChannel(idsh, name, importance);
// Configure the notification channel.
mChannel.setDescription(description);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
mChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
assert mNotificationManager != null;
mNotificationManager.createNotificationChannel(mChannel);
Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
Notification notification = new Notification.Builder(this,idsh)
.setContentTitle("Hello World")
.setContentText("Hellooooo")
.setBadgeIconType(R.mipmap.ic_launcher)
.setNumber(5)
.setContentIntent(resultPendingIntent)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setAutoCancel(true)
.build();
assert mNotificationManager != null;
mNotificationManager.notify(notificationID, notification);
Log.i("LocalService", "Received start id " + startId + ": " + intent);
}else{
Uri sounduri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)
.setSound(sounduri)
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
.setContentTitle("Hello World")
.setContentText("Hello World");
Intent resultIntent = new Intent(this, MainActivity.class);
// Because clicking the notification opens a new ("special") activity, there's
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
// Sets an ID for the notification
int mNotificationId = 001;
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
assert mNotifyMgr != null;
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
私はLogcatにこのエラーが出ます:
android.gms.persistent E/GcmPushIntentOperation: Failed to subscribe to GCM: com.google.android.inputmethod.latin
java.io.IOException: TIMEOUT
at vab.b(:[email protected]:42)
at vab.a(:[email protected]:46)
at uzy.b(:[email protected]:11)
at uzy.a(:[email protected]:29)
at com.google.android.gms.phenotype.gcmpush.GcmPushIntentOperation.a(:[email protected]:22)
at com.google.android.gms.phenotype.gcmpush.GcmPushIntentOperation.onHandleIntent(:[email protected]:6)
at com.google.android.chimera.IntentOperation.onHandleIntent(:[email protected]:2)
at bwh.run(:[email protected]:10)
at bwe.run(:[email protected]:14)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
と、この:
はE/ConfigUpdater:無視して更新要求
、その後、私はエミュレータで取得Alarmtime 1分後エラー:アプリケーションが停止し、ログキャットにあります。
Process: com.example.standard.alarm, PID: 3903
java.lang.RuntimeException: Unable to start receiver com.example.standard.alarm.Alarm_Receiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.demo.FirebaseMessagingReceiveService cmp=com.example.standard.alarm/.RingtonePlayingService }: app is in background uid UidRecord{8d38734 u0a79 RCVR idle change:uncached procs:1 seq(0,0,0)}
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3194)
at android.app.ActivityThread.-wrap17(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1672)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.demo.FirebaseMessagingReceiveService cmp=com.example.standard.alarm/.RingtonePlayingService }: app is in background uid UidRecord{8d38734 u0a79 RCVR idle change:uncached procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1518)
at android.app.ContextImpl.startService(ContextImpl.java:1474)
at android.content.ContextWrapper.startService(ContextWrapper.java:649)
at android.content.ContextWrapper.startService(ContextWrapper.java:649)
at com.example.standard.alarm.Alarm_Receiver.onReceive(Alarm_Receiver.java:15)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3187)
logcatにメッセージを表示して、画面がオフのときにサービスが実行されていることを確認してください。 –
どのようなエラーが表示されますか?ログを貼り付けます。 – codeFreak
私はLogcatエラーを追加しました。 – Navidms