나는 여기에 이들 중 많은 톤이 있지만, 하루 종일 솔루션을 시도하고 어디서나 얻지 못했습니다. Google의 문서에 대한 예나 여기에서 찾은 다른 5 가지 방법 중 하나도 나를 위해 전혀 효과가 없었습니다. 일반적인 경우와 마찬가지로 알림을 클릭하면 상태 표시 줄이 닫히고 화면에 아무 것도 표시되지 않습니다. 서비스에서 알림을 만들고 있는데 아직 생성되지 않은 새 활동을 시작하라는 알림이 필요합니다. 의도를 통해 해당 활동에 정보를 전달할 방법이 필요합니다.알림을 클릭 할 때 서비스에서 시작 활동
는 그리고 네 ...이 내 코드의 부서진 잔해 다음과 같다 무엇 안드로이드
에 대한 자바입니다.
package com.bobbb.hwk2;
import java.io.FileOutputStream;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.IBinder;
import android.provider.ContactsContract;
import android.widget.Toast;
public class contactBackup extends Service
{
private NotificationManager nManager;
private static final int NOTIFY_ID = 1100;
@Override
public void onCreate()
{
super.onCreate();
String ns = Context.NOTIFICATION_SERVICE;
nManager = (NotificationManager)getSystemService(ns);
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
// inform user that service has started
Toast.makeText(getApplicationContext(), R.string.service_started,Toast.LENGTH_LONG).show();
String data = lookUpContacts();
if(saveToSDCard(getResources().getString(R.string.backup_file_name),data))
{
Context context = getApplicationContext();
// create the statusbar notification
Intent nIntent = new Intent(this,contactViewer.class);//Intent nIntent = new Intent(Intent.ACTION_MAIN);
nIntent.setClass(context,contactViewer.class);
//nIntent.putExtra("data",data);
Notification msg = new Notification(R.drawable.icon,"All contacts records have been written to the file.",System.currentTimeMillis());
// start notification
//PendingIntent pIntent = PendingIntent.getService(getApplicationContext(),0,nIntent,PendingIntent.FLAG_UPDATE_CURRENT|Intent.FLAG_FROM_BACKGROUND);
PendingIntent pIntent = PendingIntent.getActivity(this,0,nIntent,0);
msg.flags = Notification.FLAG_AUTO_CANCEL;
msg.setLatestEventInfo(context,
"success",
"All contacts records have been written to the file.",
pIntent);
nManager.notify(NOTIFY_ID,msg);
}
}
@Override
public void onDestroy()
{
nManager.cancel(NOTIFY_ID);
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent)
{
return null;
}
// function returns string containing information
// from contacts
public String lookUpContacts()
{
...
}
public boolean saveToSDCard(String fileName, String data)
{
...
}
}
내 문제를 일으키는 어떤 희망 만 할 수는 고칠 수 뭔가 내가 이클립스지고있어 미친 결함이 아닌 더 (지금까지 본을 다른 사람이 보인다> : U)
이 문제를 해결하는 데 도움을 주실 수 있으면 공유하십시오. 는
감사합니다 NOT이 특정 문제에 도움이되지만 게시, 스타일, 주제, 또는 좋은 연습에 대한 관계없는 말을 할 의무감을 느낄 수없는 경우, 다음을 수행하십시오 D
아니라 , 그건 당신이 putExtra를 사용하는 방법이 아니에요 ...하지만 조언을 기반으로 나는 addi 그 플래그를 의도와 PendingIntent에 모두 적용하여 차이를 만들지 마십시오. 그래도 고마워. – user980058
편집 내용이 내가 한 내용과 일치합니다. 여전히 주사위가 없습니다 : 3 – user980058