谷歌Play商店应用程序(又称Android Market)已经更新,有许多很酷的功能,甚至是应用程序的愿望清单.
我想知道是否有任何官方API与它进行通信,甚至意图.我想知道人们是否只是查看日志以查看意图,或者是否有官方API来访问应用程序的每个页面.
以下是此类API可能允许您执行的操作的一些示例:
等等…
在Android上,有两种方法可以通过BroadcastReceivers监听系统事件:
由于某些项目包含许多活动,服务和"管理器"类,因此让一个BroadcastReceiver通知应用程序上的所有侦听器有关已发生的事情,而不是使用多个BroadcastReceiver可能很有用(和他们的代码处理).
此类BroadcastReceiver的一个示例是侦听连接更改的示例:
@Override
public void onCreate() {
super.onCreate();
...
registerReceiver(new ConnectivityChangedBroadcastReceiver(), new IntentFilter(
ConnectivityManager.CONNECTIVITY_ACTION));
...
}
Run Code Online (Sandbox Code Playgroud)
目的是在应用程序"活着"时(通过服务和/或活动)收听事件.
使用清单会错过这个目的,因为它会在每次事件发生时唤醒应用程序,即使应用程序不需要它.
事实是,取消注册不会发生,也许它会导致操作系统以不同的方式对待应用程序.
在从Application扩展的类上调用"registerReceiver"是一个众所周知的做法吗?
使用时是否有任何副作用和需要了解的事项?
有没有替代方案?
我只是想确保它被认为是安全的.
这是一个简单的问题,看到G +(这里)有关于此的大量帖子,以及官方文档(这里)缺乏信息:
当设备进入"打盹"模式时,应用程序的服务会发生什么变化?
它对后台/前台服务(绑定/未绑定,已启动/未启动)有什么作用,有/无部分/完整唤醒锁?
例如,为了创建在设备屏幕关闭时播放音频流的服务,您会做什么?如果音频流不是来自本地文件,而是来自网络,该怎么办?
看到Google开发者声称:
已经运行前台服务的应用程序(带有相关通知)不受打盹的限制.
- 之后进行了大量的讨论,声称这并不完全正确,我认为知道特殊的后台操作应用程序应该做什么是相当令人困惑的.
android android-service android-doze-and-standby android-doze
是否有可能获得对videoView正在使用的mediaPlayer实例的引用,最好是在它的ctor内?如果是这样,怎么样?
由于videoView没有mediaPlayer那么多的监听器,我希望能够访问mediaPlayer以获得额外的控制和更好的事件处理.
背景:
这就是为什么我决定创建我自己的布局,你要告诉每个孩子他们的重量(和周围的重量)与它的大小相比应该是什么.
看来我已经成功了,但出于某种原因,我认为有一些我无法追查的错误.
其中一个错误就是textView,即使我为它提供了大量空间,它也会将文本放在顶部而不是放在中心.另一方面,imageViews工作得很好.另一个错误是,如果我在自定义布局中使用布局(例如frameLayout),则其中的视图将不会显示(但布局本身将会显示).
请帮我弄清楚它为什么会发生.
如何使用:而不是线性布局的下一个用法(我故意使用长XML,以显示我的解决方案如何缩短事物):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<View android:layout_width="wrap_content" android:layout_height="0px"
android:layout_weight="1" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="0px" android:layout_weight="1"
android:orientation="horizontal">
<View android:layout_width="0px" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:layout_width="0px" android:layout_weight="1"
android:layout_height="match_parent" android:text="@string/hello_world"
android:background="#ffff0000" android:gravity="center"
android:textSize="20dp" android:textColor="#ff000000" />
<View android:layout_width="0px" android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<View android:layout_width="wrap_content" android:layout_height="0px"
android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我所做的只是(x是将视图本身放在权重列表中的位置):
<com.example.weightedlayouttest.WeightedLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.weightedlayouttest"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">
<TextView android:layout_width="0px" android:layout_height="0px"
app:horizontalWeights="1,1x,1" app:verticalWeights="1,1x,1"
android:text="@string/hello_world" android:background="#ffff0000"
android:gravity="center" android:textSize="20dp" android:textColor="#ff000000" />
</com.example.weightedlayouttest.WeightedLayout>
Run Code Online (Sandbox Code Playgroud)
我的特殊布局代码是:
public class WeightedLayout extends ViewGroup
{
@Override …Run Code Online (Sandbox Code Playgroud) android android-layout android-linearlayout android-layout-weight android-percent-library
从Honeycomb(API 11)开始,Android具有允许broadcastReceiver以异步方式运行的功能,在它假定它可以使用名为" goAsync " 的方法杀死其进程之前大约10秒:
这可以由onReceive(Context,Intent)中的应用程序调用,以允许它在从该函数返回后保持广播活动.这不会改变对广播相对响应的期望(在10秒内完成),但允许实现将与其相关的工作移到另一个线程,以避免因磁盘IO而导致主UI线程出现故障.
我在很多地方搜索过,没有找到任何关于如何使用它的示例或教程.
不仅如此,该方法返回一个PendingIntent实例,我不知道该如何处理它:
返回表示活动广播结果的BroadcastReceiver.PendingResult.BroadcastRecord本身不再有效; 所有数据和其他交互必须通过BroadcastReceiver.PendingResult API.完成广播处理后,必须调用PendingResult.finish()方法.
你是如何使用这种方法的?
什么是它返回的PendingIntent,我应该怎么做呢?
android asynchronous broadcastreceiver android-pendingintent
Google最近发布了对其支持库的更新,该库现在有一个新的" SwipeRefreshLayout "视图.
该视图允许包装另一个视图,同时支持向下滑动以执行刷新操作.
截图:

谷歌没有提供样本(至少没有我能找到的样本),所以我自己尝试过使用它.
每当我刷卡时,我都会遇到崩溃(NPE),但后来我发现这是因为我没有为它提供"OnRefreshListener".
但我仍然不知道如何使用它,更不用说自定义它了
这是布局文件的XML:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.swiperefreshlayouttest.MainActivity"
tools:ignore="MergeRootFrame" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
代码,虽然它根本没有做任何特别的事情:
public class MainActivity extends ActionBarActivity
{
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); …Run Code Online (Sandbox Code Playgroud) 我正在尝试检查是否在运行时启用/禁用了活动(或任何其他应用程序组件类型).
可以使用下一个代码:
final ComponentName componentName = new ComponentName(context, activityClass);
final PackageManager pm = context.getPackageManager();
final int result = pm.getComponentEnabledSetting(componentName);
Run Code Online (Sandbox Code Playgroud)
但是返回的结果,如文档中所写:
返回组件的当前启用状态.可以是COMPONENT_ENABLED_STATE_ENABLED,COMPONENT_ENABLED_STATE_DISABLED或COMPONENT_ENABLED_STATE_DEFAULT之一.最后一个意味着组件的启用状态基于清单中的原始信息,如ComponentInfo中所示.
所以它不仅是启用/禁用,还是"默认".
如果返回"COMPONENT_ENABLED_STATE_DEFAULT",我如何知道它是默认为启用还是禁用(在运行时)?
这个问题的原因是无论人们放入清单中的内容("启用"属性),代码都应该有效.
是否有可能使用意图解决?
android android-manifest android-package-managers android-activity
我今天刚刚创建了一个新的POC(关于活动转换,但这不是主题),我注意到在主要活动的"onCreate"方法中写了一个新行:
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
Run Code Online (Sandbox Code Playgroud)
和更多:
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
mClient.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"SinglePhotoViewer Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches …Run Code Online (Sandbox Code Playgroud) 我试图手动(逐帧)查看动画GIF和WEBP文件的位图,这样它不仅可以用于视图,还可以用于其他情况(例如动态壁纸).
仅使用ImageDecoder API(此处为示例)从Android P支持动画GIF/WEBP文件.
对于GIF,我想尝试滑翔的任务,但我失败了,所以我试图克服这一,通过使用一个库,允许(加载它们在这里,解决方案在这里).我认为它运作正常.
对于WebP,我以为我找到了另一个可以在较旧的Android版本上运行的库(这里,在这里制作了fork ),但似乎在某些情况下它无法很好地处理WebP文件(在此报道).我试图弄清楚问题是什么以及如何解决,但我没有成功.
因此,假设有一天谷歌将通过支持库支持旧版Android的GIF和WEBP动画(他们在这里写了),我决定尝试使用ImageDecoder来完成任务.
事实上,在ImageDecoder的整个API中,我们应该如何使用它.我不知道如何克服其局限性.
这就是ImageDecoder如何用于在ImageView上显示动画WebP(当然,这里只有一个示例):
class MainActivity : AppCompatActivity() {
@SuppressLint("StaticFieldLeak")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val source = ImageDecoder.createSource(resources, R.raw.test)
object : AsyncTask<Void, Void, Drawable?>() {
override fun doInBackground(vararg params: Void?): Drawable? {
return try {
ImageDecoder.decodeDrawable(source)
} catch (e: Exception) {
null
}
}
override fun onPostExecute(result: Drawable?) {
super.onPostExecute(result) …Run Code Online (Sandbox Code Playgroud) android ×10
android-doze ×1
animated-gif ×1
api ×1
asynchronous ×1
google-play ×1
imagedecoder ×1