2016-10-27 5 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 Intent.ACTION_CALL
  2. にマニフェストにパーミッションを追加します。android.permission.CALL_PHONE
+0

私はそのすべてを行いましたが、マニフェストにアクセス許可を追加しましたが、私がACTION_CALLに変更しても、私には許可エラーが出ます。次にstartActivityをメソッドの中に入れた場合、通知ボタンをクリックすると、通知をクリックするのを待たずにすぐにダイヤラーが表示されます。おそらく、ボタン通知=(ボタン)findViewById(R.id.btnNotification)を追加するのを忘れてしまった。 – MDC

+0

1.ランタイムアクセス許可の読み取り – madless

関連する問題