2017-01-03 84 views
-4

使用意向的CALL和權限。它適用於三星galaxy s4上的android 5。當我在我的活動中按下按鈕時,它會打電話。然而在android 6上,三星j7,它只是顯示一個數字。如何實際撥打電話,不顯示號碼,在Android 6

如何讓它做呼叫?

import android.Manifest; 
import android.content.Intent; 
import android.content.pm.PackageManager; 
import android.net.Uri; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v4.app.ActivityCompat; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.util.Log; 
import android.view.View; 
import android.view.Menu; 
import android.view.MenuItem; 

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) 
    { 
     if (requestCode==this.requestCode_permission_CALL_PHONE) 
     { 
      if (permissions[0].equals(Manifest.permission.CALL_PHONE)) { 
       if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) 
        { 
         Intent intent = new Intent(Intent.ACTION_CALL); 
         intent.setData(Uri.parse("tel:" + this.getString(R.string.phone_number))); 
         this.startActivity(intent); 
        } 
       } else { 
        Log.d("permission","permission grant ignored by user"); 
        //requestPermissions(new String[]{Manifest.permission.SEND_SMS}, PERMISSIONS_CODE); 
       } 
      } 
     } 
    } 
    public int requestCode_permission_CALL_PHONE=1001; 

    public void doCall(View v) { 
     if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { 
      ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.CALL_PHONE} , this.requestCode_permission_CALL_PHONE); 
      return; 
     } 
     Intent intent = new Intent(Intent.ACTION_CALL); 
     intent.setData(Uri.parse("tel:" + this.getString(R.string.phone_number))); 
     this.startActivity(intent); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 
+2

請分享一些代碼 –

+1

請分享您的代碼。 –

+2

設置運行時權限 – sasikumar

回答

0

有一些像Xiomi,Redmi甚至一些設備的三星設備的權限管理器/安全管理器的概念。請檢查您是否有該設備。 如果沒有,您可以正確設置運行時權限。

相關問題