我正在尝试Android Lollipop附带的新JoScheduler API.到目前为止,我已经设法成功地创建并运行了6000毫秒的延迟,没有网络要求而没有问题.
但是,我刚刚尝试通过使用setPersisted(true)函数来保持相同的工作.一旦调用了job build()函数,它就会失败,说我需要Manifest文件中的RECEIVED_BOOT_COMPLETED权限.
但我已经添加了许可:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.android" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Run Code Online (Sandbox Code Playgroud)
我甚至在添加作业之前添加了以下代码,以查看应用是否已注册权限:
PackageManager pm = context.getPackageManager();
int hasPerm = pm.checkPermission(Permission.RECEIVE_BOOT_COMPLETED,
context.getPackageName());
if (hasPerm == PackageManager.PERMISSION_GRANTED)
{
// Goes into here every time
}
Run Code Online (Sandbox Code Playgroud)
但是,当作业生成时,我收到以下错误:
java.lang.IllegalArgumentException: Error: requested job be persisted without holding RECEIVE_BOOT_COMPLETED permission.
Run Code Online (Sandbox Code Playgroud)
我的代码创建并将作业添加到JobSchedular:
ComponentName serviceComponent = new ComponentName(getApplicationContext(), MyJobService.class);
JobInfo.Builder builder = new JobInfo.Builder(1, serviceComponent)
.setMinimumLatency(6000)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPersisted(true);
JobScheduler jobScheduler = (JobScheduler) getApplicationContext().getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(builder.build());
Run Code Online (Sandbox Code Playgroud)
我的JobService清单声明:
<service
android:name=".service.MyJobService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true" >
</service>
Run Code Online (Sandbox Code Playgroud)
所以我想知道我是否在做其他任何人都无法发现的错误.我唯一注意到它确实会产生影响的是,代码是在IntentService中运行的,所以我想知道这是否是JobScheduler无法找到权限的原因.
我一直在研究如何在Android中创建圆形ImageView.在阅读StackOverflow上有关该主题的问题之后:
和
我已经将我自己的ImageView放在一起,使用链接作为指导来完成我需要它做的事:带边框的圆形图像.
以下是我使用的代码:
public class CircularImageView extends ImageView
{
private int borderWidth = 5;
private int viewWidth;
private int viewHeight;
private Bitmap image;
private Paint paint;
private Paint paintBorder;
private BitmapShader shader;
public CircularImageView(Context context) {
super(context);
setup();
}
public CircularImageView(Context context, AttributeSet attrs) {
super(context, attrs);
setup();
}
public CircularImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setup();
}
private void setup()
{
// init paint
paint = new Paint();
paint.setAntiAlias(true);
paintBorder = new …
Run Code Online (Sandbox Code Playgroud) 我目前正在与Android Iab v3作斗争.
我以前一直在使用Google的IabHelper类来显示成功的可用产品.然而,今天它不再给我任何回报.
传递给IabHelper类中IInAppBillingService的getSkuDetails函数的querySku字段的内容是:
捆绑[{ITEM_ID_LIST = [com.app.android.credits.10,com.app.android.credits.25,com.app.android.credits.50]}]
我在返回的包中得到的是:
捆绑[{DETAILS_LIST = [],RESPONSE_CODE = 0}]
从它工作的时间开始,现在我根本没有改变IabHelper代码以及显示产品的代码.代码的重要部分是:
private void getItemsForSale()
{
ArrayList<String> skuList = new ArrayList<String>();
skuList.add(getResources().getString(R.string.ten_credits_product_id));
skuList.add(getResources().getString(R.string.twenty_credits_product_id));
skuList.add(getResources().getString(R.string.fifty_credits_product_id));
mHelper.queryInventoryAsync(true, skuList, this);
}
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv)
{
if(result.isFailure())
{
Log.d("DEBUG", "Error Inventory Query: " + result);
AppMsg.makeText(BuyCreditsActivity.this, R.string.sorry_something_went_wrong, AppMsg.STYLE_ALERT).show();
}
else
{
// Code here queries the inv object returned which has a blank array
}
}
Run Code Online (Sandbox Code Playgroud)
这就是为什么我这么困惑.
有没有人知道外部因素可能导致开始没有返回任何产品细节?
我最近从ImageView扩展到创建一个CircularImageView类,它使图像呈圆形,带有彩色边框.这是通过onDraw(canvas)方法绘制到传入的画布上完成的:
//load the bitmap
loadBitmap();
// init shader
if(image !=null)
{
shader = new BitmapShader(Bitmap.createScaledBitmap(image, viewWidth + (borderWidth * 2), viewHeight + (borderWidth * 2), true), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
int circleCenter = viewWidth / 2;
// circleCenter is the x or y of the view's center
// radius is the radius in pixels of the cirle to be drawn
// paint contains the shader that will texture the shape
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter + borderWidth, paintBorder);
canvas.drawCircle(circleCenter …
Run Code Online (Sandbox Code Playgroud) 我已经成功地建立了使用下面的例子从谷歌自己在操作栏分页,http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.html为一个基地.我的代码看起来像这样:
public class Main extends SherlockFragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1 = getSupportActionBar().newTab();
tab1.setIcon(R.drawable.ic_tab_example_selected);
tab1.setTabListener(new TabListener<Tab1>(this, "A", Tab1.class));
getSupportActionBar().addTab(tab1);
ActionBar.Tab tab2 = getSupportActionBar().newTab();
tab2.setIcon(R.drawable.ic_tab_example_selected);
tab2.setTabListener(new TabListener<Tab2>(this, "B", Tab2.class));
getSupportActionBar().addTab(tab2);
ActionBar.Tab tab3 = getSupportActionBar().newTab();
tab3.setIcon(R.drawable.ic_tab_example_selected);
tab3.setTabListener(new TabListener<Tab3>(this, "C", Tab3.class));
getSupportActionBar().addTab(tab3);
ActionBar.Tab tab4 = getSupportActionBar().newTab();
tab4.setIcon(R.drawable.ic_tab_example_selected);
tab4.setTabListener(new TabListener<Tab4>(this, "D", Tab4.class));
getSupportActionBar().addTab(tab4);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
return …
Run Code Online (Sandbox Code Playgroud) android android-fragments actionbarsherlock android-actionbar
我有一个SlidingDrawer和一个渲染图像的自定义SurfaceView.我刚刚尝试拖动SlidingDrawer,并且这样做发现它在SurfaceView中的图像后面并且完全隐藏.
您可以想象这对用户来说没什么用处,因此在拉起时需要图像始终落在SlidingDrawer之后.这可能吗?
包含它有助于这是xml中的SlidingDrawer:
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:handle="@+id/handle"
android:content="@+id/content"
android:layout_alignParentBottom="true">
<TextView
android:id="@id/handle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:textStyle="bold"
android:text="text"/>
<include layout="@layout/content"
android:id="@id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</SlidingDrawer>
Run Code Online (Sandbox Code Playgroud)
这是xml中的SurfaceView:
<FrameLayout android:id="@+id/FrameLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.android.imagemagic.widgets.ImageManipulationSurfaceView
android:id="@+id/surfaceArea"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_gravity="center"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
SurfaceView是自定义的,并在onDraw()方法中使用以下代码:
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
//Clear canvas
Paint paint = new Paint();
paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
canvas.drawPaint(paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC));
// Draw image
canvas.drawBitmap(image, imageX, imageY, null);
}
Run Code Online (Sandbox Code Playgroud) 我目前正在为 Android 应用程序中的一些流行平台创建直接意图,以共享一些文本。我目前正试图获得与 LinkedIn 合作的直接意图。
我目前有一个直接的意图为 Twitter 工作,如下所示:
shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setClassName("com.twitter.android",
"com.twitter.android.PostActivity");
shareIntent.setType("text/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivityForResult(shareIntent, 9);
Run Code Online (Sandbox Code Playgroud)
我现在需要的和 LinkedIn 是一样的。到目前为止,我在互联网上搜索后知道了 LinkedIn 的基本包。那是“com.linkedin.android”(如果这是错误的,请纠正我)。但是,我缺少的关键部分是在 LinkedIn 应用程序中处理共享的类的名称。即 com.linkedin.android.?。
android ×7
android-view ×1
bitmapimage ×1
eclipse ×1
image ×1
java ×1
linkedin ×1
picasso ×1
surfaceview ×1