在我看过的各种Android代码中:
public class MyActivity extends Activity {
public void method() {
mContext = this; // since Activity extends Context
mContext = getApplicationContext();
mContext = getBaseContext();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我找不到任何合适的解释,哪些更好,以及在什么情况下应该使用.
关于这方面的文件的指示,以及关于如果选择了错误的可能会破坏的指导,将不胜感激.
我目前正在尝试将我的应用程序调整为Android M的新权限模型.
我正在收集我需要的所有权限,然后运行
Log.i("Permissions", "Requesting permissions: " + permissions);
requestPermissions(requiredPermissions.toArray(new String[requiredPermissions.size()]), requestCodeForPermissions);
Run Code Online (Sandbox Code Playgroud)
requiredPermissions拥有我需要的权限android.permission.WRITE_EXTERNAL_STORAGE
.
该例程肯定是执行的,因为我在logcat中有Log行:
08-07 12:52:46.469: I/Permissions(1674): Requesting permissions: android.permission.RECEIVE_BOOT_COMPLETED; android.permission.WRITE_EXTERNAL_STORAGE
Run Code Online (Sandbox Code Playgroud)
但是权限对话框从不显示,更不用说调用onRequestPermissionsResult()了.
我究竟做错了什么?基于一些教程,我发现我没有遗漏任何东西.我只有用于测试的模拟器,没有物理设备.这是关于设置的屏幕: 图像
可能值得一提的是:如果我尝试从主屏幕打开已安装应用程序的概述,我只会得到launcher3 has exited
.我不确定这可能是相关的.
有没有人知道它为什么没有显示?
我是Google Play上两个闹钟应用的开发者.我想让他们使用Android 6.0.但是,打盹模式使它们不响.我把它们放在白名单上,我放了一个前景通知图标,我不知道我还能做什么 - 当处于打盹模式时,警报管理器警报仍然被忽略.然而,时钟应用程序(这是一个Google Play而不是AOSP应用程序)是不同的.当在Clock应用程序上启用闹钟时,"adb deviceidle step"将始终显示为"active"且永远不会"idle","idle_pending"或其他任何内容.
Android在这里作弊,给自己的应用程序更多的力量,又名."拉苹果"?Google Play上的所有闹钟应用程序是否即将失效?有点担心,这些都是高质量的应用程序,每个人都需要一年的兼职开发时间,并且对我来说是很大的收入来源.关于如何让这些工作起作用的任何线索都将是一个巨大的帮助.
设置AlarmManager意图:
Intent intent = new Intent(context, ReceiverAlarm.class);
if (android.os.Build.VERSION.SDK_INT >= 16) {
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
}
amSender = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT); //FLAG_CANCEL_CURRENT seems to be required to prevent a bug where the intent doesn't fire after app reinstall in KitKat
am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, scheduleToTime+1, amSender);
Run Code Online (Sandbox Code Playgroud)
和ReceiverAlarm类:
public class ReceiverAlarm extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (wakeLock == null) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); …
Run Code Online (Sandbox Code Playgroud) 我正在使用带有Android M Preview的Nexus 5.
我试图解决的问题是:
除非您的应用收到高优先级的Google云消息传递,否则会禁用网络访问权限.
我在做的是:
我把手机置于打盹模式,然后我发送一个优先级值为10的推送通知,我希望能在短时间内访问互联网,但这不起作用.
我应该使用其他类型的通知吗?有没有可用的文件?
谢谢.
Android M更改:https: //developer.android.com/preview/behavior-changes.html
我发现了有关GCM优先级消息的信息:https: //developers.google.com/cloud-messaging/server-ref
如果手机处于打盹模式或我的应用程序处于待机模式,我怎么能在我的应用程序中知道?
我可以通过使用一些订阅方法来了解它吗?
我在团队中遇到了这个问题:我们想测试与日历的交互,我们显然需要日历写入权限才能执行此操作.有没有办法确保仪器测试有必要的权限?我知道你可以虚拟地授予特定avd的权限,但是有更好的方法吗?
testing permissions android unit-testing android-6.0-marshmallow
有了Androids新的权限系统,我想知道如何正确实现它.关于如何以及何时使用权限的教程似乎非常清楚.但是,我不知道谁请求权限以及请求它们的位置.
所以,基本上我的问题是:如果活动,谁开始另一个活动请求事先获得许可,或者需要许可的活动是否应该提出请求?
如果需要许可的活动应该请求它,我应该requestForPermission
在里面onCreate
还是在里面打电话onStart
?
虽然这似乎是非常简单的问题,但我没有在文档中找到任何提示.
谢谢.
调用ActivityCompat.requestPermissions不会显示UI对话框.
ActivityCompat.requestPermissions(MainActivity.this, new String[]{"Manifest.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);
Run Code Online (Sandbox Code Playgroud)
但是,如果我将minSDKversion更改为23并运行
requestPermissions(new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);
Run Code Online (Sandbox Code Playgroud)
出现对话框.为什么?BTW.要在模拟器上运行它,模拟器将以API 23为目标.
我正在研究Android上的传统VOIP应用程序.它现在不使用Google Cloud Messaging技术,而是永远保持自己的TCP连接.
最近谷歌推出了带有Doze模式的 Android M预览版
所以问题是:在没有重新设计整个系统以使用GCM的情况下,应用程序如何在打盹模式下接收传入呼叫/消息是否有任何解决方法?
android push-notification android-networking google-cloud-messaging android-6.0-marshmallow
任何人都可以举例说明如何实现这个抽象类 - ConnectionService.my的想法是使用TelecomManager拨打电话.
https://developer.android.com/reference/android/telecom/ConnectionService.html#SERVICE_INTERFACE
TelecomManager telecomManager = (TelecomManager)this.getSystemService(Context.TELECOM_SERVICE);
PhoneAccountHandle accountHandle=telecomManager.getSimCallManager();
PhoneAccount account=telecomManager.getPhoneAccount(accountHandle);
telecomManager.registerPhoneAccount(account);
CharSequence label=account.getLabel();
ConnectionRequest request = null;
Connection connection= service.onCreateOutgoingConnection(accountHandle,request);
Run Code Online (Sandbox Code Playgroud)
现在我需要知道在请求feild和Connection服务中将给出的内容如何在它之前实现..