2017-09-20 11 views
0

私は頭をアップ通知に取り組んでいます。私のコードはすべてのデバイスで正常に動作していますが、xiaomiやLeEcoではアンドロイド5.1より上のデバイスはうまく動作していません。 私のコードは:xiaomiとLeEcoのようなデバイスのためのヘッドアップ通知

RemoteViews contentView = null; 
    contentView = new RemoteViews(context.getPackageName(), R.layout.demo); 

final android.support.v4.app.NotificationCompat.Builder notification = new NotificationCompat.Builder(context) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setDefaults(Notification.DEFAULT_ALL) 
      .setPriority(NotificationCompat.PRIORITY_HIGH) 
      .setCustomHeadsUpContentView(contentView) 
      .setVibrate(new long[0]) 
      .setCategory(Notification.CATEGORY_CALL) 
      .setDeleteIntent(createOnDismissedIntent(context, 2222)) 
      .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) 

final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(1111, notification.build()); 

何が問題になりますか?

+0

あなたはここに投稿してくださいその後、任意のエラーを取得しています。 –

+0

私はエラーは発生しませんが、ヘッズアップ通知を受信して​​いません。これはパネルでの通常の通知のようになります。私は詳細を確認しましたが、これらのデバイスは通知のためのより多くの権限を持っています彼らはそれをより制限的にしました。私は手動でこれらのチェックをオンにする必要がありますし、私はヘッドアップ通知を受信します。 LeEcoのように "バナー通知のチェック"があります。 –

答えて

0

は、私は、このソリューションは、あなたのために非常に有用になると思うが、私はLeEcoデバイスのいずれかの解決策を見つけることができません。

public class WhiteListUtils { 

private static final String SKIP_WHITELIST_APP = "SKIP_WHITELIST_APP"; 

private static final String XIAOMI = "xiaomi"; 
private static final String HUAWEI = "huawei"; 
private static final String OPPO = "oppo"; 
private static final String VIVO = "vivo"; 

private static SharedPreferences settings; 

private WhiteListUtils() { 
} 

public static void showWhiteListingApps(Context context) { 
    if (settings == null) 
     settings = context.getSharedPreferences("WhiteListUtils", MODE_PRIVATE); 
    if (!settings.getBoolean(SKIP_WHITELIST_APP, false)) 
     checkOSCompat(context); 
} 

private static void checkOSCompat(Context context) { 
    try { 
     Intent intent = new Intent(); 
     String manufacturer = android.os.Build.MANUFACTURER; 
     if (XIAOMI.equalsIgnoreCase(manufacturer)) { 
      intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")); 
     } else if (OPPO.equalsIgnoreCase(manufacturer)) { 
      intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")); 
      intent.setComponent(new ComponentName("com.coloros.oppoguardelf", "com.coloros.powermanager.fuelgaue.PowerConsumptionActivity")); 
     } else if (VIVO.equalsIgnoreCase(manufacturer)) { 
      intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")); 
     } else if (HUAWEI.equalsIgnoreCase(manufacturer)) { 
      intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")); 
     } 

     if (isCallable(context, intent)) { 
      showAlertWindow(context, intent); 
     } else { 
      if (BuildConfig.BUILD_TYPE.contains("release")) 
       Crashlytics.log("Intent not callable for whitelisting " + intent.toString()); 
      Log.e("Intent not callable for whitelisting " + intent.toString()); 
     } 
    } catch (Exception e) { 
     if (BuildConfig.BUILD_TYPE.contains("release")) { 
      Crashlytics.logException(e); 
     } 
     Log.e("checkOSCompat Error " + e.getMessage()); 
    } 
} 

private static void showAlertWindow(final Context context, final Intent intent) { 
    new AlertDialog.Builder(context) 
      .setIcon(android.R.drawable.ic_dialog_alert) 
      .setTitle("Protected Apps") 
      .setMessage(String.format("%s requires to be enabled in 'Protected Apps' to function properly.%n", context.getString(R.string.app_name))) 
      .setPositiveButton("Go to Apps", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        context.startActivity(intent); 
        settings.edit().putBoolean(SKIP_WHITELIST_APP, true).apply(); 
       } 
      }) 
      .setNegativeButton(android.R.string.cancel, null) 
      .show(); 
} 


private static boolean isCallable(Context context, Intent intent) { 
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, 
      PackageManager.MATCH_DEFAULT_ONLY); 
    return list.size() > 0; 
} 

public void hasProtectedApps(String packaGe, String activity) { 
    try { 
     String replacedActivityName = activity.replace(packaGe, ""); 
     //String cmd = "am start -n com.huawei.systemmanager/.optimize.process.ProtectActivity"; 
     String cmd = "am start -n " + packaGe + "/" + replacedActivityName; 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 
      cmd += " --user " + getUserSerial(); 
     } 
     Runtime.getRuntime().exec(cmd); 
    } catch (IOException e) { 
     if (BuildConfig.BUILD_TYPE.contains("release")) 
      Crashlytics.logException(e); 
     Log.e("isProtectedApps Error " + e.getMessage()); 

    } 
} 

private String getUserSerial() { 
    //noinspection ResourceType 
    Object userManager = getSystemService("user"); 
    if (null == userManager) return ""; 

    try { 
     Method myUserHandleMethod = android.os.Process.class.getMethod("myUserHandle", (Class<?>[]) null); 
     Object myUserHandle = myUserHandleMethod.invoke(android.os.Process.class, (Object[]) null); 
     Method getSerialNumberForUser = userManager.getClass().getMethod("getSerialNumberForUser", myUserHandle.getClass()); 
     Long userSerial = (Long) getSerialNumberForUser.invoke(userManager, myUserHandle); 
     if (userSerial != null) { 
      return String.valueOf(userSerial); 
     } else { 
      return ""; 
     } 
    } catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { 
     if (BuildConfig.BUILD_TYPE.contains("release")) 
      Crashlytics.logException(e); 
     Log.e("getUserSerial Error " + e.getMessage()); 
    } 
    return ""; 
    } 
} 
関連する問題