小编urS*_*Sus的帖子

意图 - 如果活动正在运行,请将其置于最前面,否则启动一个新的(来自通知)

我的应用程序有通知,这是 - 很明显 - 没有任何标志,每次启动一个新的活动,所以我得到对方的顶部,这是错误的运行多个同样的活动.

我想要它做的是将通知挂起意图中指定的活动带到前面(如果它已在运行),否则启动它.

到目前为止,我所拥有的通知的意图/待定意图是

private static PendingIntent prepareIntent(Context context) {
    Intent intent = new Intent(context, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

    return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
Run Code Online (Sandbox Code Playgroud)

奇怪的是,它有时会起作用,有时它不会......我觉得我已经尝试了每一个标志组合.

android android-intent android-activity android-pendingintent

122
推荐指数
5
解决办法
7万
查看次数

Android - Facebook SDK 3 - 如何在没有LoginButton的情况下以编程方式登录

我正在编写一个与Facebook SDK集成的应用程序,以分享一些(字符串)内容作为墙贴.现在,我让HelloFacebookSample工作了.但是它使用LoginButton来记录用户.

我不希望这样.我想要做的就是点击操作栏中的我的分享按钮并分享到Facebook.因此,我想以编程方式登录,我试图模拟LoginButton的功能,但到目前为止还没有成功.我明白了

12-06 15:34:33.180:E/AndroidRuntime(19493):java.lang.UnsupportedOperationException:Session:尝试重新授权具有待处理请求的会话.

公共类MainActivity扩展了FacebookActivity {

@SuppressWarnings("serial")
private static final List<String> PERMISSIONS = new ArrayList<String>() {
    {
        add("publish_actions");
    }
};
private final int REAUTHORIZE_ACTIVITY = 3;
private Button postStatusUpdateButton;
private PendingAction pendingAction = PendingAction.NONE;

private enum PendingAction {
    NONE, POST_PHOTO, POST_STATUS_UPDATE
}

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Log.d("MainActivity", "onClick");
            onClickPostStatusUpdate();
        }

    });

}

@Override …
Run Code Online (Sandbox Code Playgroud)

android login button facebook-android-sdk

39
推荐指数
2
解决办法
2万
查看次数

Android Volley ImageLoader - BitmapLruCache参数?

我在使用新的Volley库实现Image缓存时遇到了麻烦.在演示文稿中,代码看起来像这样

mRequestQueue = Volley.newRequestQueue(context);
mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache());
Run Code Online (Sandbox Code Playgroud)

BitmapLruCache显然不包含在工具包中.知道如何实现它或指向一些资源?

http://www.youtube.com/watch?v=yhv8l9F44qo @ 14:38

谢谢!

android image-loading bitmapcache android-volley

35
推荐指数
3
解决办法
3万
查看次数

ActionBar徽标居中,两侧是Action项目

我怎么能让一个操作栏在中心有徽标,两边有两个动作项?

在此输入图像描述

我将使用ActionBar Sherlock.

android center graphical-logo android-actionbar

34
推荐指数
1
解决办法
3万
查看次数

片段共享元素转换与add()而不是replace()?

我试图在片段之间进行共享元素转换,当使用replace()添加第二个片段时一切正常,但是在代码库add()中使用了很多,但是当使用它时,转换只是跳到结束值

是否有可能在添加的片段之间进行转换? 谢谢

@Override
public void onClick(View v) {
    setSharedElementReturnTransition(TransitionInflater.from(getActivity())
        .inflateTransition(android.R.transition.move));

    FragmentB secondFragment = new FragmentB();
    secondFragment.setSharedElementEnterTransition(TransitionInflater.from(getActivity())
        .inflateTransition(android.R.transition.move));

    getFragmentManager().beginTransaction()
        .add(R.id.container, secondFragment)
        .addToBackStack(null)
        .addSharedElement(imageView, imageView.getTransitionName())
        .commit();
}
Run Code Online (Sandbox Code Playgroud)

android shared-element-transition fragment-transitions

33
推荐指数
2
解决办法
2400
查看次数

有没有办法在Android中偏移中心的视图?

我试图使我的按钮不完全在中心,但让我们说在屏幕高度的2/5s,我正在寻找属性失败,所以我试过这种方法

<RelativeLayout 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:background="@drawable/background"
android:padding="20dp" >

 <ImageButton
    android:id="@+id/flashlight_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_above="@+id/fakeView"
    android:background="@null"
    android:contentDescription="@string/flashlight_button_description"
    android:src="@drawable/freeml_bright" />

   <View
    android:id="@+id/fakeView"
    android:layout_width="10dp"
    android:layout_height="10dp"
    android:layout_centerInParent="true"
    android:background="#FFAABB" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

但是它不起作用,即使我在假视图上设置了保证金.

有任何想法吗?

//编辑//

谢谢你的回答家伙,填充属性工作,但因为它是一个大图像,如果我希望它从屏幕高度的2/5开始,它覆盖屏幕的中心点,所以如果我使用填充属性它的工作,但它将它推离中心,不允许它覆盖它.对不起这是我的错

虽然,我使用线性布局工作,我想避免,因为在顶部和底部有更多的视图彼此相邻,所以它将导致使用线性布局的嵌套视图.不幸的是,我认为这是唯一的选择.

