2016-04-19 8 views
0

開発用デバイスがUSBに接続されている場合、私のアプリケーションの通知メッセージ文字列が表示されます。私はUSBから電話を切断するとすぐに、アプリが開いていても、自分のアプリの通知は表示されなくなり、空白になります。通知メッセージは、USBに接続されているデバイスのみを表示します

ADBでアプリケーションを実行しているときにlogcatにエラーがなく、他のすべてのパラメータが通知に正常に渡されます。唯一の問題は、setContentText()がAndroid Studio/ADBが動作していなくても、電話がUSB経由でコンピュータに接続されている場合にのみ動作するように見えることです。

devデバイスは、4.1.2で動作する古いSamsung SPH-L300(el-cheapo Virgin携帯電話)です。私はそれをテストする別のデバイスを持っていません。私はAndroid Studio 1.5.1をIDEとして使用しています。

いくつかのマニフェスト要素がありませんか?私は似たような問題について聞いたことがありますが、それはUSBに接続していないときにしか動作しない、別の方法でした。それに対する解決策は、gradle.buildでSDKの最小値とターゲットを変更することで、私の問題を解決できませんでした(ただし、試してみると何かを見逃してしまった可能性があります)。ここ

通知はアラームマネージャから放送受信機を使用して活性化されるが....コードです:

package com.example.notificationApp; 

import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.content.res.Resources; 
import android.graphics.Color; 
import android.media.RingtoneManager; 
import android.net.Uri; 
import android.os.Bundle; 
import android.support.v4.app.NotificationCompat; 
import android.util.Log; 

public class AlarmReceiver extends BroadcastReceiver { 
public AlarmReceiver() { 
} 

@Override 
public void onReceive(Context context, Intent intent) { 

    // get the info needed to identify this specific reminder... 
    Bundle bundle = intent.getExtras() 
    int alarmID = bundle.getInt("reminderID"); 

    Intent returnIntent = new Intent(context, HomeActivity.class); 
    PendingIntent pIntent = PendingIntent.getActivity(context, alarmID, returnIntent, 0); 

    Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 

    // make vibrate pattern... 
    long[] pattern = {500,500,500,500,500,500,500,500,500}; 

    Notification notify = new NotificationCompat.Builder(context) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setTicker("Appointment reminder") 
      .setContentTitle("Reminder...") 
      .setContentText("TEST TEXT") 
      .setSound(alarmUri) 
      .setLights(Color.BLUE, 500, 500) 
      .setVibrate(pattern) 
      .setContentIntent(pIntent) 
      .setAutoCancel(true) 
      .build(); 

    NotificationManager notificationManager = 
      (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 

    notificationManager.notify(alarmID, notify); 
} 

そして、ここでは私のManifest.xmlです:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.notificationApp"> 

<!-- Permission to start Alarm on device reboot --> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
<uses-permission android:name="android.permission.VIBRATE" /> 

<uses-sdk 
    android:minSdkVersion="15" 
    android:targetSdkVersion="23" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 

    <activity android:name=".HomeActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <receiver android:name=".AutoStart"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 

    <receiver android:name=".CheckAlarmReceiver"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 

    <receiver android:name=".AlarmReceiver" /> 

    <!-- 
     ATTENTION: This was auto-generated to add Google Play services to your project for 
     App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. 
    --> 
    <meta-data 
     android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" /> 

</application> 

私はこの1つに困惑しています、誰でも手がかりを持っていますか?前もって感謝します!!

答えて

1

私はこの問題を発見し、他の誰かが同じ問題で終わった場合にそれを投稿したかったのです。信じられないかもしれませんが、問題は携帯電話の開発者の設定でStay Awakeモードをオンにしていたことです。 Stay Awakeをオフにして、デベロッパーの設定でやり直してください!

私はちょうど見つけ、この他のポストからアイデアを得た:

https://stackoverflow.com/a/25566924/3716557

(リンクでの回答に任意のupvotesを指示してください)

+0

あなたのアイデアdoes't作業を。私はあなたのコードを使用していますが、何も変更しません。 –

+0

http://stackoverflow.com/users/7344925/ashish-shahi問題はコードではなく、デバイスの設定にありました。通知で同様の問題が発生していますか? – user3716557

+0

私はデバイスを変更しています –

関連する問題