小编Amr*_*rut的帖子

Xamarin表示android应用程序没有获取DeviceToken Parse SDK

我正在为Android和iOS开发xamarin表单应用程序.我正在使用Parse SDK实现PushNotifications.我在.iOS项目的参考文献中引用了.Droid项目和Parse.iOS dll中添加了Parse.Android dll.我的问题有时在Android上我无法检索DeviceToken.解析安装类中没有DeviceToken和pushtype的条目.它的值是"未定义的".下面是我的代码以及清单.

public  async void RegisterForPushNotifications ()
    {
        try {
            if (Utility.isNetworkConnected ()) {
                await ParsePush.SubscribeAsync ("");
                var installation = ParseInstallation.CurrentInstallation;
                // I'm saving the DeviceToken in App.regId for future uses
                App.regId = System.String.IsNullOrWhiteSpace (installation.DeviceToken) ? "" : installation.DeviceToken;
                ParsePush.ParsePushNotificationReceived += PushNotificationReceived;
            }
        } catch (ParseException e) {
            System.Diagnostics.Debug.WriteLine (e.StackTrace);
        } catch (Java.Lang.Exception e) {
            e.PrintStackTrace ();
        }
    }
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.nirvaniclabs">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
<application android:label="RxLifetime" android:icon="@drawable/icon" android:largeHeap="true">
    <receiver android:name="parse.ParsePushBroadcastReceiver" …
Run Code Online (Sandbox Code Playgroud)

c# android xamarin.android parse-platform xamarin.forms

40
推荐指数
1
解决办法
981
查看次数

如何拦截导航栏后退按钮单击Xamarin表单?

我有一个xamarin表单页面,用户可以在表单中更新某些数据.我需要拦截导航栏后退按钮单击以警告用户是否有一些数据尚未保存.如何做?

我能够拦截Android中使用的硬件Bar Back Button Clicked Android.MainActivity.OnBackPressed(),但该事件仅在硬件Bar Back Button上单击,而不是单击导航栏后退按钮.

我也尝试覆盖Xamarin.Forms.NavigationPageOnBackButtonPressed()但它不起作用.为什么?有人已经解决了这个问题吗?

我也尝试过压倒OnDisappear(),有两个问题:

  1. 该页面已经在视觉上消失了,所以"你确定吗?" 对话框出现在上一页上.
  2. 无法取消后退动作.

那么,是否可以截取导航栏后退按钮?

xamarin.android xamarin xamarin-studio xamarin.forms

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

在APK META-INF/maven/com.squareup/otto/pom.xml中复制的重复文件

我正在尝试运行我的应用程序时遇到下面提到的错误.

错误:任务':app:transformResourcesWithMergeJavaResForAmazonCheezCoverage'的执行失败.

com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:在APK META-INF/maven/com.squareup/otto/pom.xml中复制的重复文件File1:/ Users/afourtest /. gradle/caches/modules-2/files-2.1/com.crashlytics.android/crashlytics/1.1.13/e821eafa1bf489a26bdb71f95078c26785b37a1/crashlytics-1.1.13.jar File2:/Users/afourtest/.gradle/caches/modules-2/files -2.1/com.squareup /奥托/ 1.3.7/69d90fd7fb70e54746e26c10454c220e40a775ce /奥托1.3.7.jar

我的app build.gradle就在这里

android gradle android-studio

10
推荐指数
1
解决办法
6168
查看次数

什么是Android P API 28中不推荐使用的ConnectivityManager.TYPE_WIFI的替代方法?

在Android P API 28中不推荐使用ConnectivityManager.TYPE_WIFI。此外,也不推荐使用NetworkInfo#getTypeConnectivityManager.TYPE_MOBILE

那么,有什么替代方案呢?我知道我们必须使用NetworkCapabilities类中的方法。但是,我无法将所有内容合并到一个地方,例如如何在NetworkCapabilities类中进行getType()以及如何在其上添加WIFI和蜂窝数据检查?

请协助。

android android-sdk-manager android-api-levels

9
推荐指数
3
解决办法
5792
查看次数

向上导航(操作栏的后退箭头)不适用于片段

我将抽屉布局作为我活动的基本布局,我正在替换这个抽屉布局内的框架上的两个碎片.第一个片段未添加到片段的后栈中.我在我的活动中显示汉堡包图标(我还想在我的第一个片段中使用抽屉菜单).在第二个片段中,我禁用了汉堡包图标mActionBarDrawerToggle.setDrawerIndicatorEnabled(false)并启用了后退按钮actionBar.setDisplayHomeAsUpEnabled(true).

在第一个片段onResume我通过mActionBarDrawerToggle.setDrawerIndicatorEnabled(true)启用了汉堡包图标,这样当用户从第二个片段按下按钮(硬件和动作栏的向上按钮)时,用户将返回第一个片段并启用汉堡包图标.一切都很好,只是我无法从第二个片段动作栏后退按钮返回.我无法点击它.以下是我的代码: -

活动代码

