小编use*_*337的帖子

我试图通过adb测试Android深层链接网址来启动我的应用程序

当我在adb中键入命令时:

./adb shell am start -W -a android.intent.action.VIEW -d "example:gizmos" com.myapp
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Starting: Intent { act=android.intent.action.VIEW dat=example://gizmos pkg=com.myapp }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=example://gizmos flg=0x10000000 pkg=com.myapp }
Run Code Online (Sandbox Code Playgroud)

但是当我在adb中输入命令时:

./adb shell am start -W -a android.intent.action.VIEW -d "example:gizmos" com.myapp.activity.DeepLinkActivity
Run Code Online (Sandbox Code Playgroud)

一切正常,我收到消息,我可以在手机上看到活动的启动:

Starting: Intent { act=android.intent.action.VIEW dat=example://gizmos cmp=com.myapp.activity.DeepLinkActivity }
Status: timeout
Activity: com.myapp.activity.DrawerActivity
Complete
Run Code Online (Sandbox Code Playgroud)

我的问题是为什么我需要获得我的活动的完整路径,而不仅仅是包名?因为当外部应用程序或浏览器尝试深层链接时,它们不会调用我的应用程序中的活动.

这是我的AndroidManifest.xml

<activity
        android:name=".activity.DeepLinkActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="example"
                  android:host="gizmos" />

        </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

android deep-linking adb android-manifest

38
推荐指数
11
解决办法
4万
查看次数

向上滚动不适用于Listview中的SwipeRefreshLayout

我想用listView实现滚动刷新功能.此外,如果列表为空,则在同一布局文件中还有其他视图元素.这是我的布局文件.问题是,当我向下滚动然后尝试向上滚动时,而不是一直滚动到顶部然后刷新它只是在那里刷新并向上滚动不起作用.

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="64dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp" >

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:src="@drawable/inbox_empty" />

        <TextView
            android:id="@+id/noEventsText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="16dp"
            android:layout_toRightOf="@+id/noEventsIcon" />

        <View
            android:id="@+id/divider"
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="4dp"
            android:background="@color/dividerOnBlack" />
    </RelativeLayout>

    <ListView
        android:id="@+id/list_items"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:cacheColorHint="@android:color/transparent"
        android:choiceMode="multipleChoice"
        android:descendantFocusability="afterDescendants"
        android:divider="@android:color/transparent"
        android:dividerHeight="0px"
        android:scrollbars="none" />
</LinearLayout>

</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的onScroll方法.

@Override
public void onScroll(AbsListView view,int firstVisibleItem,int visibleItemCount,int totalItemCount) {
    // If the total item count is zero and the previous isn't, assume the …
Run Code Online (Sandbox Code Playgroud)

java android swiperefreshlayout

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

深层链接进入应用程序后的后退按钮不会返回到它来自的位置

当从移动浏览器网站进入Android应用程序的深层链接,然后我按下后退按钮,应用程序关闭,后台没有任何东西,而不是去移动浏览器网站.当我点击所有打开的应用程序的设备按钮时,我看到浏览器仍然在内存中,因此我认为操作系统不会清除浏览器.有人解决了这个问题吗?请帮忙.

browser android deep-linking

8
推荐指数
1
解决办法
1005
查看次数

Android Retrofit预计BEGIN_OBJECT但是STRING在第1行第1列路径$

我在我的Android应用程序中使用okhttp Retrofit来发出网络请求.在其中一个请求中,我收到此错误:

com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期为BEGIN_OBJECT但在第1行第1行为STRING路径$

我在日志中看到201响应,但Retrofit会抛出此错误.以下是我的代码.

signup(signupParams, new Callback<Member>() {
            @Override
            public void success(Member member, Response response) {
                if (member != null) {
                    UserAccount userAccount = new UserAccount(member);
                    userAccount.save();
            }

            @Override
            public void failure(RetrofitError re) {
                BusProvider.post(new SignupFailedEvent(re, email));
            }
        });
Run Code Online (Sandbox Code Playgroud)

signupParams值是 -

{"emailAddress":"test@gmail.com","password":"tester123","userSource":"APH"}
Run Code Online (Sandbox Code Playgroud)

我用jsonLint测试了这个json,它是一个有效的json.这是我的会员类,理想情况下应该是回应.

public class Member {
    public String emailAddress;
    public String token;
    public long id;
    public String firstName;
    public String lastName;
}
Run Code Online (Sandbox Code Playgroud)

响应的示例应该是这样的:

{
    "emailAddress": "test@gmail.com",
    "id": 1437811,
    "token": "sdhshdghsdhhsdbcjhbsjdhc",
    "firstName": "John",
    "lastName": "Smith"
}
Run Code Online (Sandbox Code Playgroud)

android json gson retrofit okhttp

6
推荐指数
1
解决办法
8461
查看次数

Android:ft.remove() 和 popBackStack() 之间的区别

我正在尝试从堆栈中删除一个片段。我正在使用这段代码:

FragmentManager fm = getSupportFragmentManager();
    if (fm != null) {
        FragmentTransaction ft = fm.beginTransaction();
        Fragment currentFragment = fm.findFragmentById(R.id.my_id);
        if (currentFragment != null) {
            ft.remove(currentFragment);
            ft.commit();
        }
    }
Run Code Online (Sandbox Code Playgroud)

我需要使用上面的代码调用 popBackStack() 吗?

fm.popBackStack();
Run Code Online (Sandbox Code Playgroud)

java android android-fragments fragmentmanager

5
推荐指数
1
解决办法
3951
查看次数

Android点击通知不会打开附加的Activity

当我点击状态栏中的通知时,我想打开一个活动.我在StackOverflow上看到了这个问题,但这些答案都不适用于我.此问题仅在Lollipop设备上出现,最佳重现方式是:1.启动应用程序.2.重新启动应用程序.3.接收推送通知.4.单击通知并尝试3-4推送通知.

以下是我的代码:我也尝试了以下内容:

  1. 添加Intent.ACTION_MAIN
  2. Intent.CATEGORY_LAUNCHER的意图
  3. PendingIntent.FLAG_UPDATE_CURRENT.
  4. 我的AndroidManifest.xml中的android:exported ="true"

但没有任何作用.我只在Lollipop设备上看到这个问题.请注意我间歇地看到这个问题.这是与缓存的意图有关还是未交付的内容.请帮忙.

PendingIntent pendingIntent = getPendingIntent(context, payload);
Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat)
            .setContentTitle(res.getString(R.string.app_name))
            .setContentText(payload.getMessage())
            .setTicker(payload.getMessage())
            .setContentIntent(pendingIntent)
            .setSound(soundUri);

private PendingIntent getPendingIntent(Context context, NotificationPayload payload) {
    int requestID = (int) System.currentTimeMillis();
    Intent intent = new Intent(context, DeepLinkActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setPackage(BuildConfig.APPLICATION_ID);
    intent.putExtra(NotificationHelper.KEY_NOTIFICATION_PAYLOAD, payload);
    return PendingIntent.getActivity(context, requestID, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
}
Run Code Online (Sandbox Code Playgroud)

android push-notification android-activity android-pendingintent

5
推荐指数
1
解决办法
1808
查看次数

用Volley进行Android单元测试

是否可以为我的Android应用程序编写单元测试,我使用Volley进行网络请求.对于Eg.我想为登录功能编写单元测试,其中我发布了一个带有用户凭据的截击请求,并在响应中检查有效的用户对象.有没有人做过类似的事情?请提供示例或参考.

这是我的登录方法:

    public void login() {
    try {
        JSONObject jsonRequest = new JSONObject();
        String emailString = email.getText().toString();
        jsonRequest.put("email", emailString);
        String passwordString = password.getText().toString();
        jsonRequest.put("password", passwordString);

        NetworkUtil.postLogin(new Listener<User>() {

            @Override
            public void onResponse(User response) {
                setUser(response);
                onUserSuccess();
            }
        }, new ErrorListener("postLogin") {

            @Override
            public void onErrorResponse(VolleyError error) {
                super.onErrorResponse(error);
                onUserError(error);
            }

        }, jsonRequest);
    } catch (Exception e) {
    }
Run Code Online (Sandbox Code Playgroud)

我的postLogin方法就像添加一个截击请求:

    public static void postLogin(Listener<User> listener, ErrorListener errorListener,
        JSONObject jsonRequest) {
    VolleySingleton
            .getInstance()
            .getRequestQueue()
            .add(new GsonRequest<User>(getUrl("login"), "user_profile", User.class, jsonRequest, Method.POST,
                    listener, errorListener)); …
Run Code Online (Sandbox Code Playgroud)

android unit-testing android-volley android-instrumentation

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