2012-07-22 2 views
1

랩합니다. 모든 것은 내 갤럭시 S II에서 훌륭하게 작동합니다 (스프린트에서 4g의 장엄한 터치가 나옵니다. 거기에 S II의 모델이 너무 많아서 특정해야한다고 생각합니다). 알림 단어는 아무런 문제가 없습니다. 예 :내가 흥미있는 (물론, 나에게 적어도) 문제가 발생했습니다

내 공포
this is a notification, but it's too long, 
so it'll show this second line on it's own. 

, 나는 어떤 안드로이드 폰은 자동 줄 바꿈하지 않았다 실현하고, 위의 메시지가로 표시 할 수 있도록 사실 단순히 자신의 화면의 끝에서 내 통지를 잘라 :

this is a notification, but it's too long, 
분명히 이것은 수행하지 않을 것입니다.

그렇다면 전체 메시지가 항상 표시되도록하려면 어떻게해야합니까?

답변

0

재 작성

우리는 당신이 Notifcation의 tickerText 단어에 랩을 강제하려는 전에 설명한 것처럼. 한 가지 방법은 적절한 길이의 줄에 텍스트를 깨고에 대한 통지를 보내 각 하나 나는 의 길이를 가정 : 당신은 내가 설정 한의 불가분의 일부를 생략 볼 수 있습니다 그러나

public class Example extends Activity { 
    public class AlarmReceiver extends BroadcastReceiver { 
     @Override 
     public void onReceive(Context context, Intent intent) { 
      Log.v("Example", "Alarm received"); 
      sendNotification(); 
     } 
    } 

    AlarmManager alarmManager; 
    NotificationManager notificationManager; 

    AlarmReceiver alarmReceiver = new AlarmReceiver(); 
    Notification notification = new Notification(); 
    Intent notificationIntent; 
    PendingIntent pendingIntent; 
    int tickerIndex = 0; 
    List<String> tickerTexts = new ArrayList<String>(); 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
     notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

     // Determine the screen width and density, split tickerText appropriately 
     String tickerText = "A tickerText that is long enough to cause a word wrap in portrait."; 
     tickerTexts.add(tickerText.substring(0, 35)); 
     tickerTexts.add(tickerText.substring(35)); 

     notificationIntent = new Intent(this, Example.class); 
     pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 

     notification.flags = Notification.FLAG_ONLY_ALERT_ONCE; 
     notification.icon = android.R.drawable.star_on; 

     sendNotification(); 
     registerReceiver(alarmReceiver, new IntentFilter("Generic")); 
    } 

    @Override 
    protected void onDestroy() { 
     unregisterReceiver(alarmReceiver); 
     super.onDestroy(); 
    } 

    public void sendNotification() { 
     Log.v("Example", "Send Notification " + tickerIndex); 

     notification.tickerText = tickerTexts.get(tickerIndex); 
     notification.setLatestEventInfo(this, "Title", "Text " + tickerIndex, pendingIntent); 
     notificationManager.cancel(0); 
     notificationManager.notify(0, notification); 

     tickerIndex++; 
     if(tickerIndex < tickerTexts.size()) { 
      Log.v("Example", "Setting up alarm"); 
      PendingIntent alarmPending = PendingIntent.getBroadcast(this, 0, new Intent("Generic"), 0); 
      alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000, alarmPending); 
     } 
    } 
} 

나는 맞는 텍스트를 계산하지 않았다. 적절한 중단 점을 결정하려면 화면 너비, 글꼴의 크기 조절 된 크기 및 밀도를 계산해야합니다. 당신은 또한 "!!!" 글꼴에 따라 "www"보다 짧을 수도 있고 사용자가 가로와 세로 사이를 전환 할 수도 있습니다 ... 소스 코드에서 일반적인 Android가 tickerText를 분해하는 방법을 살펴볼 수 있습니다.

어쨌든 tickerText를 자동 줄 바꿈으로 변경하는 것은 원래 String을 압축하거나 "비 포장"전화 제조업체에 분노한 편지를 보내는 것보다 훨씬 복잡 할 수 있습니다.

+0

샘 (sam) 감사합니다. 훌륭한 답변 인 것처럼 보이지만, 실제로 필요한 것은 도움이되지 않습니다. 내 알림을 남겨 두지 않고 있습니다. 이벤트가 발생했을 때 깜박일뿐입니다. 나를 위해 일하지 마라. 내가 너무 길어서 알림을 원하지 않는다는 것에 동의한다. 나는 1-2 단어를 놓치고있다. ... – raingod

+0

"깜박이는"것은 상태 표시 줄의'tickerText'를 의미한다. 또는 내가 이미지를 얻을 수 있다면 두 번)? – Sam

+0

예, 정확하게. 그게 바로 끊어지고있는 .. – raingod

관련 문제