14

मैं एक कॉलिंग ऐप बना रहा हूं।एंड्रॉइड मार्शमलो 6.0 में आने वाली कॉल का जवाब नहीं दे सकता

यहां ऑटो उत्तर है जो एंड्रॉइड 4.0 और 5.0 पर काम करता है; जबकि जब मेरे पास एक इनकमिंग कॉल उत्तर कॉल बटन काम करता है लेकिन यह एंड्रॉइड 6.0 पर काम नहीं करता है।

मैं इस पोस्ट के जवाब का परीक्षण किया, लेकिन यह बहुत काम नहीं करता: Answer Incoming Call in Android 6.0

IncomingActivity:

@Override 
public void onClick(View v) { 
    switch (v.getId()) 
    { 
     case R.id.imgaccept: 
     { 
      if (Build.VERSION.SDK_INT >= 21) { 
       new Thread(new Runnable() { 

        @Override 
        public void run() { 

         try { 
          Runtime.getRuntime().exec("input keyevent " + KeyEvent.KEYCODE_HEADSETHOOK); 
          Intent intent = new Intent(getApplicationContext(), OutGoing.class); 
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 
          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
          intent.putExtra(CommonMethods.OUTGOING_NUMBER, savedNumber); 
          startActivity(intent); 
          finish(); 
         } 
         catch (Throwable t) { 

         } 
        } 
       }).start(); 
      } 
      else { 
       Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON); 
       buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK)); 
       sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED"); 

       Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON); 
       buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK)); 
       sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED"); 

       Intent intent = new Intent(this, OutGoing.class); 
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 
       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       intent.putExtra(CommonMethods.OUTGOING_NUMBER, savedNumber); 
       startActivity(intent); 
       finish(); 
      } 
      break; 
     } 
     case R.id.imgdecline: 
     { 
      CommonMethods.rejectCall(this); 
      finish(); 
      break; 
     } 
     default: 
      break; 
    } 
} 
+0

के लिए जाने के शो सूचना बॉक्स टिकटिक करने की जरूरत है? – Ahmed

+1

हाँ मैं सभी अनुमति की जांच – Secret

+1

@ सेक्रेट: क्या आपको इसके लिए समाधान मिला है? –

उत्तर

5

कई अनुसंधान करने के लिए, अंत में मैंने पाया समाधान

NotificationCall.java

public class NotificationCall extends NotificationListenerService { 

@RequiresApi(api = Build.VERSION_CODES.KITKAT) 

static StatusBarNotification mysbn; 
Context context; 

public StatusBarNotification[] getActiveNotifications() { 
    return super.getActiveNotifications(); 
} 

public void onCreate() { 
    super.onCreate(); 
    this.context = getApplicationContext(); 
} 

@Override 
public void onNotificationPosted(StatusBarNotification sbn) { 
    super.onNotificationPosted(sbn); 
    mysbn = sbn; 
    try { 

     String packageName = sbn.getPackageName(); 
     Intent intent = new Intent("Msg"); 
     intent.putExtra("package", packageName); 
     LocalBroadcastManager.getInstance(this.context).sendBroadcast(intent); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    } 
} 

प्रकट में जोड़ें:

<service 
     android:name=".NotificationCall" 
     android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"> 
     <intent-filter> 
      <action android:name="android.service.notification.NotificationListenerService" /> 
     </intent-filter> 
    </service> 

बटन पर क्लिक स्वीकार करें:

button.setOnClickListener(new View.OnClickListener() { 
     @TargetApi(Build.VERSION_CODES.LOLLIPOP) 
     @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 
     @Override 
     public void onClick(View v) { 
      try { 
       for (MediaController mediaController : ((MediaSessionManager) getApplicationContext().getSystemService("media_session")).getActiveSessions(new ComponentName(getApplicationContext(), NotificationCall.class))) { 
        if ("com.android.server.telecom".equals(mediaController.getPackageName())) { 
         mediaController.dispatchMediaButtonEvent(new KeyEvent(1, 79)); 
         return; 
        } 
       } 
      } catch (SecurityException e2) { 
       e2.printStackTrace(); 
      } 
     } 
    }); 

तुम बस

Settings > Apps > All > Dialer > Check the notification box 

अनुमति के लिए करने के लिए जाने शो सूचना बॉक्स टिकटिक करने की जरूरत है:

if (Settings.Secure.getString(getContentResolver(), "enabled_notification_listeners").contains(getApplicationContext().getPackageName())) 
    { 

    } else 
     { 
     Intent i = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); 
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(i); 
    } 

संस्करण Nougat संस्करण का परीक्षण किया है।

चीयर्स!

0

हल हो गया! डायलर ऐप में "अधिसूचनाएं दिखाएं" बॉक्स अनचाहे था।

यह सुनिश्चित नहीं है कि यह कैसे हुआ।

ही समस्या का सामना किसी के लिए:

सेटिंग> एप्लिकेशन> सभी> डायलर> सूचना बॉक्स की जाँच करें।

0

आप आप पर Android 6.0+ अनुमतियों के लिए जाँच कर रहे हैं बस

Settings > Apps > All > Dialer > Check the notification box

संबंधित मुद्दे