是否可以运行Google Sample - RuntimePermissionsBasic
在OS低于MNC(Android M)的设备上?
该项目附带:
compileSdkVersion "android-MNC"
targetSdkVersion "MNC"
Run Code Online (Sandbox Code Playgroud)
到目前为止一直这么好,在低于M OS的情况下运行它将获得:
INSTALL_FAILED_OLDER_SDK
但当我把它改为:
compileSdkVersion 22
targetSdkVersion "MNC"
Run Code Online (Sandbox Code Playgroud)
Android Studio无法识别该checkSelfPermission (...)
方法
在我的产品的自动化测试期间,我将文件推送到应用程序专用目录和chmod
文件,以便应用程序可以访问它.在API <Marshmallow,这很好,应用程序从来没有访问文件的问题.
现在,在某些文件上,我尝试打开它时会收到以下日志:
W/System.err(7669): Caused by:
java.io.FileNotFoundException: /data/user/0/foo/foo.txt: open failed: EACCES (Permission denied) 09-28 18:20:56.724:
W/System.err(7669): at libcore.io.IoBridge.open(IoBridge.java:452) 09-28 18:20:56.724:
W/System.err(7669): at java.io.FileInputStream.<init>(FileInputStream.java:76) 09-28 18:20:56.724:
W/System.err(7669): at android.app.ContextImpl.openFileInput(ContextImpl.java:384) 09-28 18:20:56.724:
W/System.err(7669): at android.content.ContextWrapper.openFileInput(ContextWrapper.java:177) 09-28 18:20:56.724:
W/System.err(7669): Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) 09-28 18:20:56.724:
W/System.err(7669): at libcore.io.Posix.open(Native Method) 09-28 18:20:56.724:
W/System.err(7669): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) 09-28 18:20:56.724:
W/System.err(7669): at libcore.io.IoBridge.open(IoBridge.java:438) 09-28 18:20:56.716:
W/pool-5-thread-1(8279): type=1400 audit(0.0:57): avc: denied { search } for name="files" dev="mtdblock1" ino=7314 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=dir permissive=0 …
Run Code Online (Sandbox Code Playgroud) Android 6.0中的应用程序链接正在更改,因此Android可以更好地了解哪些应用程序可以直接打开内容,而不是每次都使用对话框停止用户.
我该如何实现它?
我写了这段代码.
ConnectivityManager connectivity = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {}
Run Code Online (Sandbox Code Playgroud)
但是不推荐使用getAllNetworkInfo().请帮忙.谢谢.
我刚刚更新了我的Nexus 5,我的应用程序功能已停止工作.
原因是接口LeScanCallback
没有调用该函数onLeScan
.在下面的代码中,我使用了一些弃用的代码,但是我需要这样做,因为我正在测试一些技术.这就是我启动蓝牙适配器的方法:
@Override
protected void onStart()
{
super.onStart();
// Check if the device has BLE
if (!this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE))
{
bleNotSupported();
return;
}
// Initializes a Bluetooth adapter.
final BluetoothManager bluetoothManager = (BluetoothManager)this.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled())
{
bleNotEnabled();
/*
* Bluetooth can be enabled in app:
*
* Intent btIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
* btIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
* mAppContext.startActivity(btIntent);
*/
return;
}
boolean bluetoothScanning = mBluetoothAdapter.startLeScan(mScanCallback); // this is true as well
progressBar.setVisibility(View.VISIBLE); …
Run Code Online (Sandbox Code Playgroud) 我最近更新了我的应用程序,以支持android 6 marshmallow.我按照https://developer.android.com/training/permissions/requesting.html上的说明进行操作
并为Manifest.permission.RECEIVE_SMS添加了requestPermissions.当我运行以下代码时:
Log.i(TAG, "sending SMS...");
Intent intent = new Intent("android.provider.Telephony.SMS_RECEIVED");
intent.putExtra("pdus", data);
getContext().sendOrderedBroadcast(intent, null);
Run Code Online (Sandbox Code Playgroud)
我明白了
java.lang.SecurityException:Permission Denial:不允许从pid = 1999发送广播android.provider.Telephony.SMS_RECEIVED,uid = 10056
即使我授予SMS_RECEIVED权限,我也无法在设备上发送短信广播.
任何想法为什么我在Android 6上获得此安全异常.
我的目标是在我的设备链接中生成假短信[ 我可以发送"短信接收意图"吗? .我没有在谷歌上发现任何提及它不再允许.
我正在整合第三方sdk,它是从应用程序类启动的.但是在Android Marshmallow API 23上进行测试时,我收到权限错误,因为SDK需要"ACCESS_COARSE_LOCATION"权限.
因为我需要在应用程序级别上集成SDK,而不是在活动级别上,当我打电话时
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1 );
Run Code Online (Sandbox Code Playgroud)
IDE正在给出错误,因为"this"不是Activity.
是否可以从Application类请求Android权限.
我试图从我的应用程序打开消息应用程序,但我在Marshmallow中收到ActivityNotFoundException.我用了下面的代码:
Intent n = new Intent(Intent.ACTION_VIEW);
n.setType("vnd.android-dir/mms-sms");
n.putExtra("address", phone);
n.putExtra("sms_body", " ");
startActivity(n);
Run Code Online (Sandbox Code Playgroud) 我尝试在Android 6.0上的外部SD卡上写一切,但我无法写上它.
我对stackoverflow进行了研究,发现了很多东西,但都没有.这是我的代码
String extPath = System.getenv("SECONDARY_STORAGE") + "/Android/data/com.gvm.externalstorage.externalstoragetest/";
File file = new File(extPath,"myFiles");
if (!file.exists()) {
boolean dirResult = file.mkdirs();
Log.e("Directory Exist", dirResult + " Directory created");
} else {
Log.e("Directory Exist", "Exist");
Log.e("Direcotry Path",file.getAbsolutePath());
}
//String displayname = fileName.replace("%20", " ");
File outputFile = new File(file, "mytest5.txt");
outputFile.createNewFile();
Run Code Online (Sandbox Code Playgroud)
此代码适用于Android 5.0,但不适用于Android 6.0.
然后我也尝试了这个路径,这给了我权限错误,我已经为运行时权限设置了所有权限和托管代码.
/mnt/media_rw/6AC9-083B
File write failed: java.io.IOException: open failed: EACCES (Permission denied)
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我,那么在过去的3天里我会这样做很棒.
谢谢,Anvesh
我是Android工作室的新手,我以前在我的应用程序上工作Android版本5.1它工作正常但现在在6我无法获得许可或我不确定我的方法是否错误.我正在制作一个应用程序,它使用我的手机可用的访问点列表.但即使我被授予权限,我的应用程序也没有向我显示wifi列表,但相同的代码适用于早期版本.
Mainactivity:
package com.wiferange.wifi_test;
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.List;
public class MainActivity extends AppCompatActivity {
ListView lv;
String lists[]={"a","b"};
WifiManager wifi;
String wifis[];
WifiScanReceiver wifiReciever;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
lv = (ListView)findViewById(R.id.listView);
wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE); …
Run Code Online (Sandbox Code Playgroud) android android-permissions android-studio android-6.0-marshmallow
android ×9
permissions ×3
applinks ×1
bluetooth ×1
connection ×1
file ×1
networking ×1
request ×1