2016-10-27 3 views
0

알림을 생성 했으므로 알림을 생성했지만 어떻게해야할지 모르겠으나 답을 찾으려고했지만 전화를 걸 수 없었습니다. .알림을 클릭하여 전화하는 방법

notification.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      createNotification(v); 
     } 
    }); 


public void createNotification(View view) { 
    Intent intent = new Intent(); 
    PendingIntent pIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0); 

    Notification noti = new Notification.Builder(MainActivity.this) 
      .setContentTitle("Make a Call") 
      .setContentText("0390000000") 
      .setSmallIcon(R.drawable.phone) 

      .setContentIntent(pIntent).getNotification(); 
    noti.flags |= Notification.FLAG_AUTO_CANCEL; 
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

    notificationManager.notify(0, noti); 
} 

나는이를 가지고 있지만 난 단지 전화 걸기를 열고 위에 함께

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tel: 0390000000"))); 

코드를 넣어하는 방법을 모르겠어요,하지만 난 바로 그 번호로 전화를합니다.

도움을 주시면 감사하겠습니다.

M.

답변

1

도 추가

Intent notificationIntent = new Intent(Intent.ACTION_CALL); 
callIntent.setData(Uri.parse("tel:123456789")); 


notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
     | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

PendingIntent intent = PendingIntent.getActivity(context, 0, 
     notificationIntent, 0); 

시도 매니페스트 파일의 사용 권한

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> 
0
  1. 변경 Intent.ACTION_VIEW
  2. 가 매니페스트에 권한을 추가 Intent.ACTION_CALL합니다 : android.permission.CALL_PHONE을
+0

나는 그 모든 것을했는데, 매니페스트에 권한을 추가했지만 ACTION_CALL으로 변경하면 여전히 권한 오류가 발생합니다. 그런 다음 startActivity를 메서드 안에 넣으면 알림 단추를 클릭하면 알림을 클릭하지 않고 곧바로 전화 걸기를 표시합니다. 아마도 버튼을 추가하는 것을 잊어 버렸습니다. notification = (Button) findViewById (R.id.btnNotification); – MDC

+0

1. 런타임 사용 권한 읽기 – madless

관련 문제