小编lon*_*ngi的帖子

Android:如果在屏幕上重新启动活动,来自通知的PendingIntent不会触发onCreate()

猜测我对Intent Flags有一些误解.我正在尝试做的是,我有一个无线电流应用程序,它有两个活动(PlayerApplication和SettingsScreen).我有一个用于Streaming的Service.class,它在后台运行,它也包含一个Notification(你可以在notification-overlay菜单和PlayerApplication中停止/开始播放).如果用户单击通知,则应将PlayerApplicationActivity返回到屏幕.

一切正常,期待案例:用户打开SettingsScreenActivity - >打开NotificationOverlayMenu - >点击通知 - > PendingIntent恢复到PlayerApplicationActivity

现在,PlayerApplicationScreen就在那里,但我无法点击任何内容.我看,如果我从Notification继续,我的PlayerApplication的onCreate()不会被触发.但布局看起来很好(在onCreate()中也膨胀)

我在Service.class中使用了以下PendingIntent:

PendingIntent contentIntent = PendingIntent.getActivity(
      this.getApplicationContext(), //Service.class
      0, 
      new Intent(this,PlayerApplicationActivity.class)
             .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP),
      0);
Run Code Online (Sandbox Code Playgroud)

所以实际上PendingIntent应该将Activity(如果已经运行)带回到顶部.我使用错误的意图还是我错过了一点?

编辑:我在Manifest.xml中声明了launchMode

android:launchMode="singleTask"
Run Code Online (Sandbox Code Playgroud)

android android-intent android-notifications android-pendingintent

8
推荐指数
2
解决办法
4315
查看次数

UIPageViewController:子控制器在滚动期间忽略状态栏高度

我遇到了一些问题UIPageViewController.如果我滚动到了新的一页,新的视图控制器是落后的状态栏,而我在滚动.滚动后,视图控制器将自身置于状态栏下方.

我正在使用Storyboard(Universal).UIPageViewController有属性Extend Edges: Under Top Bars.我错过了什么?

在此输入图像描述

  • 设置automaticallyAdjustsScrollViewInsets为false不起作用
  • 使用edgesForExtendedLayout = UIRectEdge.None也没有用
  • 在这里找到一些开放的问题,但没有答案(链接)

UPDATE

跳跃的另一个原因是来自'Constraints'的'边缘'(在这里找到).如果使用约束,请确保取消选中边距(右对话框).您可以稍后在"实用程序"中将其删除(左侧对话框).检查两个连接的视图!

在此输入图像描述

statusbar ios uipageviewcontroller

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

如何使用一个查询搜索带地址的联系人(FORMATTED_ADDRESS)?

我尝试对用户联系人实施实时搜索,我想获取每个匹配联系人的姓名,缩略图和地址(如果有).

用户键入时正在运行实时搜索.

所以他输入了ma并将获得'martin','matthews'......

他将继续垫子,只会看到'matthews'

我尝试使用如下所示的单个查询来实现此目的,但我总是在FORMATTED_ADRESS字段中获取联系号码.我想我有一个JOIN问题,因为我使用ContactsContract.CommonDataKinds,并ContactsContract.Contacts在相同的查询?

