intent

Override Activity from Android Library project

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an Android project. Now I need to create a second edition of that project. What will differ: New edition of the Project should have different content in one of the Activities. I was thinking about creating a library project and two new projects( project1 and project2 ) which will use library project, but I don't really understand how to setup this. Should I just convert the original project into library, then create two new projects and then what ? How to make project1 use activity1 and project2 use activity2 in the same place? EDIT

浅析Android 消息机制

旧时模样 提交于 2019-12-03 06:38:16
浅析Android 消息机制 转载: https://www.jianshu.com/p/b6f4e84d53de 消息机制存在的意义 为什么不能在非UI线程中操作UI控件? 因为Android的UI控件不是线程安全的,如果在多线程中并发访问可能会导致UI控件处于不可预期的状态, 为什么不对UI控件加上锁机制? 首先加上锁会让UI访问的逻辑变得复杂;其次锁机制会降低UI访问的效率,因为锁机制会阻塞某些线程的执行 Android是在哪儿校验UI操作是否是在UI线程? //ViewRootImpl.java public ViewRootImpl(Context context, Display display) { ... ... mThread = Thread.currentThread(); ... ... } //该方法会多个方法的开头被调用,例如requestLayout()、invalidateChildInParent()等等... ... void checkThread() { if (mThread != Thread.currentThread()) { throw new CalledFromWrongThreadException("Only the original thread that created a view hierarchy can

Android双卡打电话和发短信

自闭症网瘾萝莉.ら 提交于 2019-12-03 04:19:45
一、打电话   首先需要申请电话信息权限,AndroidManifest.xml权限配置如下所示。 1 <!-- 打电话的权限 --> 2 <uses-permission android:name="android.permission.CALL_PHONE"/> 3 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>   Android5.1及以前版本只需要在AndroidManifest.xml中配置完权限后就可以进行打电话,打电话方式如下: 1 Intent intent = new Intent(Intent.ACTION_CALL);//android.intent.action.CALL 2 //2). 携带数据 3 String number = et_main_number.getText().toString(); 4 intent.setData(Uri.parse("tel:"+number)); 5 //3). startActivity(intent) 6 startActivity(intent);   对于Android5.1以后的版本,除了AndroidManifest.xml权限配置以外,还需要通过用户允许获取权限,代码如下所示: 1 //检测用户是否同意权限

Android中Intent组件详解

倾然丶 夕夏残阳落幕 提交于 2019-12-03 04:16:00
Intent是不同组件之间相互通讯的纽带,封装了不同组件之间通讯的条件。 Intent 本身是定义为一个类别(Class),一个Intent对象表达一个目的(Goal)或期望(Expectation),叙述其所期望的服务或动作、与动 作有关的数据等。Android则根据此Intent对象之叙述,负责配对,找出相配的组件,然后将 Intent对象传递给所找到的组件,Android的媒婆任务就完成了。 在Google Doc中是这样描述Intent的 (摘自Android中文翻译组) 当接收到ContentResolver发出的请求后,内容提供者被激活。而其它三种组件──activity、服务和广播接收器被一种叫做intent的异步消息所激活。 intent 是一个保存着消息内容的Intent对 象。对于activity和服务来说,它指明了请求的操作名称以及作为操作对象的数据的URI和其它一些信息。比如说,它可以承载对一个activity 的请求,让它为用户显示一张图片,或者让用户编辑一些文本。而对于广播接收器而言,Intent对象指明了声明的行为。比如,它可以对所有感兴趣的对象声 明照相按钮被按下。 对于每种组件来说,激活的方法是不同的: 1.通过传递一个 Intent对象至 Context.startActivity()或Activity

Android Bluetooth : get Device Specific AT commands

匿名 (未验证) 提交于 2019-12-03 03:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using " android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT " intent to get device specific AT commands. But the broadcastreciever didn't fire when I send AT command from MY Bluetooth Kit. When I send AT+CHUP\r from my kit the android work on this command internally and disconnects the call. But when I send AT+XEVENT=foo,3\r from kit but I am not getting any thing in receiver. Help me out 回答1: I also had a hard time getting the vendor specific headset event to work, but finally figured it out. You have to add the Category of

Android 8.0 Oreo AlarmManager with broadcast receiver and implicit broadcast ban

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have critical reminders that are set via the Alarm Manager (It should function the same way as an alarm clock application). Previously I had the following in my Android Manifest: <receiver android:name="com.example.app.AlarmReceiver" > <intent-filter> <action android:name="${packageName}.alarm.action.trigger"/> </intent-filter> </receiver> The broadcast receiver: public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive( final Context context, final Intent intent) { // WAKE LOCK // BUILD NOTIFICATION etc... } }

Suppress notifications from a service if activity is running

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an Activity and Service that work together in my application. I've configured the service as a remote service (implemented AIDL) so it will keep running even when the Activity isn't visible. The service is responsible for polling a server for data and sending alert notifications when certain criteria are met. I do not want the Service to send these notifications when the Activity is visible. Is there a way for the Service to know the status of any particular activity? Particularly an activity that is bound to it? updated with manifest

Is it possible to start a service with a shortcut?

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to create a shortcut on the home screen that, when pressed, will start a service instead of an activity. Is it possible? How? Thanks! 回答1: You can create a dummy Activity that simply starts a Service, then finishes itself: public class MyServiceActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, MyService.class); startService(intent); finish(); } } 回答2: No, sorry. Shortcuts only launch activities. 文章来源: Is it possible to start a service

Schedule notification using alarm manager in xamarin forms for android

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have created a dependencie to show the notifications In My DeviceDetails_Droid.cs I've set set alarm for 30 seconds The functionality for local notification works perfectly when app is active but when I killed the app (close app) the alarm receiver not getting called. public void ShowNotification(string message, string title) { Intent alarmIntent = new Intent(Forms.Context, typeof(AlarmReceiver)); alarmIntent.PutExtra ("message", message); alarmIntent.PutExtra ("title", title); PendingIntent pendingIntent = PendingIntent.GetBroadcast(Forms

android intent when MY app is installed

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i need to perform an action when my application is installed. i've looked into using Intent.PACKAGE_ADDED but i don't receive the intent in the app that's being installed. i want to run code when my app is installed for the first time. the use case is registering with an online service. i can listed for BOOT_COMPLETED which is fine if the app is already installed, but i need to handle the case when the user first installs the app. this post, Can you run an intent or script when your app gets installed on Android? suggests listening to TIMER