它基本上使用另一个线性布局,填充顶部和底部视图未使用的剩余空间,高度= 0dp,权重= 1,并将其重力设置为中心

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/application_logo_description"
        android:src="@drawable/mylight" />

     <ImageButton
        android:id="@+id/settings_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:background="@null"
        android:contentDescription="@string/settings_button_description"
        android:src="@drawable/settings_button" /> 
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/flashlight_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:contentDescription="@string/flashlight_button_description" …
Run Code Online (Sandbox Code Playgroud)

android center android-layout android-view android-relativelayout

24
推荐指数
2
解决办法
2万
查看次数

Android - 禁用应用程序的虚拟启动窗口

我想知道如何实现这种效果.

我的应用程序(默认所有内容),当点击启动器图标时,立即显示某种空的虚拟窗口,其中没有任何事情发生,然后将布局加载到其中.

"重型"应用程序,如YouTube,云端硬盘,Dropbox等,在启动时似乎等待启动后,没有显示虚拟窗口并加载到准备好的布局中.

知道怎么做或者我应该在哪里研究?

谢谢

//编辑:这与加载数据库之类的东西无关,我应该在其中显示progressBar,imho这与活动存在之前的东西有关.

android window startup

14
推荐指数
2
解决办法
1万
查看次数

Android Volley - 如何动画图片加载?

任何想法如何在图像加载时播放动画淡入淡出?现在它只是闪烁到位.我正在使用Volley工具包中的NetworkImageView.

另外,有没有办法在不使用ImageLoader.get(..)的情况下在网络图像视图上设置加载和错误位图?

谢谢!

//编辑:好的,多亏你们所有人,但是如果我们想成为完美主义者,我们应该只在从磁盘缓存加载时动画,覆盖setImageBitmap即使从 memcache中拉出也会使动画关闭

你想要做的是shouldAnimate像这样向ImageListener.onResponse 添加一个布尔值

public static ImageListener getImageListener(final ImageView view, final int defaultImageResId,
        final int errorImageResId) {
    return new ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                view.setImageResource(errorImageResId);
            }
        }

        @Override
        public void onResponse(ImageContainer response, boolean isImmediate, boolean shouldAnimate) {
            if (response.getBitmap() != null) {
                if (shouldAnimate) {
                    // ADDED
                    view.setAlpha(0f);
                    view.setImageBitmap(response.getBitmap());
                    view.animate().alpha(1f).setDuration(1000);
                    // END ADDED
                } else {
                    view.setImageBitmap(response.getBitmap());
                }
            } else if (defaultImageResId != …
Run Code Online (Sandbox Code Playgroud)

android animated fadein imageview android-volley

13
推荐指数
3
解决办法
1万
查看次数

如何强制停止正在进行的意图服务?

我有一个意图服务,下载几千兆字节的视频.我有一个"停止"按钮,如果意外点击"开始"或其他什么,停止下载.我知道这已被问过几次,但对我没有工作答案.

我试着打电话stopService(),不行.那只是打电话IntentService.OnDestroy().我试着打电话stopSelf()进去onDestroy,也没办法.

我尝试过像标志一样的东西,但如果onHandleIntent已经在运行,它就不会被调用,它等待当前的工作完成并执行.即使这会起作用,我也不得不像巨型if语句一样,这很糟糕

我唯一的选择是将其重写为常规服务吗?

//回答

public class SyncService extends IntentService {

    boolean isCanceled;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        if (intent.hasExtra("action")) {

            // Set the canceling flag
            isCanceled= intent.getStringExtra("action").equals("cancel");

        }
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        // Clean up the possible queue
        if (intent.hasExtra ("action")) {
            boolean cancel = intent.getStringExtra ("action"). Equals ("cancel");
            if (cancel) {
                return;
            }
        }

        ...

        Get your inputStream …
Run Code Online (Sandbox Code Playgroud)

service android intentservice

12
推荐指数
1
解决办法
7807
查看次数

新的KitKat URI不响应Intent.ACTION_VIEW

由于KitKat已将URI从拾取器更改为喜欢的

 content://com.android.providers.media.documents/document/image:3951
Run Code Online (Sandbox Code Playgroud)

那时我的ACTION_VIEW意图都不再有用了.例如,当用户选择图像时,我会使用

public static void openImage(Fragment f, Uri uri) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/*");

        f.startActivity(intent);
    }
Run Code Online (Sandbox Code Playgroud)

和Android图库和Google+照片一起出现,但选中后,图库只显示空白屏幕,照片显示"未找到中等"

声音也一样,我习惯使用

public static void playSound(Fragment f, Uri uri) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, "audio/*");

    f.startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)

用于在以前的版本中显示Google Play音乐,使用小白色播放对话框UI.使用新的URI,我得到一个例外,没有应用程序能够处理此意图.

//对于照片,有趣的是,当你在新的KK选择器UI中选择Gallery而不是Pictures时,它会返回有效的旧URI.

有任何想法吗?系统应用程序还没有为新的uris做好准备吗?我应该以某种方式将新的uris破解为旧的uris以使意图有效吗?或者我错过了什么?

谢谢!

android uri android-intent

11
推荐指数
1
解决办法
1337
查看次数