public static List<ContactModel> getContactsForQuery(Context context, String query) {

    String[] projection = new String[] {
        ContactsContract.Contacts.DISPLAY_NAME,
        Contacts.PHOTO_THUMBNAIL_URI,
        ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS
    };

    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String selection = ContactsContract.Contacts.DISPLAY_NAME + " LIKE '%" + query +  "%'";
    Cursor cursor = context.getContentResolver().query(uri, projection, selection, null,null);
    if (cursor.moveToFirst()) {

        do {
            String name = cursor.getString(0);
            String thumbail = cursor.getString(1);
            String formattedADress = cursor.getString(2);
        }
        while (cursor.moveToNext());
    }
Run Code Online (Sandbox Code Playgroud)

我实际上解决了我的问题 …

android contactscontract android-contacts

7
推荐指数
1
解决办法
359
查看次数

Android:从设备隐藏音量更改栏?

有没有办法隐藏音量变化栏/通知(但你可以称之为..btw.你怎么称呼它?)?

关于音量变化的截图nexus

我附上了截图.每次更改音量时都会显示此栏(至少在我的nexus测试设备上).或者这是一个特殊的关系?

android android-layout android-audiomanager

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

Android:BackStack行为不端,如果应用程序是从另一个应用程序启动的

我有一个应用程序,以一个开头SplashScreenActivity.然后,显示a LoginActivity,或者如果用户已经登录,MainActivity则显示a.如果应用程序已在运行,SplashScreenActivity则会被解除以下内容

//SplashScreenActivity
 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Adding this check for following cases
    if (!isTaskRoot())
    {
        String intentAction = getIntent().getAction();
        if (getIntent().hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
            finish();
            return;
        }

        if(getIntent().getCategories().contains(GCMIntentService.INTENT_CATEGORY_GH_NOTIFICATION)){
            finish();
            return;
        }
    }
Run Code Online (Sandbox Code Playgroud)

出现问题

如果我从PlayStore等其他活动启动应用程序,它会在正确的活动中恢复,如果已经运行的话.这是Intent我用来在第二个应用程序中重现

//AnotherApplication.apk
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("my.package.name");
startActivity(launchIntent);
Run Code Online (Sandbox Code Playgroud)

但是,这个动作在某种程度上打破了Backstack.它不是在后台关闭应用程序MainActivity,而是重新启动应用程序.

//MainActivity.class
@Override
public void onBackPressed() {
    if (getNavDrawerMain().isDrawerOpen()) {
        getNavDrawerMain().closeDrawer();
    } else {
        closeApp();
    }
}

protected void closeApp() { …
Run Code Online (Sandbox Code Playgroud)

android application-close back-stack

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

更改ProgressBar.Horizo​​ntal不确定行为

我尝试实现一个水平不确定的ProgressBar,它将在结束时反转其动画.为了澄清,我希望进度条从0到100动画,然后从100回到0.这是标准动画的视频,我想在结束时反转.

根据ProgressBar的文档,这应该可以用xml,但我无法做到这一点.你可以设置重复(标准?)或循环(这是我想要的)

这是我的实现:

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="8dip"
    android:indeterminate="true"
    android:indeterminateOnly="true"      //tried "false" too
    android:indeterminateBehavior="cycle" // type "reverse" is the one from linked video?
    android:max="100" />
Run Code Online (Sandbox Code Playgroud)

尝试过max-value,与众不同style-parents

但是,我找到了值android:indeterminateDuration="[value]"并设置了1到1秒,另一个设置为10秒.最后,两个进度加载器都有相同的长度,这让我想到了这些样式可能会被某些地方覆盖?!

有谁知道如何解决这一问题?

赏金更新:问题已解决,对于indeterminateBehaviour正在运行的工作示例

android android-progressbar

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

目标C:如何将CGImageRef转换为UIImageView?

我正在使用XZINGObjC框架来创建EAN-Barcode-Image.在文档之后,我就是这么做的

 //in viewDidAppear

 //XZING: create Matrix
 NSString* eanString = @"1234567890123";  //sth. like that
 ZXBitMatrix* result = [writer encode:eanString
                              format:kBarcodeFormatEan13
                               width:500
                              height:500
                               error:&error];
if (result) {
      //XZING: convert matrix to CGImageRef
      CGImageRef imageRef = [[ZXImage imageWithMatrix:result] cgimage]; 

      //CRASHLINE HERE!! (this is NOT in the XZING documentation, but i cannot figure out the issue!)
      UIImage* uiImage = [[UIImage alloc] initWithCGImage:imageRef];  //<--CRASH: EXC_BAD_ACCESS

      if(image != nil){
          //assigning image to ui
          self.barCodeImageView.image = uiImage;   
      }
Run Code Online (Sandbox Code Playgroud)

如果我使用断点逐步执行此代码,它可以工作!但是,我认为在某些时候图像还没有准备好使用?!但我找不到原因.

我尝试了什么:

  • 使用imageRefuiImage …

exc-bad-access objective-c uiimage cgimageref

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

使用Swift禁用MPMoviePlayerController的音频(和中断)

目前,这就是我在UIViewController的子视图中播放视频的方式:

override func viewDidAppear(animated: Bool)  {
    let filePath = NSBundle.mainBundle().pathForResource("musicvideo", ofType: "mp4")
    self.moviePlayerController.contentURL = NSURL.fileURLWithPath(filePath)
    self.moviePlayerController.play()
    self.moviePlayerController.repeatMode = .One
    self.moviePlayerController.view.frame = self.view.bounds
    self.moviePlayerController.scalingMode = .AspectFill
    self.moviePlayerController.controlStyle = .None
    self.moviePlayerController.allowsAirPlay = false
    self.view.addSubview(self.moviePlayerController.view)
}
Run Code Online (Sandbox Code Playgroud)

我已经通过以下方式阅读了关于禁用音频的方法(根本没有工作).请记住,我正在尝试禁用它,以便不通过音乐应用程序,Spotify等中断当前播放的音乐.

// Playing media items with the applicationMusicPlayer will restore the user's Music state after the application quits.

// The current volume of playing music, in the range of 0.0 to 1.0.
// This property is deprecated -- use MPVolumeView for volume control instead.
Run Code Online (Sandbox Code Playgroud)

1) MPMusicPlayerController.applicationMusicPlayer().volume = …

mpmovieplayercontroller avplayer avplayerlayer swift

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

如何在Android中实现(无限)水平(时间)选择器?

我最近在 EPG 应用程序中发现了一个(自定义)UI 元素,我想知道如何实现类似的功能。

在此输入图像描述

基本上:使用这个 ui 元素,您可以选择一个时间。它只显示整小时和半小时,但您可以在(整个)屏幕上垂直滑动时选择 5 分钟间隔。如果您选择时间,应用程序会根据所选时间更新 UI。

该 UI 元素位于ListView. 垂直滑动可让您在列表中滚动,水平滑动(在整个屏幕上)可更改时间值。

我想实现类似的东西,但我完全不知道从哪里开始。我的主要问题是,如何实现时间列表并为其设置动画?(假设从今天开始到两天后)。我应该尝试延长ListView这一时间吗?或者TimePickerScrubber

编辑:(想法1)

  1. 具有半时间值和日期的水平 ListView(如果您滑动到第二天)
  2. 顶部的 Textview 计算单元格当前值和偏移量的时间?

android android-custom-view android-listview android-timepicker

5
推荐指数
0
解决办法
1691
查看次数

Android:如果从另一个应用程序打开应用程序,则 launchMode singleTop 不起作用

我有一个应用程序,如果从另一个应用程序启动(例如通过 Playstore),它会出现错误。它不会恢复到已经存在的实例Activity,而是作为新实例重新启动。

我拥有的:

  • launchMode="singleTop"声明每项活动manifest.xml
  • 我尝试了同样的操作 launchMode=singleTask,但它具有相同的行为
  • intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)在每个Intent开始新的内容时使用额外的Activity
  • onNewIntent()不在已经运行的实例中调用

我使用以下代码从另一个应用程序启动我的应用程序(带或不带附加addFlag()

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("my.package.name");
launchIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(launchIntent);
Run Code Online (Sandbox Code Playgroud)

我的启动器活动是一个SplashScreenActivity,如果MainActivity用户使用以下代码登录并获取finished()

 Intent intent = null;
 intent = new Intent(SplashScreenActivity.this, HomeActivity.class);
 intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
 startActivity(intent);
 finish();
Run Code Online (Sandbox Code Playgroud)

我缺少什么?有什么建议欢迎留言!

android android-launcher

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