if (Utility.isLargeScreen(this))
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    else
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mHiddenGemsApplication = (HiddenGemsApplication) getApplication();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    initViews();

    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    mTextViewActionBarTitle.setText(getString(R.string.app_name));

    mActionBarDrawerToggle = new ActionBarDrawerToggle(HomeActivity.this, mDrawerLayout, mToolbar, R.string.open_drawer, R.string.close_drawer) {

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);

    mActionBarDrawerToggle.syncState();

    mFragmentManager = getSupportFragmentManager();

    replaceFragment(new CategoryFragment(), getString(R.string.app_name), CategoryFragment.TAG);

 @Override
public void onBackPressed() {

    if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawers();
        return;
    } …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments android-actionbar android-toolbar

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

导航视图项的ActionLayout显示在右侧

我正在开发一个应用程序,我正在使用新设计支持库的导航视图控制器进行抽屉菜单.一切都很好.我已使用app:menu属性设置导航视图的项目.物品完美展示.现在我正在添加app:actionLayout这些项目,它也会被添加,但问题是它会在视图的右侧显示.

我的活动XML

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <afour.com.uniapp.customwidgets.CustomTextView
            android:id="@+id/text_toolbarTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="start"
            android:text="@string/app_name"
            android:textColor="@android:color/white"
            android:textSize="20sp"
            app:FontName="@string/type_face_splash" />
    </android.support.v7.widget.Toolbar>


    <FrameLayout
        android:id="@+id/frame_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar" />

        </RelativeLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/holo_green_dark"
    android:paddingTop="20dp"
    app:headerLayout="@layout/navigation_header_layout"
    app:paddingStart="0dp"
    app:itemBackground="@android:color/holo_green_light"
    app:itemTextColor="@android:color/white"
    app:menu="@menu/main_menu" />

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

我的菜单文件

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<item
    android:id="@+id/nav_about"
    android:title="@string/aboutus"
    app:showAsAction="never" />

<item
    android:id="@+id/nav_logout"
    app:actionLayout="@layout/logout_item_layout"
    app:showAsAction="collapseActionView" />

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

我的动作布局文件

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<ImageButton
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
    android:background="@android:color/transparent"
    android:contentDescription="@string/aboutus"
    android:padding="05dp"
    android:src="@android:drawable/ic_menu_help" …
Run Code Online (Sandbox Code Playgroud)

xml android menuitem android-layout navigation-drawer

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

Android P Beta-AlarmManager通知不起作用

我正在Android P Beta版本4上测试我的应用程序。我的应用程序的targetSdkVersion为27

已经观察到警报管理器通知未按预期工作。我正在使用以下代码来设置通知-

           if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
                alarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmIntentBuilder.buildPendingIntent(context, uri));
            } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                alarmManager.setExact(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmIntentBuilder.buildPendingIntent(context, uri));
            } else {
                alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmIntentBuilder.buildPendingIntent(context, uri));
            }
Run Code Online (Sandbox Code Playgroud)

我在Android 8.0上测试了相同的逻辑,但工作正常。在Android 9.0中,通知有效,但有时根本不起作用。另外,如果它们能正常工作,它们并不精确,并且会花费大量时间,即使应用程序处于前台,也会发生这种情况。

逻辑是,我有在特定时间设置的重复提醒,这些提醒应该每天在指定时间自行重复。另外,这些都是高优先级提醒,应该在确切的时间降落,因此我正在使用setExact,一旦收到通知,它就会显示出来,并设置同一天下周的新警报。

我已经检查了Android P API文档,但是找不到任何对AlarmManager和Notifications的工作有影响的链接。我唯一引起问题的是Android P中的电源管理和优先级存储桶。但是,即使应用程序位于前台,通知也无法正常工作。

我在这里想念的任何东西。任何帮助深表感谢。

android android-alarms android-notifications android-powermanager android-9.0-pie

7
推荐指数
2
解决办法
3574
查看次数

在Android中正确定位弹出窗口

我坚持使用弹出窗口定位。我在单击按钮时显示我的弹出窗口。我希望它应该根据可用空间定位。此外,如果我的按钮在中心,它应该在按钮下方。下面是我的代码。请让我知道我错在哪里。谢谢你。

mBtnPopUp.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            ListView mListView = (ListView) mPopUpView.findViewById(R.id.pop_up_list_view);
            mListView.setAdapter(mPopupListAdapter);
            Drawable drawable = getResources().getDrawable(android.R.drawable.alert_light_frame);
            mPopupWindow.setBackgroundDrawable(drawable);
            // mPopupWindow.setBackgroundDrawable(new BitmapDrawable());

            showLikeQuickAction(0, 0);
            mPopupWindow.showAsDropDown(mBtnPopUp);
        }
    });

    mPopupWindow.setOutsideTouchable(true);
