0

上に表示されていないと、私はそれが私のRedmi 3sの上で動作していないという問題点call.but着信時に警告を表示するために使用しています私のコードであるプライムまたは6.0上で実行されている任意のデバイス。私が要求しなければならない、または他のway.any助けがより有用である任意の許可はありますか。警告ダイアログがMIデバイス上または下に6.0

CallBarring.java以下

public class CallBarring extends BroadcastReceiver { 
    // This String will hold the incoming phone number 
    private String number; 
    CustomDialog dialog; 
    TelephonyManager telephonyManager; 
    PhoneStateListener listener; 
    Context context; 

    @Override 
    public void onReceive(final Context context, Intent intent) { 
     // If, the received action is not a type of "Phone_State", ignore it 
     if (!intent.getAction().equals("android.intent.action.PHONE_STATE")) 
      return; 

     // Else, try to do some action 
     else { 
      this.context = context; 
      if(dialog == null){ 
      dialog = new CustomDialog(context); 
      dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 
      dialog.show(); 
      } 
      // Fetch the number of incoming call 
      number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); 
      telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
      listener = new PhoneStateListener() { 
       @Override 
       public void onCallStateChanged(int state, String incomingNumber) { 
        String stateString = "N/A"; 
        switch (state) { 
        case TelephonyManager.CALL_STATE_IDLE: 
         stateString = "Idle"; 
         dialog.dismiss(); 
         break; 
        case TelephonyManager.CALL_STATE_OFFHOOK: 
         stateString = "Off Hook"; 
         dialog.dismiss(); 
         break; 
        case TelephonyManager.CALL_STATE_RINGING: 
         stateString = "Ringing"; 
         dialog.show(); 
         break; 
        } 
        Toast.makeText(context, stateString,Toast.LENGTH_LONG).show(); 
       } 
      }; 

      // Register the listener with the telephony manager 
      telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); 

      // Check, whether this is a member of "Black listed" phone numbers 
      // stored in the database 
      /*if (MainActivity.blockList.contains(new Blacklist(number))) { 
       // If yes, invoke the method 
       disconnectPhoneItelephony(context); 
       return; 
      }*/ 
     } 
    } 

    // Method to disconnect phone automatically and programmatically 
    // Keep this method as it is 
    @SuppressWarnings({ "rawtypes", "unchecked" }) 
    private void disconnectPhoneItelephony(Context context) { 
     ITelephony telephonyService; 
     TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
     try { 
      Class c = Class.forName(telephony.getClass().getName()); 
      Method m = c.getDeclaredMethod("getITelephony"); 
      m.setAccessible(true); 
      telephonyService = (ITelephony) m.invoke(telephony); 
      telephonyService.endCall(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    class CustomDialog extends Dialog implements OnClickListener { 

     public CustomDialog(Context context) { 
      super(context); 
      // TODO Auto-generated constructor stub 
     } 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      // TODO Auto-generated method stub 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.list_item); 
      Button btnEndCall = (Button) findViewById(R.id.end_call); 
      //btnEndCall.set 
      btnEndCall.setOnClickListener(this); 
     } 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      disconnectPhoneItelephony(context); 
     } 
    } 

である私ののAndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="--------------" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="14" 
     android:targetSdkVersion="21" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <receiver android:name=".CallBarring" > 
      <intent-filter android:priority="100" > 
       <action android:name="android.intent.action.PHONE_STATE" /> 
      </intent-filter> 
     </receiver> 
    </application> 

    <uses-permission android:name="android.permission.CALL_PHONE" /> 
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> 

</manifest> 
+0

あなたはランタイム許可をinplementedしていますか? MIデバイスで –

+0

時には彼らは、自動的にいくつかの権限を許可していません。手動で許可が有効かされていない場合、私はhope.Settings>アプリケーション/アプリケーション>アプリケーションが確認してください自分のアプリの設定から、それを可能にしなければなりません。有効にしない場合は試してください。また、6.0とそれ以上のデバイスに、あなたは私がそれを実装します聞いている許可のランタイム許可 –

+0

@VladMatvienkoを実装する必要があります。 –

答えて

0

としてあなたは、ランタイム許可を求めることができる:

private static final int READ_PHONE_STATE = 1; 
private static String[] PERMISSIONS = { 
    Manifest.permission.READ_PHONE_STATE, 
}; 


private boolean checkPermissions() { 
     int result; 
     List<String> listPermissionsNeeded = new ArrayList<>(); 
     for (String p : PERMISSIONS) { 
      result = ContextCompat.checkSelfPermission(mContext, p); 
      if (result != PackageManager.PERMISSION_GRANTED) { 
       listPermissionsNeeded.add(p); 
      } 
     } 
     if (!listPermissionsNeeded.isEmpty()) { 
      ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), READ_PHONE_STATE); 
      return false; 
     } 
     return true; 
    } 

@Override 
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 
     switch (requestCode) { 
      case READ_PHONE_STATE: 
       if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
        // Permission granted. 
       } else { 
        //code for deny 
       } 
       break; 
     } 
    } 
+0

を喜ば助けるask.canする必要がどの権限を知っています通知から電話 –

+0

その6.0以上のランタイム許可が必須である場合、私は言われたよう! –

+0

これは他のデバイスでも機能しますか? –

関連する問題