public void showLikeQuickAction(int xOffset, int yOffset)
{

    int[] location = new int[2];
    mBtnPopUp.getLocationOnScreen(location);

    Rect anchorRect = new Rect(location[0], location[1], location[0] + mBtnPopUp.getWidth(), location[1] + mBtnPopUp.getHeight());

    mBtnPopUp.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootWidth = mBtnPopUp.getMeasuredWidth();
    int rootHeight = mBtnPopUp.getMeasuredHeight();

    @SuppressWarnings("deprecation")
    int screenWidth = mWindowManager.getDefaultDisplay().getWidth();


    int xPos = screenWidth - …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-intent android-layout

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

错误:找不到与给定名称匹配的资源('minHeight'与值'?attr/actionBarSize')

我正在尝试构建android studio项目,并且我遇到以下错误:

Error:(11, 28) No resource found that matches the given name (at 'minHeight' with value '?attr/actionBarSize').
Error:(12, 29) No resource found that matches the given name (at 'background' with value '?attr/colorPrimary').
Run Code Online (Sandbox Code Playgroud)

下面是我的XML文件: -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:qwerjk="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black" >

<android.support.v7.widget.Toolbar
    android:id="@+id/builder_toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary" />

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/layout_bottom"
    android:layout_below="@id/builder_toolbar"
    android:layout_centerInParent="true" >

    <RelativeLayout
        android:id="@+id/lCanvas"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" >

        <ImageView
            android:id="@+id/imgEditor"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
           android:layout_alignParentTop="true" />

        <qwerjk.better_text.MagicTextView
            android:id="@+id/tvEditTop"
            style="@style/BuilderText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@id/imgEditor"
            android:layout_centerHorizontal="true"
            android:text="TOP"
            qwerjk:strokeColor="#FF000000"
            qwerjk:strokeJoinStyle="miter"
            qwerjk:strokeWidth="5" …
Run Code Online (Sandbox Code Playgroud)

android android-studio build.gradle android-gradle-plugin

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

Android 布局方向未在运行时语言更改时更新

我正在开发一个支持两种不同语言的应用程序 -

  1. 英语
  2. 阿拉伯

用户可以随时切换到任何语言,并根据我正在更改应用程序语言的选择。

下面提到的是代码片段 -

public static void setLocale(String languageCode, Context ctx) {

    Locale locale = new Locale(languageCode);
    Locale.setDefault(locale);

    if (Build.VERSION.SDK_INT >= VERSION_CODES.N) {
        updateResourcesLocale(ctx, locale);
    } else {
        updateResourcesLocaleLegacy(ctx, locale);
    }
}


private static void updateResourcesLocale(Context context, Locale locale) {
    Configuration configuration = context.getResources().getConfiguration();
    configuration.setLocale(locale);
    context.getApplicationContext().createConfigurationContext(configuration);
}

private static void updateResourcesLocaleLegacy(Context context, Locale locale) {
    Resources resources = context.getResources();
    Configuration configuration = resources.getConfiguration();
    configuration.locale = locale;
    configuration.setLayoutDirection(locale);
    resources.updateConfiguration(configuration, resources.getDisplayMetrics());
}
Run Code Online (Sandbox Code Playgroud)

同样在应用程序的每个活动中,我都覆盖了attachBaseContext方法。我在其中使用了以下逻辑-

@Override
protected void attachBaseContext(Context …
Run Code Online (Sandbox Code Playgroud)

android localization android-layout android-configchanges

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

showSoftInputFromInputMethod 已弃用 Android P API 28

showSoftInputFromInputMethod该类中的方法在InputMethodManagerAndroid P 中已弃用。根据文档,我们应该InputMethodService.requestShowSelf(int)在 Android P 及更高版本中使用该方法。

现在的问题是我们如何获得该类的参考InputMethodService。我尝试创建一个新对象并调用requestShowself()它,但它不起作用。

InputMethodService inputMethodService = new InputMethodService();
inputMethodService.requestShowSelf(0);
Run Code Online (Sandbox Code Playgroud)

我们如何使用建议的替代方案来替代 API 28 及更高版本的弃用?

android android-keypad android-input-method inputmethodmanager android-9.0-pie

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

将 WindowSoftInputMode 设置为 AdjustPan 时出现问题

我正在研究 Xamarin 表单项目。我的应用程序中有许多条目字段,其中一个在弹出窗口中,弹出窗口在设备屏幕的中心打开。在滚动视图中也很少有条目字段。问题仅在于 Android 应用程序。对于 iOS,它运行良好。当我单击弹出窗口旁边的输入字段时,软键盘被打开并且我的弹出窗口的 UI 受到干扰。因此,我决定将WindowSoftInputMode = SoftInput.AdjustPan设置 为我的主要活动。这解决了我的弹出窗口 UI 问题,但是现在当我单击其他输入字段时,我的![滚动视图停止滚动](侧面滚动视图中很少有输入字段)。我尝试使用 AdjustResize 和其他软输入,但是没用。关于如何摆脱这种情况的任何想法?

初始弹出界面

softkey_board_open

softkey_board_closed

xamarin.android xamarin xamarin.mac xamarin-studio xamarin.forms

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